Zephyr Project API 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_DMA_STM32_H_
8#define ZEPHYR_INCLUDE_DRIVERS_DMA_DMA_STM32_H_
9
10#include <zephyr/devicetree.h>
12#include <zephyr/drivers/dma.h>
13
14/* @brief linked_channel value to inform zephyr dma driver that
15 * DMA channel will be handled by HAL
16 */
17#define STM32_DMA_HAL_OVERRIDE 0x7F
18
19/* @brief gives the first DMA channel : 0 or 1 in the register map
20 * when counting channels from 1 to N or from 0 to N-1
21 */
22#if defined(CONFIG_DMA_STM32U5)
23/* from DTS the dma stream id is in range 0..N-1 */
24#define STM32_DMA_STREAM_OFFSET 0
25#elif !defined(CONFIG_DMA_STM32_V1)
26/* from DTS the dma stream id is in range 1..N */
27/* so decrease to set range from 0 from now on */
28#define STM32_DMA_STREAM_OFFSET 1
29#elif defined(CONFIG_DMA_STM32_V1) && defined(CONFIG_DMAMUX_STM32)
30/* typically on the stm32H7 series, DMA V1 with mux */
31#define STM32_DMA_STREAM_OFFSET 1
32#else
33/* from DTS the dma stream id is in range 0..N-1 */
34#define STM32_DMA_STREAM_OFFSET 0
35#endif /* ! CONFIG_DMA_STM32_V1 */
36
38/* macro for dma slot (only for dma-v1 or dma-v2 types) */
39#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2bis)
40#define STM32_DT_DMA_SLOT(node_id, dir) 0
41#define STM32_DT_INST_DMA_SLOT(inst, dir) 0
42
43#define STM32_DT_DMA_SLOT_BY_IDX(node_id, idx) 0
44#define STM32_DT_INST_DMA_SLOT_BY_IDX(inst, idx) 0
45#else
46#define STM32_DT_DMA_SLOT(node_id, dir) DT_DMAS_CELL_BY_NAME(node_id, dir, slot)
47#define STM32_DT_INST_DMA_SLOT(inst, dir) STM32_DT_DMA_SLOT(DT_DRV_INST(inst), dir)
48
49#define STM32_DT_DMA_SLOT_BY_IDX(node_id, idx) DT_DMAS_CELL_BY_IDX(node_id, idx, slot)
50#define STM32_DT_INST_DMA_SLOT_BY_IDX(inst, idx) STM32_DT_DMA_SLOT_BY_IDX(DT_DRV_INST(inst), idx)
51#endif
52
53#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2) || \
54 DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2bis) || \
55 DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dmamux)
56#define STM32_DT_DMA_FEATURES(node_id, dir) 0
57#define STM32_DT_INST_DMA_FEATURES(inst, dir) 0
58#else
59#define STM32_DT_DMA_FEATURES(node_id, dir) DT_DMAS_CELL_BY_NAME(node_id, dir, features)
60#define STM32_DT_INST_DMA_FEATURES(inst, dir) STM32_DT_DMA_FEATURES(DT_DRV_INST(inst), dir)
61#endif
62
63#define STM32_DT_DMA_CTLR(node_id, dir) DT_DMAS_CTLR_BY_NAME(node_id, dir)
64#define STM32_DT_INST_DMA_CTLR(inst, dir) STM32_DT_DMA_CTLR(DT_DRV_INST(inst), dir)
65
66#define STM32_DT_DMA_CHANNEL_CONFIG(node_id, dir) \
67 DT_DMAS_CELL_BY_NAME(node_id, dir, channel_config)
68#define STM32_DT_INST_DMA_CHANNEL_CONFIG(inst, dir) \
69 STM32_DT_DMA_CHANNEL_CONFIG(DT_DRV_INST(inst), dir)
70
71#define STM32_DT_DMA_CHANNEL_CONFIG_BY_IDX(node_id, idx) \
72 DT_DMAS_CELL_BY_IDX(node_id, idx, channel_config)
73#define STM32_DT_INST_DMA_CHANNEL_CONFIG_BY_IDX(inst, idx) \
74 STM32_DT_DMA_CHANNEL_CONFIG_BY_IDX(DT_DRV_INST(inst), idx)
75
76/* macros for channel-config */
77/* enable circular buffer */
78#define STM32_DMA_CONFIG_CYCLIC(config) ((config >> 5) & 0x1)
79/* direction defined on bits 6-7 */
80/* 0 -> MEM_TO_MEM, 1 -> MEM_TO_PERIPH, 2 -> PERIPH_TO_MEM */
81#define STM32_DMA_CONFIG_DIRECTION(config) ((config >> 6) & 0x3)
82/* periph increment defined on bit 9 as true/false */
83#define STM32_DMA_CONFIG_PERIPHERAL_ADDR_INC(config) ((config >> 9) & 0x1)
84/* mem increment defined on bit 10 as true/false */
85#define STM32_DMA_CONFIG_MEMORY_ADDR_INC(config) ((config >> 10) & 0x1)
86/* periph data size defined on bits 11-12 */
87/* 0 -> 1 byte, 1 -> 2 bytes, 2 -> 4 bytes */
88#define STM32_DMA_CONFIG_PERIPHERAL_DATA_SIZE(config) \
89 (1 << ((config >> 11) & 0x3))
90/* memory data size defined on bits 13, 14 */
91/* 0 -> 1 byte, 1 -> 2 bytes, 2 -> 4 bytes */
92#define STM32_DMA_CONFIG_MEMORY_DATA_SIZE(config) \
93 (1 << ((config >> 13) & 0x3))
94/* priority increment offset defined on bit 15 */
95#define STM32_DMA_CONFIG_PERIPHERAL_INC_FIXED(config) ((config >> 15) & 0x1)
96/* priority defined on bits 16-17 as 0, 1, 2, 3 */
97#define STM32_DMA_CONFIG_PRIORITY(config) ((config >> 16) & 0x3)
98
99/* macro for features (only for dma-v1) */
100#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1)
101#define STM32_DMA_FEATURES_FIFO_THRESHOLD(features) (features & 0x3)
102#else
103#define STM32_DMA_FEATURES_FIFO_THRESHOLD(features) 0
104#endif
105
106#if defined(CONFIG_SOC_SERIES_STM32H5X) || defined(CONFIG_SOC_SERIES_STM32H7RSX) || \
107 defined(CONFIG_SOC_SERIES_STM32MP2X) || defined(CONFIG_SOC_SERIES_STM32N6X) || \
108 defined(CONFIG_SOC_SERIES_STM32U3X) || defined(CONFIG_SOC_SERIES_STM32U5X) || \
109 defined(CONFIG_SOC_SERIES_STM32WBAX)
110#define STM32_DMA_GET_CHANNEL_INSTANCE LL_DMA_GET_CHANNEL_INSTANCE
111#else
112#define STM32_DMA_GET_CHANNEL_INSTANCE __LL_DMA_GET_CHANNEL_INSTANCE
113#endif
114
115#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1)
116#define STM32_DMA_GET_INSTANCE(reg, channel) \
117 __LL_DMA_GET_STREAM_INSTANCE((reg), (channel) - STM32_DMA_STREAM_OFFSET);
118#else
119#define STM32_DMA_GET_INSTANCE(reg, channel) \
120 STM32_DMA_GET_CHANNEL_INSTANCE((reg), (channel) - STM32_DMA_STREAM_OFFSET);
121#endif
123
124#ifndef CONFIG_STM32_HAL2
149int dma_stm32_zcfg_to_halcfg(const struct device *dma, const struct dma_config *zephyr_config,
150 DMA_InitTypeDef *hal_config, uint16_t source_addr_adj,
151 uint16_t dest_addr_adj);
153#endif /* CONFIG_STM32_HAL2 */
154
155#endif /* ZEPHYR_INCLUDE_DRIVERS_DMA_DMA_STM32_H_ */
DMA Devicetree macro public API header file.
Devicetree main header.
Main header file for DMA (Direct Memory Access) driver API.
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
DMA configuration structure.
Definition dma.h:201