Skip to content

Commit ae6322a

Browse files
committed
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 <[email protected]>
1 parent 1a49b41 commit ae6322a

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ static int flash_stm32_ospi_init(const struct device *dev)
22422242
* the minimum information to inform the DMA slot will be in used and
22432243
* how to route callbacks.
22442244
*/
2245-
struct dma_config dma_cfg = dev_data->dma.cfg;
2245+
struct dma_config *dma_cfg = &dev_data->dma.cfg;
22462246
static DMA_HandleTypeDef hdma;
22472247

22482248
if (!device_is_ready(dev_data->dma.dev)) {
@@ -2251,22 +2251,22 @@ static int flash_stm32_ospi_init(const struct device *dev)
22512251
}
22522252

22532253
/* Proceed to the minimum Zephyr DMA driver init */
2254-
dma_cfg.user_data = &hdma;
2254+
dma_cfg->user_data = &hdma;
22552255
/* HACK: This field is used to inform driver that it is overridden */
2256-
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
2257-
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, &dma_cfg);
2256+
dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE;
2257+
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, dma_cfg);
22582258
if (ret != 0) {
22592259
LOG_ERR("Failed to configure DMA channel %d", dev_data->dma.channel);
22602260
return ret;
22612261
}
22622262

22632263
/* Proceed to the HAL DMA driver init */
2264-
if (dma_cfg.source_data_size != dma_cfg.dest_data_size) {
2264+
if (dma_cfg->source_data_size != dma_cfg->dest_data_size) {
22652265
LOG_ERR("Source and destination data sizes not aligned");
22662266
return -EINVAL;
22672267
}
22682268

2269-
int index = find_lsb_set(dma_cfg.source_data_size) - 1;
2269+
int index = find_lsb_set(dma_cfg->source_data_size) - 1;
22702270

22712271
#if CONFIG_DMA_STM32U5
22722272
/* Fill the structure for dma init */
@@ -2286,14 +2286,14 @@ static int flash_stm32_ospi_init(const struct device *dev)
22862286
hdma.Init.MemInc = DMA_MINC_ENABLE;
22872287
#endif /* CONFIG_DMA_STM32U5 */
22882288
hdma.Init.Mode = DMA_NORMAL;
2289-
hdma.Init.Priority = table_priority[dma_cfg.channel_priority];
2289+
hdma.Init.Priority = table_priority[dma_cfg->channel_priority];
22902290
hdma.Init.Direction = DMA_PERIPH_TO_MEMORY;
22912291
hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel);
22922292
#ifdef CONFIG_DMA_STM32_V1
22932293
/* TODO: Not tested in this configuration */
2294-
hdma.Init.Channel = dma_cfg.dma_slot;
2294+
hdma.Init.Channel = dma_cfg->dma_slot;
22952295
#else
2296-
hdma.Init.Request = dma_cfg.dma_slot;
2296+
hdma.Init.Request = dma_cfg->dma_slot;
22972297
#endif /* CONFIG_DMA_STM32_V1 */
22982298

22992299
/* Initialize DMA HAL */

drivers/flash/flash_stm32_qspi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ static int flash_stm32_qspi_init(const struct device *dev)
15581558
* the minimum information to inform the DMA slot will be in used and
15591559
* how to route callbacks.
15601560
*/
1561-
struct dma_config dma_cfg = dev_data->dma.cfg;
1561+
struct dma_config *dma_cfg = &dev_data->dma.cfg;
15621562
static DMA_HandleTypeDef hdma;
15631563

15641564
if (!device_is_ready(dev_data->dma.dev)) {
@@ -1567,34 +1567,34 @@ static int flash_stm32_qspi_init(const struct device *dev)
15671567
}
15681568

15691569
/* Proceed to the minimum Zephyr DMA driver init */
1570-
dma_cfg.user_data = &hdma;
1570+
dma_cfg->user_data = &hdma;
15711571
/* HACK: This field is used to inform driver that it is overridden */
1572-
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
1573-
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, &dma_cfg);
1572+
dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE;
1573+
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, dma_cfg);
15741574
if (ret != 0) {
15751575
return ret;
15761576
}
15771577

