cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a fix on using FREERTOS + FATFS + SDIO + DMA?

shabbir.hussain
Associate III

I am creating a project for the STM32F767ZI. The Fatfs library WITHOUT freeRTOS works well. When I include freeRTOS in my project, I cannot get past mounting the disk:

retSD = f_mount(&SDFatFS, (TCHAR const*) SDPath, 1);

From reading the forums, I found that some people have found a solution for certain MCUs. Is there a configuration where I can use FREERTOS + FATFS + SDIO + DMA?

My cubemx settings are as follows: I am using SDIO 1 bit bus and DMA for RX and TX. I have set my stack size to 0x2000, my heap size to 0x4000. I'm using FatFS with the DMA template.

6 REPLIES 6

Try keeping ALL the SDIO/FATFS stuff in a singular thread, and use DTCMRAM for all SDIO/SDMMC work. Put checks in DISKIO to confirm both memory usage AND alignment.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shabbir.hussain
Associate III

I am using it in a single thread. In fact, I'm calling the mount command in the "default task", so I'm already single threaded.

Is setting the SDIO to use DTCRAM an option in cubeMX?

Can you point to any resources for putting checks in DiskIO that check memory usage and alignment? On my cube IDE I see that my current project uses only 20% of the ram resources.

shabbir.hussain
Associate III

I have solved this issue and it comes down to choosing the correct cubeMX settings. Here are the settings that work on the STM32F767ZI:

SDMMC

  • SDIO 1 bit
  • Hardware flow control turned ON
  • enable NVIC for all 3 items in the table (it should read DMA2 chan 0, DMA2 chan5, SDMMC)
  • Add SDMMC_TX, SDMMC_RX in the DMA menu
  • Ensure DO and CMD pins in the GPIO have a pullup resistor

FreeRTOS

  • Enabled
  • Disable premption
  • under tasks and queues make the default task stack size 512 words

FatFS

  • Enable LFN
  • under platform settings choose a GPIO input pin to serve as the SD detect pin. Create one if the menu is empty.

Whoa! Any idea why you need to disable preemption??

I'm assuming that the FatFs library is not actually reentrant.

@shabbir.hussain​ - It doesn't need to be, unless you are using it in multiple tasks, or FatFS uses non-reentrant components (which it should not do), right ??