cancel
Showing results for 
Search instead for 
Did you mean: 

Using FatFS with freeRTOS

DBrau.2
Associate III

Can you recommend me any link showing how to configure it in CubeMX and what I have to do to write and read the SD card.

I have checked this https://controllerstech.com/interface-sd-card-with-sdio-in-stm32/ and it's working but no with freeRTOS. Not only when I move the code to taksa, but also if I leave it before starting tasks. It is enough to generate a code for freertos. I have also tried this https://www.programmersought.com/article/85814787223/ and this time it's mounting outside the task, but inside it's hanging out. And akso a lot of others site.

5 REPLIES 5
Houssem CHAABANI
Senior II

Hi @DBrau.2​ ,

If you are asking for a video tutorial you can add a comment in this link.

Otherwise you can activate freeRtos and FatFS under middleware in STM32CubeMX.

After that it depends on your needs and on your code workflow to manage FatFS with FreeRtos.

They are many solutions for this but it depends on your application.

I recommend that you create a thread to manage all the SD card data in/out, mounting/dismounting and other functionality.

Hope that this helps you!

Thanks!

The SDIO/SDMMC layer and peripheral is not multi-tasking, you need to arbitrate usage to single owner at a time. It is also really intolerant of users wandering off-task mid data transfer, the FIFO is not deep enough if you yield and lose focus.

Use DMA. Watch the memory region being used, the caching and alignment.

>>I recommend that you create a thread to manage all the SD card data in/out, mounting/dismounting and other functionality.

+1

Queue IO in a file management task, handling buffers, etc.

Ideally keep all FatFs f_read/f_write transactions aligned and multiples of sector size

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

@DBrau.2 did you solved your problem?

I'm just about to try CubeMX FatFS with manually added FreeRTOS (not from CubeMX) and I wonder if it will work.

According your problem - maybe FatFS needs bigger stack for task?

Bsm
Associate II

I created implementation with general operations for fatsfs & freertos with CubeMX u can test this code

github.com/Bsm-B/Stm32-FatFs-FreeRTOS/

Consider using a version of FatFS that isn't 7 years old, and buggy.

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