15781578
/* Proceed to the HAL DMA driver init */
1579-
if (dma_cfg.source_data_size != dma_cfg.dest_data_size) {
1579+
if (dma_cfg->source_data_size != dma_cfg->dest_data_size) {
15801580
LOG_ERR("Source and destination data sizes not aligned");
15811581
return -EINVAL;
15821582
}
15831583

1584-
int index = find_lsb_set(dma_cfg.source_data_size) - 1;
1584+
int index = find_lsb_set(dma_cfg->source_data_size) - 1;
15851585

15861586
hdma.Init.PeriphDataAlignment = table_p_size[index];
15871587
hdma.Init.MemDataAlignment = table_m_size[index];
15881588
hdma.Init.PeriphInc = DMA_PINC_DISABLE;
15891589
hdma.Init.MemInc = DMA_MINC_ENABLE;
15901590
hdma.Init.Mode = DMA_NORMAL;
1591-
hdma.Init.Priority = table_priority[dma_cfg.channel_priority];
1591+
hdma.Init.Priority = table_priority[dma_cfg->channel_priority];
15921592
hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel);
15931593
#ifdef CONFIG_DMA_STM32_V1
15941594
/* TODO: Not tested in this configuration */
1595-
hdma.Init.Channel = dma_cfg.dma_slot;
1595+
hdma.Init.Channel = dma_cfg->dma_slot;
15961596
#else
1597-
hdma.Init.Request = dma_cfg.dma_slot;
1597+
hdma.Init.Request = dma_cfg->dma_slot;
15981598
#endif /* CONFIG_DMA_STM32_V1 */
15991599

16001600
/* Initialize DMA HAL */

drivers/i2s/i2s_stm32_sai.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
279279
{
280280
struct i2s_stm32_sai_data *dev_data = dev->data;
281281
struct stream *stream = &dev_data->stream;
282-
struct dma_config dma_cfg = dev_data->stream.dma_cfg;
282+
struct dma_config *dma_cfg = &dev_data->stream.dma_cfg;
283283
int ret;
284284

285285
SAI_HandleTypeDef *hsai = &dev_data->hsai;
@@ -291,12 +291,12 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
291291
}
292292

293293
/* Proceed to the minimum Zephyr DMA driver init */
294-
dma_cfg.user_data = hdma;
294+
dma_cfg->user_data = hdma;
295295

296296
/* HACK: This field is used to inform driver that it is overridden */
297-
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
297+
dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE;
298298

299-
ret = dma_config(stream->dma_dev, stream->dma_channel, &dma_cfg);
299+
ret = dma_config(stream->dma_dev, stream->dma_channel, dma_cfg);
300300
if (ret != 0) {
301301
LOG_ERR("Failed to configure DMA channel %d", stream->dma_channel);
302302
return ret;
@@ -305,16 +305,16 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
305305
hdma->Instance = STM32_DMA_GET_INSTANCE(stream->reg, stream->dma_channel);
306306
hdma->Init.Mode = DMA_NORMAL;
307307

308-
if (dma_cfg.channel_priority >= ARRAY_SIZE(dma_priority)) {
308+
if (dma_cfg->channel_priority >= ARRAY_SIZE(dma_priority)) {
309309
LOG_ERR("Invalid DMA channel priority");
310310
return -EINVAL;
311311
}
312-
hdma->Init.Priority = dma_priority[dma_cfg.channel_priority];
312+
hdma->Init.Priority = dma_priority[dma_cfg->channel_priority];
313313

314314
#if defined(DMA_CHANNEL_1)
315-
hdma->Init.Channel = dma_cfg.dma_slot * DMA_CHANNEL_1;
315+
hdma->Init.Channel = dma_cfg->dma_slot * DMA_CHANNEL_1;
316316
#else
317-
hdma->Init.Request = dma_cfg.dma_slot;
317+
hdma->Init.Request = dma_cfg->dma_slot;
318318
#endif
319319

320320
#if defined(CONFIG_DMA_STM32U5)
@@ -336,7 +336,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
336336
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
337337
#endif
338338

339-
if (stream->dma_cfg.channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) {
339+
if (dma_cfg->channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) {
340340
hdma->Init.Direction = DMA_MEMORY_TO_PERIPH;
341341

342342
#if defined(CONFIG_DMA_STM32U5)

drivers/video/video_stm32_dcmi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ static int stm32_dma_init(const struct device *dev)
147147
* the minimum information to inform the DMA slot will be in used and
148148
* how to route callbacks.
149149
*/
150-
struct dma_config dma_cfg = config->dma.cfg;
150+
struct dma_config *dma_cfg = &config->dma.cfg;
151151
static DMA_HandleTypeDef hdma;
152152

153153
/* Proceed to the minimum Zephyr DMA driver init */
154-
dma_cfg.user_data = &hdma;
154+
dma_cfg->user_data = &hdma;
155155
/* HACK: This field is used to inform driver that it is overridden */
156-
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
157-
ret = dma_config(config->dma.dma_dev, config->dma.channel, &dma_cfg);
156+
dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE;
157+
ret = dma_config(config->dma.dma_dev, config->dma.channel, dma_cfg);
158158
if (ret != 0) {
159159
LOG_ERR("Failed to configure DMA channel %d", config->dma.channel);
160160
return ret;

0 commit comments

Comments
 (0)