cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452 + SD + DMA + FATFS + STM32CubeMX v5.0.0: critical bug in Cube-generated code

Steve Melnikoff
Associate III

We are using an STM32L452 with SD, DMA and FATFS, with code generated with STM32CubeMX v5.0.0.

The code inserted by Cube in stm32l4xx_hal_msp.c, function HAL_SD_MspInit(), assigns various values to the hdma_sdmmc1.Init struct, and then uses them to initialise the chosen DMA channel. Significantly, Direction is set to DMA_PERIPH_TO_MEMORY, i.e. a read.

__HAL_LINKDMA is then used to associate this one DMA channel to both the rx and tx DMA channels in hsd (the SD card's context information) - even though there is only one DMA channel.

Thereafter, the first write operation fails, because the Direction is never changed.

As a result, the library code in its original form will never work for writes. Hence this is should be regarded as a critical bug.

It's possible to work around this by amending BSP_SD_ReadBlocks_DMA() and BSP_SD_WriteBlocks_DMA() to update the value of Direction as required, and then re-initialising the DMA channel.

Note that this bug was first reported in this thread more than a year ago, with a detailed workaround supplied a few months later by user Evgeny Kirshin.

Please could ST confirm that this will be addressed as a matter of urgency in the next version of Cube?

0 REPLIES 0