2024-05-14 06:06 AM
I want to use DMA with SPI in slave receive mode with words longer than 8 bits :
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.
Solved! Go to Solution.
2024-05-22 07:44 AM
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.
2024-05-15 02:21 PM
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).
2024-05-16 03:16 AM
2024-05-22 07:44 AM
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.