Showing results for 
Search instead for 
Did you mean: 

Has anyone gotten SDMMC + DMA + FATFS + RTOS to work with CubeIDE?



There are several videos on youtube that beautifully demonstrate how easy it is to setup SDMMC + DMA + FATFS + RTOS in CubeIDE. I have followed these meticulously but I am unable to get it to work to my great frustration. There are several 3-year old theads on this forum in which users report the same problems. For instance this one:

The thread proposes a solution, but as the thread is 3 years old, I see some things changed in the code generated by CubeIDE in the meanwhile and I having a hard time getting the old proposed patch to work.

I only see that the DMA interrupts for rx and tx are not triggered at all.

I'm hoping someone got some experience with this with a more recent version of CubeIDE, since I would hope that the critical error that has been found 3 years ago has been addressed in some way.


For reference here are some step-by-step tutorials to implement SDMMC + DMA + FATFS + RTOS. I've followed these, without avail. I'm running on a STM32L433VCT.


I got it to work by following the resolution in this old thread:

Additionally, the stm32l4xx_hal_msp.c file needed to be changed too. I had to overwrite the original hdma_sdmmc1_rx.Instance = DMA2_Channel4; to become hdma_sdmmc1_rx.Instance = DMA2_Channel5;

Since both the channels for rx and tx need to be the same, which is something the MX user interface in CubeIDE does not allow.


  //overwrite the rx DMA channel, must be the same as the tx channel, this is a bug in STM32CubeIDE

  //for info see thread:


  hdma_sdmmc1_rx.Instance = DMA2_Channel5;

  if (HAL_DMA_Init(&hdma_sdmmc1_rx) != HAL_OK)





 /* USER CODE END SDMMC1_MspInit 1 */

So apparently, this critical bug in former CubeMX, now part of CubeIDE is still present 3 years after it has been found. Tested with STM32CubeIDE version 1.7.0


No quite there yet apparently. I got it to work, I can mount, read and write to my SD card, but I need to change the stack size for the thread in which this is running. Once I increase the stack size 256->512 the SD card fails to mount. Not sure what is going on here.

Another thing that makes me even more confused is when I try to use my SD card function in another project which does not use RTOS at all, the exact same code then fails to mount the card. I'm completely stuck.