Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dma_stm32.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DRIVERS_DMA_STM32_H_
8#define ZEPHYR_INCLUDE_DRIVERS_DMA_STM32_H_
9
10#include <zephyr/devicetree.h>
12
13/* @brief linked_channel value to inform zephyr dma driver that
14 * DMA channel will be handled by HAL
15 */
16#define STM32_DMA_HAL_OVERRIDE 0x7F
17
18/* @brief gives the first DMA channel : 0 or 1 in the register map
19 * when counting channels from 1 to N or from 0 to N-1
20 */
21#if defined(CONFIG_DMA_STM32U5)
22/* from DTS the dma stream id is in range 0..N-1 */
23#define STM32_DMA_STREAM_OFFSET 0
24#elif !defined(CONFIG_DMA_STM32_V1)
25/* from DTS the dma stream id is in range 1..N */
26/* so decrease to set range from 0 from now on */
27#define STM32_DMA_STREAM_OFFSET 1
28#elif defined(CONFIG_DMA_STM32_V1) && defined(CONFIG_DMAMUX_STM32)
29/* typically on the stm32H7 series, DMA V1 with mux */
30#define STM32_DMA_STREAM_OFFSET 1
31#else
32/* from DTS the dma stream id is in range 0..N-1 */
33#define STM32_DMA_STREAM_OFFSET 0
34#endif /* ! CONFIG_DMA_STM32_V1 */
35
36/* macro for dma slot (only for dma-v1 or dma-v2 types) */
37#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2bis)
38#define STM32_DMA_SLOT(id, dir, slot) 0
39#define STM32_DMA_SLOT_BY_IDX(id, idx, slot) 0
40#else
41#define STM32_DMA_SLOT(id, dir, slot) DT_INST_DMAS_CELL_BY_NAME(id, dir, slot)
42#define STM32_DMA_SLOT_BY_IDX(id, idx, slot) DT_INST_DMAS_CELL_BY_IDX(id, idx, slot)
43#endif
44
45#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2) || \
46 DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2bis) || \
47 DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dmamux)
48#define STM32_DMA_FEATURES(id, dir) 0
49#else
50#define STM32_DMA_FEATURES(id, dir) \
51 DT_INST_DMAS_CELL_BY_NAME(id, dir, features)
52#endif
53
54#define STM32_DMA_CTLR(id, dir) \
55 DT_INST_DMAS_CTLR_BY_NAME(id, dir)
56#define STM32_DMA_CHANNEL_CONFIG(id, dir) \
57 DT_INST_DMAS_CELL_BY_NAME(id, dir, channel_config)
58#define STM32_DMA_CHANNEL_CONFIG_BY_IDX(id, idx) \
59 DT_INST_DMAS_CELL_BY_IDX(id, idx, channel_config)
60
61/* macros for channel-config */
62/* enable circular buffer */
63#define STM32_DMA_CONFIG_CYCLIC(config) ((config >> 5) & 0x1)
64/* direction defined on bits 6-7 */
65/* 0 -> MEM_TO_MEM, 1 -> MEM_TO_PERIPH, 2 -> PERIPH_TO_MEM */
66#define STM32_DMA_CONFIG_DIRECTION(config) ((config >> 6) & 0x3)
67/* periph increment defined on bit 9 as true/false */
68#define STM32_DMA_CONFIG_PERIPHERAL_ADDR_INC(config) ((config >> 9) & 0x1)
69/* mem increment defined on bit 10 as true/false */
70#define STM32_DMA_CONFIG_MEMORY_ADDR_INC(config) ((config >> 10) & 0x1)
71/* periph data size defined on bits 11-12 */
72/* 0 -> 1 byte, 1 -> 2 bytes, 2 -> 4 bytes */
73#define STM32_DMA_CONFIG_PERIPHERAL_DATA_SIZE(config) \
74 (1 << ((config >> 11) & 0x3))
75/* memory data size defined on bits 13, 14 */
76/* 0 -> 1 byte, 1 -> 2 bytes, 2 -> 4 bytes */
77#define STM32_DMA_CONFIG_MEMORY_DATA_SIZE(config) \
78 (1 << ((config >> 13) & 0x3))
79/* priority increment offset defined on bit 15 */
80#define STM32_DMA_CONFIG_PERIPHERAL_INC_FIXED(config) ((config >> 15) & 0x1)
81/* priority defined on bits 16-17 as 0, 1, 2, 3 */
82#define STM32_DMA_CONFIG_PRIORITY(config) ((config >> 16) & 0x3)
83
84/* macro for features (only for dma-v1) */
85#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1)
86#define STM32_DMA_FEATURES_FIFO_THRESHOLD(features) (features & 0x3)
87#else
88#define STM32_DMA_FEATURES_FIFO_THRESHOLD(features) 0
89#endif
90
91#if defined(CONFIG_SOC_SERIES_STM32H5X) || defined(CONFIG_SOC_SERIES_STM32H7RSX) || \
92 defined(CONFIG_SOC_SERIES_STM32MP2X) || defined(CONFIG_SOC_SERIES_STM32N6X) || \
93 defined(CONFIG_SOC_SERIES_STM32U3X) || defined(CONFIG_SOC_SERIES_STM32U5X) || \
94 defined(CONFIG_SOC_SERIES_STM32WBAX)
95#define STM32_DMA_GET_CHANNEL_INSTANCE LL_DMA_GET_CHANNEL_INSTANCE
96#else
97#define STM32_DMA_GET_CHANNEL_INSTANCE __LL_DMA_GET_CHANNEL_INSTANCE
98#endif
99
100#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1)
101#define STM32_DMA_GET_INSTANCE(reg, channel) \
102 __LL_DMA_GET_STREAM_INSTANCE((reg), (channel) - STM32_DMA_STREAM_OFFSET);
103#else
104#define STM32_DMA_GET_INSTANCE(reg, channel) \
105 STM32_DMA_GET_CHANNEL_INSTANCE((reg), (channel) - STM32_DMA_STREAM_OFFSET);
106#endif
107
108#endif /* ZEPHYR_INCLUDE_DRIVERS_DMA_STM32_H_ */
DMA Devicetree macro public API header file.
Devicetree main header.