cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452 + SD + DMA + FATFS + STM32CubeMX v5.0.0: DMA and SD interrupts can signal end of transfer before it's complete

Steve Melnikoff
Associate III

We are using an STM32L452, running directly from an HSE crystal at 8 MHz (i.e. no PLL), using the SDMMC peripheral with an SD clock of 8 MHz, and DMA for transferring data to and from SDMMC.

When the DMA part of an SD read is complete, HAL_DMA_IRQHandler() calls hdma->XferCpltCallback, which for SD reads is SD_DMAReceiveCplt(), which then calls HAL_SD_RxCpltCallback(), and finally BSP_SD_ReadCpltCallback(), which signals that the read has finished.

However, it is possible that the SDMMC peripheral is still busy, and initiating another SD operation before it has finished could cause an error.

Similarly, when the SD part of a DMA write is complete, HAL_SD_IRQHandler() calls HAL_SD_TxCpltCallback() and BSP_SD_WriteCpltCallback(), which signals that the write has finished.

Again, it is possible that the DMA part of this operation is still busy at this point.

We found that the best way to avoid these subtle timing issues was to only call the callbacks when both the SD and DMA interrupts had completed. This ensured that all operations had completed.

We recommend that this be implemented in the library generated by Cube.

0 REPLIES 0