cancel
Showing results for 
Search instead for 
Did you mean: 

Configure SDMMC+FATFS+DMA+RTOS in STM32CubeMX for STM32L4

Evgeny Kirshin
Associate III
Posted on January 24, 2018 at 19:28

Hello,

There were questions similar to this before, but not exactly. 

This is applicable to STM32CubeMX V4.24.0 with STM32CubeL4 fw package V1.11.0 (latest at this time).

Previously code generated by STM32CubeMX for configuration of SDMMC+FATFS+DMA+RTOS was not working. Some workarounds were found on the discussion boards which required modification of code generated by STM32CubeMX (i.e. these modifications would be erased by following code regenerations). The code generated by STM32CubeMX did not match code from the STM32CubeL4 package (STM32Cube_FW_L4_V1.11.0\Projects\32L496GDISCOVERY\Applications\FatFs\FatFs_uSD_DMA_RTOS). For example, SD_initialize() function from sd_diskio.c was missing initialization of queue SDQueueID (compared to the same function in 

sd_diskio_dma_rtos.c from the STM32CubeL4 example). Essentially, the queue was left uninitialized at all (should this have been done by user?). 

Right now, in

STM32CubeMX V4.24.0 I see this has been corrected (initialization of SDQueueID is now present in the generated SD_initialize() function). However, it is still not clear how to correctly configure the project in 

STM32CubeMX and what are additional modifications required in the generated code (what is left to be done by user).

Also, the STM32CubeL4 example uses only one SDMMC DMA channel for both TX and RX. Is it possible to generate code from STM32CubeMX which will be using only one channel in the same way as the STM32CubeL4 example? Comparing the generated code by STM32CubeMX with the STM32CubeL4 example, it currently doesn't look like there is a way to adjust the code (by using only sections for USER code) so that it works as the example code. 

Does anyone have a solution for this? Are there guidelines on SDMMC+FATFS+DMA+RTOS project generation from STM32CubeMX?

Thank you.

#stm32-l4-sdmmc-fatfs-dma-stm32cubemx
3 REPLIES 3
Posted on January 24, 2018 at 19:39

It can't do things concurrently so I don't see a value argument to multiple DMA channels. Access to the peripheral/card must be serialized.

On the 4R9I-DISCO Write DMA is problematic for 1 block, I remediated that by using the non-DMA mode for (count == 1)

HAL_SD_ErrorCallback() is called on non-error conditions.

Not using FreeRTOS, or CubeMX, can't address issues there.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Evgeny Kirshin
Associate III
Posted on January 24, 2018 at 21:03

To follow-up.

The code generated by STM32CubeMX (when single DMA channel is chosen for SDMMC) contains the following block in the end of the HAL_SD_MSP_Init() function (in stm32l4xx_hal_msp.c):

...

/* 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. */

/* Be sure to change transfer direction before calling

HAL_SD_ReadBlocks_DMA or HAL_SD_WriteBlocks_DMA. */

__HAL_LINKDMA(hsd,hdmarx,hdma_sdmmc1);

__HAL_LINKDMA(hsd,hdmatx,hdma_sdmmc1);

...

So, the recommendation is '

to change transfer direction before calling 

HAL_SD_ReadBlocks_DMA or HAL_SD_WriteBlocks_DMA

'. So the question is how and where to correctly change the transfer direction?

Thanks.

Evgeny Kirshin
Associate III
Posted on April 11, 2018 at 22:37

I addressed this issue and described my solution here: