Skip to content

Commit 47de4d1

Browse files
erwangokartben
authored andcommitted
drivers: stm32: Make use of new GET_INSTANCE DMA macro
Use the new macro and factorize code when possible. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent daeb7b9 commit 47de4d1

File tree

5 files changed

+6
-42
lines changed

5 files changed

+6
-42
lines changed

drivers/disk/sdmmc_stm32.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ static int stm32_sdmmc_configure_dma(DMA_HandleTypeDef *handle, struct sdmmc_dma
241241
return ret;
242242
}
243243

244+
handle->Instance = STM32_DMA_GET_INSTANCE(dma->reg, dma->channel_nb);
244245
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1)
245-
handle->Instance = __LL_DMA_GET_STREAM_INSTANCE(dma->reg, dma->channel_nb);
246246
handle->Init.Channel = dma->cfg.dma_slot * DMA_CHANNEL_1;
247247
handle->Init.PeriphInc = DMA_PINC_DISABLE;
248248
handle->Init.MemInc = DMA_MINC_ENABLE;
@@ -255,14 +255,11 @@ static int stm32_sdmmc_configure_dma(DMA_HandleTypeDef *handle, struct sdmmc_dma
255255
handle->Init.MemBurst = DMA_MBURST_INC4;
256256
handle->Init.PeriphBurst = DMA_PBURST_INC4;
257257
#else
258-
uint32_t channel_id = dma->channel_nb - STM32_DMA_STREAM_OFFSET;
259-
260258
BUILD_ASSERT(STM32_SDMMC_USE_DMA_SHARED == 1, "Only txrx is supported on this family");
261259
/* handle->Init.Direction is not initialised here on purpose.
262260
* Since the channel is reused for both directions, the direction is
263261
* configured before each read/write call.
264262
*/
265-
handle->Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dma->reg, channel_id);
266263
handle->Init.Request = dma->cfg.dma_slot;
267264
handle->Init.PeriphInc = DMA_PINC_DISABLE;
268265
handle->Init.MemInc = DMA_MINC_ENABLE;

drivers/flash/flash_stm32_ospi.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,27 +2263,12 @@ static int flash_stm32_ospi_init(const struct device *dev)
22632263
hdma.Init.Mode = DMA_NORMAL;
22642264
hdma.Init.Priority = table_priority[dma_cfg.channel_priority];
22652265
hdma.Init.Direction = DMA_PERIPH_TO_MEMORY;
2266+
hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel);
22662267
#ifdef CONFIG_DMA_STM32_V1
22672268
/* TODO: Not tested in this configuration */
22682269
hdma.Init.Channel = dma_cfg.dma_slot;
2269-
hdma.Instance = __LL_DMA_GET_STREAM_INSTANCE(dev_data->dma.reg,
2270-
dev_data->dma.channel);
22712270
#else
22722271
hdma.Init.Request = dma_cfg.dma_slot;
2273-
#if CONFIG_DMA_STM32U5
2274-
hdma.Instance = LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
2275-
dev_data->dma.channel);
2276-
#elif defined(CONFIG_DMAMUX_STM32)
2277-
/*
2278-
* HAL expects a valid DMA channel (not DMAMUX).
2279-
* The channel is from 0 to 7 because of the STM32_DMA_STREAM_OFFSET in the dma_stm32 driver
2280-
*/
2281-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
2282-
dev_data->dma.channel);
2283-
#else
2284-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
2285-
dev_data->dma.channel-1);
2286-
#endif /* CONFIG_DMA_STM32U5 */
22872272
#endif /* CONFIG_DMA_STM32_V1 */
22882273

22892274
/* Initialize DMA HAL */

