Skip to content

Commit a4b819f

Browse files
ABESTMkartben
authored andcommitted
driver: dma: stm32u5 Optimize stack consumption
Remove InitStructs of LL driver, since they take a lot of space on stack. This can cause stack overflow in some scenarios. Signed-off-by: Adam Berlinger <[email protected]>
1 parent 71bbe52 commit a4b819f

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

drivers/dma/dma_stm32u5.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ static int dma_stm32_configure(const struct device *dev,
350350
struct dma_stm32_stream *stream =
351351
&dev_config->streams[id - STM32_DMA_STREAM_OFFSET];
352352
DMA_TypeDef *dma = (DMA_TypeDef *)dev_config->base;
353-
LL_DMA_InitTypeDef DMA_InitStruct;
353+
uint32_t ll_priority;
354+
uint32_t ll_direction;
354355
int ret;
355356

356357
/* Linked list Node and structure initialization */
@@ -360,7 +361,6 @@ static int dma_stm32_configure(const struct device *dev,
360361

361362
LL_DMA_ListStructInit(&DMA_InitLinkedListStruct);
362363
LL_DMA_NodeStructInit(&NodeConfig);
363-
LL_DMA_StructInit(&DMA_InitStruct);
364364

365365
/* Give channel from index 0 */
366366
id = id - STM32_DMA_STREAM_OFFSET;
@@ -431,31 +431,32 @@ static int dma_stm32_configure(const struct device *dev,
431431
LOG_WRN("dest_buffer address is null.");
432432
}
433433

434-
DMA_InitStruct.SrcAddress = config->head_block->source_address;
435-
DMA_InitStruct.DestAddress = config->head_block->dest_address;
434+
LL_DMA_ConfigAddresses(dma, dma_stm32_id_to_stream(id), config->head_block->source_address,
435+
config->head_block->dest_address);
436+
436437
NodeConfig.SrcAddress = config->head_block->source_address;
437438
NodeConfig.DestAddress = config->head_block->dest_address;
438439
NodeConfig.BlkDataLength = config->head_block->block_size;
439440

440-
ret = dma_stm32_get_priority(config->channel_priority,
441-
&DMA_InitStruct.Priority);
441+
ret = dma_stm32_get_priority(config->channel_priority, &ll_priority);
442442
if (ret < 0) {
443443
return ret;
444444
}
445+
LL_DMA_SetChannelPriorityLevel(dma, dma_stm32_id_to_stream(id), ll_priority);
445446

446-
ret = dma_stm32_get_direction(config->channel_direction,
447-
&DMA_InitStruct.Direction);
447+
ret = dma_stm32_get_direction(config->channel_direction, &ll_direction);
448448
if (ret < 0) {
449449
return ret;
450450
}
451+
LL_DMA_SetDataTransferDirection(dma, dma_stm32_id_to_stream(id), ll_direction);
451452

452453
/* This part is for source */
453454
switch (config->head_block->source_addr_adj) {
454455
case DMA_ADDR_ADJ_INCREMENT:
455-
DMA_InitStruct.SrcIncMode = LL_DMA_SRC_INCREMENT;
456+
LL_DMA_SetSrcIncMode(dma, dma_stm32_id_to_stream(id), LL_DMA_SRC_INCREMENT);
456457
break;
457458
case DMA_ADDR_ADJ_NO_CHANGE:
458-
DMA_InitStruct.SrcIncMode = LL_DMA_SRC_FIXED;
459+
LL_DMA_SetSrcIncMode(dma, dma_stm32_id_to_stream(id), LL_DMA_SRC_FIXED);
459460
break;
460461
case DMA_ADDR_ADJ_DECREMENT:
461462
return -ENOTSUP;
@@ -464,16 +465,16 @@ static int dma_stm32_configure(const struct device *dev,
464465
config->head_block->source_addr_adj);
465466
return -EINVAL;
466467
}
467-
LOG_DBG("Channel (%d) src inc (%x).",
468-
id, DMA_InitStruct.SrcIncMode);
468+
LOG_DBG("Channel (%d) src inc (%x).", id,
469+
LL_DMA_GetSrcIncMode(dma, dma_stm32_id_to_stream(id)));
469470

470471
/* This part is for dest */
471472
switch (config->head_block->dest_addr_adj) {
472473
case DMA_ADDR_ADJ_INCREMENT:
473-
DMA_InitStruct.DestIncMode = LL_DMA_DEST_INCREMENT;
474+
LL_DMA_SetDestIncMode(dma, dma_stm32_id_to_stream(id), LL_DMA_DEST_INCREMENT);
474475
break;
475476
case DMA_ADDR_ADJ_NO_CHANGE:
476-
DMA_InitStruct.DestIncMode = LL_DMA_DEST_FIXED;
477+
LL_DMA_SetDestIncMode(dma, dma_stm32_id_to_stream(id), LL_DMA_DEST_FIXED);
477478
break;
478479
case DMA_ADDR_ADJ_DECREMENT:
479480
return -ENOTSUP;
@@ -482,35 +483,35 @@ static int dma_stm32_configure(const struct device *dev,
482483
config->head_block->dest_addr_adj);
483484
return -EINVAL;
484485
}
485-
LOG_DBG("Channel (%d) dest inc (%x).",
486-
id, DMA_InitStruct.DestIncMode);
486+
LOG_DBG("Channel (%d) dest inc (%x).", id,
487+
LL_DMA_GetDestIncMode(dma, dma_stm32_id_to_stream(id)));
487488

488489
stream->source_periph = (stream->direction == PERIPHERAL_TO_MEMORY);
489490

490491
/* Set the data width, when source_data_size equals dest_data_size */
491492
int index = find_lsb_set(config->source_data_size) - 1;
492493

493-
DMA_InitStruct.SrcDataWidth = table_src_size[index];
494+
LL_DMA_SetSrcDataWidth(dma, dma_stm32_id_to_stream(id), table_src_size[index]);
494495

495496
index = find_lsb_set(config->dest_data_size) - 1;
496-
DMA_InitStruct.DestDataWidth = table_dst_size[index];
497+
LL_DMA_SetDestDataWidth(dma, dma_stm32_id_to_stream(id), table_dst_size[index]);
497498

498-
DMA_InitStruct.BlkDataLength = config->head_block->block_size;
499+
LL_DMA_SetBlkDataLength(dma, dma_stm32_id_to_stream(id), config->head_block->block_size);
499500

500501
/* The request ID is stored in the dma_slot */
501-
DMA_InitStruct.Request = config->dma_slot;
502+
LL_DMA_SetPeriphRequest(dma, dma_stm32_id_to_stream(id), config->dma_slot);
502503

503504
if (config->head_block->source_reload_en == 0) {
504505
/* Initialize the DMA structure in non-cyclic mode only */
505-
LL_DMA_Init(dma, dma_stm32_id_to_stream(id), &DMA_InitStruct);
506+
LL_DMA_SetLinkedListAddrOffset(dma, dma_stm32_id_to_stream(id), 0);
506507
} else {/* cyclic mode */
507508
/* Setting GPDMA request */
508-
NodeConfig.DestDataWidth = DMA_InitStruct.DestDataWidth;
509-
NodeConfig.SrcDataWidth = DMA_InitStruct.SrcDataWidth;
510-
NodeConfig.DestIncMode = DMA_InitStruct.DestIncMode;
511-
NodeConfig.SrcIncMode = DMA_InitStruct.SrcIncMode;
512-
NodeConfig.Direction = DMA_InitStruct.Direction;
513-
NodeConfig.Request = DMA_InitStruct.Request;
509+
NodeConfig.DestDataWidth = table_dst_size[index];
510+
NodeConfig.SrcDataWidth = table_src_size[index];
511+
NodeConfig.DestIncMode = LL_DMA_GetDestIncMode(dma, dma_stm32_id_to_stream(id));
512+
NodeConfig.SrcIncMode = LL_DMA_GetSrcIncMode(dma, dma_stm32_id_to_stream(id));
513+
NodeConfig.Direction = ll_direction;
514+
NodeConfig.Request = config->dma_slot;
514515

515516
/* Continuous transfers with Linked List */
516517
stream->cyclic = true;

0 commit comments

Comments
 (0)