Skip to content

Commit ccdf98a

Browse files
mariopajafabiobaltieri
authored andcommitted
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 a6b9f87 commit ccdf98a

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ static int flash_stm32_ospi_init(const struct device *dev)
22332233
* the minimum information to inform the DMA slot will be in used and
22342234
* how to route callbacks.
22352235
*/
2236-
struct dma_config dma_cfg = dev_data->dma.cfg;
2236+
struct dma_config *dma_cfg = &dev_data->dma.cfg;
22372237
static DMA_HandleTypeDef hdma;
22382238

22392239
if (!device_is_ready(dev_data->dma.dev)) {
@@ -2242,22 +2242,22 @@ static int flash_stm32_ospi_init(const struct device *dev)
22422242
}
22432243

22442244
/* Proceed to the minimum Zephyr DMA driver init */
2245-
dma_cfg.user_data = &hdma;
2245+
dma_cfg->user_data = &hdma;
22462246
/* HACK: This field is used to inform driver that it is overridden */
2247-
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
2248-
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, &dma_cfg);
2247+
dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE;
2248+
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, dma_cfg);
22492249
if (ret != 0) {
22502250
LOG_ERR("Failed to configure DMA channel %d", dev_data->dma.channel);
22512251
return ret;
22522252
}
22532253

22542254
/* Proceed to the HAL DMA driver init */
2255-
if (dma_cfg.source_data_size != dma_cfg.dest_data_size) {
2255+
if (dma_cfg->source_data_size != dma_cfg->dest_data_size) {
22562256
LOG_ERR("Source and destination data sizes not aligned");
22572257
return -EINVAL;
22582258
}
22592259

2260-
int index = find_lsb_set(dma_cfg.source_data_size) - 1;
2260+
int index = find_lsb_set(dma_cfg->source_data_size) - 1;
22612261

22622262
#if CONFIG_DMA_STM32U5
22632263
/* Fill the structure for dma init */
@@ -2277,14 +2277,14 @@ static int flash_stm32_ospi_init(const struct device *dev)
22772277
hdma.Init.MemInc = DMA_MINC_ENABLE;
22782278
#endif /* CONFIG_DMA_STM32U5 */
22792279
hdma.Init.Mode = DMA_NORMAL;
2280-
hdma.Init.Priority = table_priority[dma_cfg.channel_priority];
2280+
hdma.Init.Priority = table_priority[dma_cfg->channel_priority];
22812281
hdma.Init.Direction = DMA_PERIPH_TO_MEMORY;
22822282
hdma.Instance = STM32_DMA_GET_INSTANCE(dev_data->dma.reg, dev_data->dma.channel);
22832283
#ifdef CONFIG_DMA_STM32_V1
22842284
/* TODO: Not tested in this configuration */
2285-
hdma.Init.Channel = dma_cfg.dma_slot;
2285+
hdma.Init.Channel = dma_cfg->dma_slot;
22862286
#else
2287-
hdma.Init.Request = dma_cfg.dma_slot;
2287+
hdma.Init.Request = dma_cfg->dma_slot;
22882288
#endif /* CONFIG_DMA_STM32_V1 */
22892289

22902290
/* 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
@@ -303,7 +303,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
303303
{
304304
struct i2s_stm32_sai_data *dev_data = dev->data;
305305
struct stream *stream = &dev_data->stream;
306-
struct dma_config dma_cfg = dev_data->stream.dma_cfg;
306+
struct dma_config *dma_cfg = &dev_data->stream.dma_cfg;
307307
int ret;
308308

309309
SAI_HandleTypeDef *hsai = &dev_data->hsai;
@@ -315,12 +315,12 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
315315
}
316316

317317
/* Proceed to the minimum Zephyr DMA driver init */
318-
dma_cfg.user_data = hdma;
318+
dma_cfg->user_data = hdma;
319319

320320
/* HACK: This field is used to inform driver that it is overridden */
321-
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
321+
dma_cfg->linked_channel = STM32_DMA_HAL_OVERRIDE;
322322

323-
ret = dma_config(stream->dma_dev, stream->dma_channel, &dma_cfg);
323+
ret = dma_config(stream->dma_dev, stream->dma_channel, dma_cfg);
324324
if (ret != 0) {
325325
LOG_ERR("Failed to configure DMA channel %d", stream->dma_channel);
326326
return ret;
@@ -329,16 +329,16 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
329329
hdma->Instance = STM32_DMA_GET_INSTANCE(stream->reg, stream->dma_channel);
330330
hdma->Init.Mode = DMA_NORMAL;
331331

332-
if (dma_cfg.channel_priority >= ARRAY_SIZE(dma_priority)) {
332+
if (dma_cfg->channel_priority >= ARRAY_SIZE(dma_priority)) {
333333
LOG_ERR("Invalid DMA channel priority");
334334
return -EINVAL;
335335
}
336-
hdma->Init.Priority = dma_priority[dma_cfg.channel_priority];
336+
hdma->Init.Priority = dma_priority[dma_cfg->channel_priority];
337337

338338
#if defined(DMA_CHANNEL_1)
339-
hdma->Init.Channel = dma_cfg.dma_slot * DMA_CHANNEL_1;
339+
hdma->Init.Channel = dma_cfg->dma_slot * DMA_CHANNEL_1;
340340
#else
341-
hdma->Init.Request = dma_cfg.dma_slot;
341+
hdma->Init.Request = dma_cfg->dma_slot;
342342
#endif
343343

344344
if (dma_cfg.source_data_size != dma_cfg.dest_data_size) {
@@ -377,7 +377,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
377377
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
378378
#endif
379379

380-
if (stream->dma_cfg.channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) {
380+
if (dma_cfg->channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) {
381381
hdma->Init.Direction = DMA_MEMORY_TO_PERIPH;
382382

383383
#if defined(CONFIG_DMA_STM32U5)

0 commit comments

Comments
 (0)