cancel
Showing results for 
Search instead for 
Did you mean: 

Initialization issue with STM32CubeMx and STM32U5xx when using circular GPDMA with SPI

JVERN.18
Associate III

I want to use DMA with SPI in slave receive mode with words longer than 8 bits :

JVERN18_0-1715690035756.png

I launch the DMA with the function: 
HAL_SPI_Receive_DMA( &HSPI_ADS, (uint8_t*)ads_dma_buffer, ADS_BUFFER_MAX_SIZE );
Unfortunately in this function the following test fails:

 

 /* Packing mode management is enabled by the DMA settings */
if (((hspi->Init.DataSize > SPI_DATASIZE_16BIT) && (hspi->hdmarx->Init.DestDataWidth != DMA_DEST_DATAWIDTH_WORD) && \
(IS_SPI_FULL_INSTANCE(hspi->Instance))) || \
((hspi->Init.DataSize > SPI_DATASIZE_8BIT) && (hspi->hdmarx->Init.DestDataWidth == DMA_DEST_DATAWIDTH_BYTE)))
{
/* Restriction the DMA data received is not allowed in this mode */
errorcode = HAL_ERROR;
__HAL_UNLOCK(hspi);
return errorcode;
}

 

Because the structure "hspi->hdmarx->Init" is never initialized.
It is not initialized, but the structure associated with the nodes is indeed initialized.
In the case where the data size is 8 bits, the test is correct because the returned and expected value is 0...
To validate the uninitialized "init" structure, I added the following code in the HAL_SPI_MspInit() function generated by the STMCubeMx

In my case it is SPI1 and the associated DMA is GPDMA1_Channel3. Obviously, the channel must be modified if another channel (or SPI) is used

 

    __HAL_LINKDMA(spiHandle, hdmarx, handle_GPDMA1_Channel3);

    if (HAL_DMA_ConfigChannelAttributes(&handle_GPDMA1_Channel3, DMA_CHANNEL_NPRIV) != HAL_OK)
    {
      Error_Handler();
    }

    /* SPI1 interrupt Init */
    HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(SPI1_IRQn);
  /* USER CODE BEGIN SPI1_MspInit 1 */
    //-------------------------------------------------------------------------
#warning Ajout pour test correct dans MX_SPI1_Init() : verifier que ce soit le bon handle !
	// Initialise le handle associé au DMA (idem hspi1.dmarx.Init après le link)
	handle_GPDMA1_Channel3.Init = NodeConfig.Init;
    //-------------------------------------------------------------------------
  /* USER CODE END SPI1_MspInit 1 */

 

The problem here arises with the SPI, but it is a general initialization problem. This problem is hidden if the data size is 8 bits, because in this case the test in HAL_SPI_Receive_DMA() (or any similar function) becomes valid.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee

Hi @JVERN.18 ,

An internal ticket (ID: 181606) is submitted to the Development team to fix this issue.

Thank you for your contribution.

PS: Internal ticket (ID: 181606) is only for reference, not available outside of ST.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

3 REPLIES 3
Imen.D
ST Employee

Hello @JVERN.18,

Thank you for having reported this.

Could you please share your ioc file which can be used to replicate the issue.

I will check the case and test with latest release of STM32CubeMX (v6.11.1) and STM32CubeU5 (v1.5).

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello Imen,

 

Thank you for your prompt response...

Here is the ioc file.

In my code:

#define HSPI_ADS hspi1

and the associated DMA is now GPDMA1_Channel1

 

Jean-Louis 

Imen.D
ST Employee

Hi @JVERN.18 ,

An internal ticket (ID: 181606) is submitted to the Development team to fix this issue.

Thank you for your contribution.

PS: Internal ticket (ID: 181606) is only for reference, not available outside of ST.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen