Skip to content

Commit d7e2581

Browse files
committed
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 29633fd commit d7e2581

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
@@ -224,8 +224,8 @@ static int stm32_sdmmc_configure_dma(DMA_HandleTypeDef *handle, struct sdmmc_dma
224224
return ret;
225225
}
226226

227+
handle->Instance = STM32_DMA_GET_INSTANCE(dma->reg, dma->channel_nb);
227228
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1)
228-
handle->Instance = __LL_DMA_GET_STREAM_INSTANCE(dma->reg, dma->channel_nb);
229229
handle->Init.Channel = dma->cfg.dma_slot * DMA_CHANNEL_1;
230230
handle->Init.PeriphInc = DMA_PINC_DISABLE;
231231
handle->Init.MemInc = DMA_MINC_ENABLE;
@@ -238,14 +238,11 @@ static int stm32_sdmmc_configure_dma(DMA_HandleTypeDef *handle, struct sdmmc_dma
238238
handle->Init.MemBurst = DMA_MBURST_INC4;
239239
handle->Init.PeriphBurst = DMA_PBURST_INC4;
240240
#else
241-
uint32_t channel_id = dma->channel_nb - STM32_DMA_STREAM_OFFSET;
242-
243241
BUILD_ASSERT(STM32_SDMMC_USE_DMA_SHARED == 1, "Only txrx is supported on this family");
244242
/* handle->Init.Direction is not initialised here on purpose.
245243
* Since the channel is reused for both directions, the direction is
246244
* configured before each read/write call.
247245
*/
248-
handle->Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dma->reg, channel_id);
249246
handle->Init.Request = dma->cfg.dma_slot;
250247
handle->Init.PeriphInc = DMA_PINC_DISABLE;
251248
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
@@ -2253,27 +2253,12 @@ static int flash_stm32_ospi_init(const struct device *dev)
22532253
hdma.Init.Mode = DMA_NORMAL;
22542254
hdma.Init.Priority = table_priority[dma_cfg.channel_priority];
22552255
hdma.Init.Direction = DMA_PERIPH_TO_MEMORY;
2256+
hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel);
22562257
#ifdef CONFIG_DMA_STM32_V1
22572258
/* TODO: Not tested in this configuration */
22582259
hdma.Init.Channel = dma_cfg.dma_slot;
2259-
hdma.Instance = __LL_DMA_GET_STREAM_INSTANCE(dev_data->dma.reg,
2260-
dev_data->dma.channel);
22612260
#else
22622261
hdma.Init.Request = dma_cfg.dma_slot;
2263-
#if CONFIG_DMA_STM32U5
2264-
hdma.Instance = LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
2265-
dev_data->dma.channel);
2266-
#elif defined(CONFIG_DMAMUX_STM32)
2267-
/*
2268-
* HAL expects a valid DMA channel (not DMAMUX).
2269-
* The channel is from 0 to 7 because of the STM32_DMA_STREAM_OFFSET in the dma_stm32 driver
2270-
*/
2271-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
2272-
dev_data->dma.channel);
2273-
#else
2274-
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
2275-
dev_data->dma.channel-1);
2276-
#endif /* CONFIG_DMA_STM32U5 */
22772262
#endif /* CONFIG_DMA_STM32_V1 */
22782263

22792264
/* 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>
@@ -284,13 +282,11 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
284282
}
285283

286284
#if defined(CONFIG_SOC_SERIES_STM32H7X)
287-
hdma->Instance = __LL_DMA_GET_STREAM_INSTANCE(stream->reg, stream->dma_channel);
288285
hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
289286
hdma->Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD;
290287
hdma->Init.Priority = DMA_PRIORITY_HIGH;
291288
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
292289
#else
293-
hdma->Instance = LL_DMA_GET_CHANNEL_INSTANCE(stream->reg, stream->dma_channel);
294290
hdma->Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
295291
hdma->Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;
296292
hdma->Init.DestDataWidth = DMA_DEST_DATAWIDTH_HALFWORD;
@@ -300,7 +296,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
300296
hdma->Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0 | DMA_DEST_ALLOCATED_PORT0;
301297
hdma->Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
302298
#endif
303-
299+
hdma->Instance = STM32_DMA_GET_INSTANCE(stream->reg, stream->dma_channel);
304300
hdma->Init.Request = dma_cfg.dma_slot;
305301
hdma->Init.Mode = DMA_NORMAL;
306302

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)