cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 SAI DMA

alvaro_sofar
Associate II

I'm trying to get SAI working with DMA on a NUCLEO-U575ZI-Q but have not been successful.

I've tried using both standard request mode and linked-list mode, but the DMA configuration code is never generated.

On an older STM32L4 project, the bottom of `HAL_SAI_MspInit` looked like:

    hdma_sai1_a.Instance = DMA2_Channel1;
    hdma_sai1_a.Init.Request = DMA_REQUEST_1;
    hdma_sai1_a.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_sai1_a.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_sai1_a.Init.MemInc = DMA_MINC_ENABLE;
    hdma_sai1_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    hdma_sai1_a.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    hdma_sai1_a.Init.Mode = DMA_CIRCULAR;
    hdma_sai1_a.Init.Priority = DMA_PRIORITY_LOW;
    if (HAL_DMA_Init(&hdma_sai1_a) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Several peripheral DMA handle pointers point to the same DMA handle.
     Be aware that there is only one channel to perform all the requested DMAs. */
    __HAL_LINKDMA(saiHandle,hdmarx,hdma_sai1_a);
    __HAL_LINKDMA(saiHandle,hdmatx,hdma_sai1_a);

With the U5, that code is never generated. Then whenever I call `HAL_SAI_Receive_DMA`, the device crashes since it tries to access `hsai->hdmarx->....` but since hdmarx is still NULL, it's dereferencing a NULL pointer.

/* Set the SAI Rx DMA Half transfer complete callback */
    hsai->hdmarx->XferHalfCpltCallback = SAI_DMARxHalfCplt;
 
    /* Set the SAI Rx DMA transfer complete callback */
    hsai->hdmarx->XferCpltCallback = SAI_DMARxCplt;
 
    /* Set the DMA error callback */
    hsai->hdmarx->XferErrorCallback = SAI_DMAError;
 
    /* Set the DMA Rx abort callback */
    hsai->hdmarx->XferAbortCallback = NULL;

What do I need to do to generate the appropriate initialization code?

Here are some screenshots of the cubemx config in Standard Request Mode. I'm also attaching the CubeMx .ioc file.

I'm using STM32CubeMx v6.6.1 with STM32Cube_FW_U5 v1.1.1

0693W00000aHt3cQAC.png0693W00000aHt3hQAC.png 

Thank you!

Alvaro

1 ACCEPTED SOLUTION

Accepted Solutions
christop
ST Employee

Hi Alvaro,

I have used your .ioc file ith STM32CubeMX v6.6.1 and v6.7.0 (after migration) and STM32CubeU5 FW library v1.1.1, and the code is generated for the DMA for SAI. The code appears in HAL_SAI_MspInit() in sai.c (see attached). Please retry.

However with the generated code, the compilation is failing due to mismatch of some variable declarations for the DMA list and node:

arm-none-eabi-gcc "../Core/Src/spi.c" -mcpu=cortex-m33 -std=gnu11 -g3 -DDEBUG -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -DSTM32U575xx -c -I../Core/Inc -I../Drivers/STM32U5xx_HAL_Driver/Inc -I../Drivers/STM32U5xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32U5xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/spi.d" -MT"Core/Src/spi.o" --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/spi.o"

../Core/Src/sai.c: In function 'HAL_SAI_MspInit':

../Core/Src/sai.c:137:48: error: 'Node_GPDMA1_Channel01' undeclared (first use in this function); did you mean 'Node_GPDMA1_Channel0'?

 137 |   if (HAL_DMAEx_List_BuildNode(&NodeConfig, &Node_GPDMA1_Channel01) != HAL_OK)

   |                        ^~~~~~~~~~~~~~~~~~~~~

   |                        Node_GPDMA1_Channel0

../Core/Src/sai.c:137:48: note: each undeclared identifier is reported only once for each function it appears in

../Core/Src/sai.c:142:36: error: 'List_GPDMA1_Channel01' undeclared (first use in this function); did you mean 'List_GPDMA1_Channel0'?

 142 |   if (HAL_DMAEx_List_InsertNode(&List_GPDMA1_Channel01, NULL, &Node_GPDMA1_Channel01) != HAL_OK)

   |                  ^~~~~~~~~~~~~~~~~~~~~

   |                  List_GPDMA1_Channel0

The variables are declared as below in sai.c:

DMA_NodeTypeDef Node_GPDMA1_Channel0;

DMA_QListTypeDef List_GPDMA1_Channel0;

but in the function calls, they are named as:

Node_GPDMA1_Channel01

List_GPDMA1_Channel01

For some reasons, the generated code has a "1" added at the end of the names of the 2 variables.

I will report this issue to STM32CubeMX development team.

Regards,

Christophe

View solution in original post

3 REPLIES 3
christop
ST Employee

Hi Alvaro,

I have used your .ioc file ith STM32CubeMX v6.6.1 and v6.7.0 (after migration) and STM32CubeU5 FW library v1.1.1, and the code is generated for the DMA for SAI. The code appears in HAL_SAI_MspInit() in sai.c (see attached). Please retry.

However with the generated code, the compilation is failing due to mismatch of some variable declarations for the DMA list and node:

arm-none-eabi-gcc "../Core/Src/spi.c" -mcpu=cortex-m33 -std=gnu11 -g3 -DDEBUG -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -DSTM32U575xx -c -I../Core/Inc -I../Drivers/STM32U5xx_HAL_Driver/Inc -I../Drivers/STM32U5xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32U5xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/spi.d" -MT"Core/Src/spi.o" --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/spi.o"

../Core/Src/sai.c: In function 'HAL_SAI_MspInit':

../Core/Src/sai.c:137:48: error: 'Node_GPDMA1_Channel01' undeclared (first use in this function); did you mean 'Node_GPDMA1_Channel0'?

 137 |   if (HAL_DMAEx_List_BuildNode(&NodeConfig, &Node_GPDMA1_Channel01) != HAL_OK)

   |                        ^~~~~~~~~~~~~~~~~~~~~

   |                        Node_GPDMA1_Channel0

../Core/Src/sai.c:137:48: note: each undeclared identifier is reported only once for each function it appears in

../Core/Src/sai.c:142:36: error: 'List_GPDMA1_Channel01' undeclared (first use in this function); did you mean 'List_GPDMA1_Channel0'?

 142 |   if (HAL_DMAEx_List_InsertNode(&List_GPDMA1_Channel01, NULL, &Node_GPDMA1_Channel01) != HAL_OK)

   |                  ^~~~~~~~~~~~~~~~~~~~~

   |                  List_GPDMA1_Channel0

The variables are declared as below in sai.c:

DMA_NodeTypeDef Node_GPDMA1_Channel0;

DMA_QListTypeDef List_GPDMA1_Channel0;

but in the function calls, they are named as:

Node_GPDMA1_Channel01

List_GPDMA1_Channel01

For some reasons, the generated code has a "1" added at the end of the names of the 2 variables.

I will report this issue to STM32CubeMX development team.

Regards,

Christophe

alvaro_sofar
Associate II

Thanks Christophe!

I appreciate the quick response.

I must have been having a bad day yesterday since I never got to this point. Now that I've added your fixes it's all working perfectly! I'll make a note to change the variables back in case anyone else re-generates the code in the near future.

Alvaro

maxborglowe
Associate III

@christop have you got any feedback on the erroneous generation of Node_GPDMA1_Channel01, and List_GPDMA1_Channel01? I had exactly this issue now, a year after this thread started, so the error still remains. Kind of an annoying bug since it regenerates the faulty variables every time you make changes in the .ioc.

//Max