drivers/flash/flash_stm32_qspi.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,21 +1592,12 @@ static int flash_stm32_qspi_init(const struct device *dev)
15921592
hdma.Init.MemInc = DMA_MINC_ENABLE;
15931593
hdma.Init.Mode = DMA_NORMAL;
15941594
hdma.Init.Priority = table_priority[dma_cfg.channel_priority];
1595+
hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel);
15951596
#ifdef CONFIG_DMA_STM32_V1
15961597
/* TODO: Not tested in this configuration */
15971598
hdma.Init.Channel = dma_cfg.dma_slot;
1598-
hdma.Instance = __LL_DMA_GET_STREAM_INSTANCE(dev_data->dma.reg,
1599-
dev_data->dma.channel);
16001599
#else
16011600
hdma.Init.Request = dma_cfg.dma_slot;
1602-
#ifdef CONFIG_DMAMUX_STM32
1603-
/* HAL expects a valid DMA channel (not a DMAMUX channel) */
1604-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
1605-
dev_data->dma.channel);
1606-
#else
1607-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
1608-
dev_data->dma.channel-1);
1609-
#endif
16101601
#endif /* CONFIG_DMA_STM32_V1 */
16111602

16121603
/* Initialize DMA HAL */

drivers/i2s/i2s_stm32_sai.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <zephyr/drivers/pinctrl.h>
1818
#include <zephyr/cache.h>
1919

20-
#include <zephyr/drivers/dma/dma_stm32.h>
21-
#include <zephyr/drivers/dma.h>
2220
#include <stm32_ll_dma.h>
2321

2422
#include <zephyr/logging/log.h>
@@ -285,15 +283,13 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
285283
}
286284

287285
#if defined(CONFIG_SOC_SERIES_STM32H7X)
288-
hdma->Instance = __LL_DMA_GET_STREAM_INSTANCE(stream->reg, stream->dma_channel);
289286
hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
290287
hdma->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
291288
hdma->Init.Priority = DMA_PRIORITY_HIGH;
292289
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
293290
hdma->Init.PeriphInc = DMA_PINC_DISABLE;
294291
hdma->Init.MemInc = DMA_MINC_ENABLE;
295292
#else
296-
hdma->Instance = LL_DMA_GET_CHANNEL_INSTANCE(stream->reg, stream->dma_channel);
297293
hdma->Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
298294
hdma->Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;
299295
hdma->Init.DestDataWidth = DMA_DEST_DATAWIDTH_HALFWORD;
@@ -303,7 +299,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
303299
hdma->Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0 | DMA_DEST_ALLOCATED_PORT0;
304300
hdma->Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
305301
#endif
306-
302+
hdma->Instance = STM32_DMA_GET_INSTANCE(stream->reg, stream->dma_channel);
307303
hdma->Init.Request = dma_cfg.dma_slot;
308304
hdma->Init.Mode = DMA_NORMAL;
309305

drivers/video/video_stm32_dcmi.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,12 @@ static int stm32_dma_init(const struct device *dev)
152152
hdma.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
153153
hdma.Init.Mode = DMA_CIRCULAR;
154154
hdma.Init.Priority = DMA_PRIORITY_HIGH;
155+
hdma.Instance = STM32_DMA_GET_INSTANCE(config->dma.reg,
156+
config->dma.channel);
155157
#if defined(CONFIG_SOC_SERIES_STM32F7X) || defined(CONFIG_SOC_SERIES_STM32H7X)
156158
hdma.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
157159
#endif
158160

159-
#if defined(CONFIG_SOC_SERIES_STM32F7X) || defined(CONFIG_SOC_SERIES_STM32H7X)
160-
hdma.Instance = __LL_DMA_GET_STREAM_INSTANCE(config->dma.reg,
161-
config->dma.channel);
162-
#elif defined(CONFIG_SOC_SERIES_STM32L4X)
163-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(config->dma.reg, config->dma.channel);
164-
#endif
165-
166161
/* Initialize DMA HAL */
167162
__HAL_LINKDMA(&data->hdcmi, DMA_Handle, hdma);
168163

0 commit comments

Comments
 (0)