cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube Linked List generation issue

fsorin
Associate II

Hi all,

I'm using STM32Cube IDE (version 1.13.1, build 17479_20230728_0839 ) to manage my company project based on a STM32U5 MCU.

More specifically, I'm using linked list feature (for playing audio with SAI + DMA transfer) and I have noticed what appears to me as a bug in auto-generated code.

Basically, I have created through CubeMx one list named SAIQueue, with one node named NodeTx and the auto-generated initialization code is the following:

 

 

/**
  * @brief  DMA Linked-list SAIQueue configuration
  * @PAram  None
  * @retval None
  */
HAL_StatusTypeDef MX_SAIQueue_Config(void)
{
  HAL_StatusTypeDef ret = HAL_OK;
  /* DMA node configuration declaration */
  DMA_NodeConfTypeDef pNodeConfig;

  /* Set node configuration ################################################*/
  pNodeConfig.NodeType = DMA_GPDMA_LINEAR_NODE;
  pNodeConfig.Init.Request = GPDMA1_REQUEST_SAI1_B;
  pNodeConfig.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
  pNodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;
  pNodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;
  pNodeConfig.Init.DestInc = DMA_DINC_FIXED;
  pNodeConfig.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;
  pNodeConfig.Init.DestDataWidth = DMA_DEST_DATAWIDTH_HALFWORD;
  pNodeConfig.Init.SrcBurstLength = 1;
  pNodeConfig.Init.DestBurstLength = 1;
  pNodeConfig.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT0;
  pNodeConfig.Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
  pNodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;
  pNodeConfig.DataHandlingConfig.DataExchange = DMA_EXCHANGE_NONE;
  pNodeConfig.DataHandlingConfig.DataAlignment = DMA_DATA_RIGHTALIGN_ZEROPADDED;
  pNodeConfig.SrcAddress = 0;
  pNodeConfig.DstAddress = 0;
  pNodeConfig.DataSize = 0;

  /* Build NodeTx Node */
  ret |= HAL_DMAEx_List_BuildNode(&pNodeConfig, &NodeTx);

  /* Insert NodeTx to Queue */
  ret |= HAL_DMAEx_List_InsertNode_Tail(&SAIQueue, &NodeTx);

  ret |= HAL_DMAEx_List_SetCircularMode(&SAIQueue);

   return ret;
}

 

If I run this code without modification, I encounter an assert failure in HAL_DMAEx_List_BuildNode (line 1069 of file stm32u5xx_hal_dma_ex.c):

 

assert_param(IS_DMA_MODE(pNodeConfig->Init.Mode));

 

This is fixed by adding the following missing line in "pNodeConfig" structure initialization:

 

pNodeConfig.Init.Mode = DMA_NORMAL;

 

Obviously, if I do any modification on the ioc file and relaunch code generation, this line is deleted and the issue is back.

Am I missing something on the UI to generate this line properly? Should this be fixed?

Thanks in advance for any insights.

10 REPLIES 10

Hello @fsorin & thanks for your post. 

I have also just hit the same problem with STM32CubeIDE 1.16.0 and STM32CubeMX 6.12.0-RC9. 

In my opinion the code relies on pNodeConfig being initialised to all 0's (which it is not because it is a stack variable) before the node configuration is set.

My solution was to make an local copy of MX_SAIQueue_Config() which clears first clears pNodeConfig before setting the other values.

It would be nice if ST could fix this auto-generation bug. Note my function has an Ex() suffix...

 

#include "linked_list.h"

extern DMA_NodeTypeDef NodeTx;
extern DMA_QListTypeDef SAIQueue;

static HAL_StatusTypeDef MX_SAIQueue_ConfigEx(void)
{
	HAL_StatusTypeDef ret = HAL_OK;
	/* DMA node configuration declaration */
	DMA_NodeConfTypeDef pNodeConfig;

#if 1
	// Bug fix
	memset(&pNodeConfig, 0, sizeof(pNodeConfig));
#endif

	/* Set node configuration ################################################*/
	pNodeConfig.NodeType = DMA_GPDMA_LINEAR_NODE;
	pNodeConfig.Init.Request = GPDMA1_REQUEST_SAI1_A;
	pNodeConfig.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
	pNodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;
	pNodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;
	etc...