From ae6322a1901e0c5fcce3632052a0dacebd840965 Mon Sep 17 00:00:00 2001 From: Mario Paja Date: Fri, 28 Nov 2025 16:15:34 +0100 Subject: [PATCH] drivers: remove on-stack copying of dma cfg on stm32 drivers This change removes the on-stack copying and instead uses a pointer to the configuration to avoid unnecessary stack usage Signed-off-by: Mario Paja --- drivers/flash/flash_stm32_ospi.c | 18 +++++++++--------- drivers/flash/flash_stm32_qspi.c | 18 +++++++++--------- drivers/i2s/i2s_stm32_sai.c | 18 +++++++++--------- drivers/video/video_stm32_dcmi.c | 8 ++++---- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/flash/flash_stm32_ospi.c b/drivers/flash/flash_stm32_ospi.c index a22e9fb7928a5..bbcd216688770 100644 --- a/drivers/flash/flash_stm32_ospi.c +++ b/drivers/flash/flash_stm32_ospi.c @@ -2242,7 +2242,7 @@ static int flash_stm32_ospi_init(const struct device *dev) * the minimum information to inform the DMA slot will be in used and * how to route callbacks. */ - struct dma_config dma_cfg = dev_data->dma.cfg; + struct dma_config *dma_cfg = &dev_data->dma.cfg; static DMA_HandleTypeDef hdma; if (!device_is_ready(dev_data->dma.dev)) { @@ -2251,22 +2251,22 @@ static int flash_stm32_ospi_init(const struct device *dev) } /* Proceed to the minimum Zephyr DMA driver init */ - dma_cfg.user_data = &hdma; + dma_cfg->user_data = &hdma; /* HACK: This field is used to inform driver that it is overridden */ - dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE; - ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, &dma_cfg); + dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE; + ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, dma_cfg); if (ret != 0) { LOG_ERR("Failed to configure DMA channel %d", dev_data->dma.channel); return ret; } /* Proceed to the HAL DMA driver init */ - if (dma_cfg.source_data_size != dma_cfg.dest_data_size) { + if (dma_cfg->source_data_size != dma_cfg->dest_data_size) { LOG_ERR("Source and destination data sizes not aligned"); return -EINVAL; } - int index = find_lsb_set(dma_cfg.source_data_size) - 1; + int index = find_lsb_set(dma_cfg->source_data_size) - 1; #if CONFIG_DMA_STM32U5 /* Fill the structure for dma init */ @@ -2286,14 +2286,14 @@ static int flash_stm32_ospi_init(const struct device *dev) hdma.Init.MemInc = DMA_MINC_ENABLE; #endif /* CONFIG_DMA_STM32U5 */ hdma.Init.Mode = DMA_NORMAL; - hdma.Init.Priority = table_priority[dma_cfg.channel_priority]; + hdma.Init.Priority = table_priority[dma_cfg->channel_priority]; hdma.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel); #ifdef CONFIG_DMA_STM32_V1 /* TODO: Not tested in this configuration */ - hdma.Init.Channel = dma_cfg.dma_slot; + hdma.Init.Channel = dma_cfg->dma_slot; #else - hdma.Init.Request = dma_cfg.dma_slot; + hdma.Init.Request = dma_cfg->dma_slot; #endif /* CONFIG_DMA_STM32_V1 */ /* Initialize DMA HAL */ diff --git a/drivers/flash/flash_stm32_qspi.c b/drivers/flash/flash_stm32_qspi.c index a88b7a0aebf03..bde14f611bac8 100644 --- a/drivers/flash/flash_stm32_qspi.c +++ b/drivers/flash/flash_stm32_qspi.c @@ -1558,7 +1558,7 @@ static int flash_stm32_qspi_init(const struct device *dev) * the minimum information to inform the DMA slot will be in used and * how to route callbacks. */ - struct dma_config dma_cfg = dev_data->dma.cfg; + struct dma_config *dma_cfg = &dev_data->dma.cfg; static DMA_HandleTypeDef hdma; if (!device_is_ready(dev_data->dma.dev)) { @@ -1567,34 +1567,34 @@ static int flash_stm32_qspi_init(const struct device *dev) } /* Proceed to the minimum Zephyr DMA driver init */ - dma_cfg.user_data = &hdma; + dma_cfg->user_data = &hdma; /* HACK: This field is used to inform driver that it is overridden */ - dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE; - ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, &dma_cfg); + dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE; + ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, dma_cfg); if (ret != 0) { return ret; } /* Proceed to the HAL DMA driver init */ - if (dma_cfg.source_data_size != dma_cfg.dest_data_size) { + if (dma_cfg->source_data_size != dma_cfg->dest_data_size) { LOG_ERR("Source and destination data sizes not aligned"); return -EINVAL; } - int index = find_lsb_set(dma_cfg.source_data_size) - 1; + int index = find_lsb_set(dma_cfg->source_data_size) - 1; hdma.Init.PeriphDataAlignment = table_p_size[index]; hdma.Init.MemDataAlignment = table_m_size[index]; hdma.Init.PeriphInc = DMA_PINC_DISABLE; hdma.Init.MemInc = DMA_MINC_ENABLE; hdma.Init.Mode = DMA_NORMAL; - hdma.Init.Priority = table_priority[dma_cfg.channel_priority]; + hdma.Init.Priority = table_priority[dma_cfg->channel_priority]; hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel); #ifdef CONFIG_DMA_STM32_V1 /* TODO: Not tested in this configuration */ - hdma.Init.Channel = dma_cfg.dma_slot; + hdma.Init.Channel = dma_cfg->dma_slot; #else - hdma.Init.Request = dma_cfg.dma_slot; + hdma.Init.Request = dma_cfg->dma_slot; #endif /* CONFIG_DMA_STM32_V1 */ /* Initialize DMA HAL */ diff --git a/drivers/i2s/i2s_stm32_sai.c b/drivers/i2s/i2s_stm32_sai.c index a73a70ba775f4..aa18f2c712e11 100644 --- a/drivers/i2s/i2s_stm32_sai.c +++ b/drivers/i2s/i2s_stm32_sai.c @@ -279,7 +279,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev) { struct i2s_stm32_sai_data *dev_data = dev->data; struct stream *stream = &dev_data->stream; - struct dma_config dma_cfg = dev_data->stream.dma_cfg; + struct dma_config *dma_cfg = &dev_data->stream.dma_cfg; int ret; SAI_HandleTypeDef *hsai = &dev_data->hsai; @@ -291,12 +291,12 @@ static int i2s_stm32_sai_dma_init(const struct device *dev) } /* Proceed to the minimum Zephyr DMA driver init */ - dma_cfg.user_data = hdma; + dma_cfg->user_data = hdma; /* HACK: This field is used to inform driver that it is overridden */ - dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE; + dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE; - ret = dma_config(stream->dma_dev, stream->dma_channel, &dma_cfg); + ret = dma_config(stream->dma_dev, stream->dma_channel, dma_cfg); if (ret != 0) { LOG_ERR("Failed to configure DMA channel %d", stream->dma_channel); return ret; @@ -305,16 +305,16 @@ static int i2s_stm32_sai_dma_init(const struct device *dev) hdma->Instance = STM32_DMA_GET_INSTANCE(stream->reg, stream->dma_channel); hdma->Init.Mode = DMA_NORMAL; - if (dma_cfg.channel_priority >= ARRAY_SIZE(dma_priority)) { + if (dma_cfg->channel_priority >= ARRAY_SIZE(dma_priority)) { LOG_ERR("Invalid DMA channel priority"); return -EINVAL; } - hdma->Init.Priority = dma_priority[dma_cfg.channel_priority]; + hdma->Init.Priority = dma_priority[dma_cfg->channel_priority]; #if defined(DMA_CHANNEL_1) - hdma->Init.Channel = dma_cfg.dma_slot * DMA_CHANNEL_1; + hdma->Init.Channel = dma_cfg->dma_slot * DMA_CHANNEL_1; #else - hdma->Init.Request = dma_cfg.dma_slot; + hdma->Init.Request = dma_cfg->dma_slot; #endif #if defined(CONFIG_DMA_STM32U5) @@ -336,7 +336,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev) hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE; #endif - if (stream->dma_cfg.channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) { + if (dma_cfg->channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) { hdma->Init.Direction = DMA_MEMORY_TO_PERIPH; #if defined(CONFIG_DMA_STM32U5) diff --git a/drivers/video/video_stm32_dcmi.c b/drivers/video/video_stm32_dcmi.c index d59cc50c2090e..844d4433e6ba0 100644 --- a/drivers/video/video_stm32_dcmi.c +++ b/drivers/video/video_stm32_dcmi.c @@ -147,14 +147,14 @@ static int stm32_dma_init(const struct device *dev) * the minimum information to inform the DMA slot will be in used and * how to route callbacks. */ - struct dma_config dma_cfg = config->dma.cfg; + struct dma_config *dma_cfg = &config->dma.cfg; static DMA_HandleTypeDef hdma; /* Proceed to the minimum Zephyr DMA driver init */ - dma_cfg.user_data = &hdma; + dma_cfg->user_data = &hdma; /* HACK: This field is used to inform driver that it is overridden */ - dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE; - ret = dma_config(config->dma.dma_dev, config->dma.channel, &dma_cfg); + dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE; + ret = dma_config(config->dma.dma_dev, config->dma.channel, dma_cfg); if (ret != 0) { LOG_ERR("Failed to configure DMA channel %d", config->dma.channel); return ret;