cancel
Showing results for 
Search instead for 
Did you mean: 

SDMMC, FATFS AND FREERTOS

yang hong
Associate II

I am working on FATFS, SDMMC WITH FREERTOS on NUCLEOH743ZI2. I use STM32CUBEMAX to config the program. however, the program doesn't work properly. sometimes, I can mount sd card properly, but when I try to open file. the program always get failed result (FR_INT_ERR). After I track the program, the error comes function "dir_sdi" when program try to create the file name. and also I try to check "FR_INT_ERR" reason from FATFS, it shows "Work area (file system object, file object or etc...) has been broken by stack overflow or something. This is the reason in most case.". I wonder memory or cache for stack causes the issue with memory alignment. Does anybody know how to fix it?

Thx.

7 REPLIES 7

SDMMC has very tight timing expectations, you can't wander off task. Especially the POLLED implementation

Stack usages should be easy enough to measure.

H7 when using DMA has alignment and cache coherency expectations.

Instrument the DISKIO level to understand the interactions and failure. Failure tends to cascade,

The FATFS implementation used by ST is VERY OLD (2017 ?), there are *KNOWN* limitations and failures with Large Media and FAT32, which classically result in Internal Failure.

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

my FATFS VERSION is R0.12C and stmcubeide (v1.70). I also use MDMA for SDMMC1 with 4 bit bus. So how can I fix this issue?

yang hong
Associate II

I did more test. The issue is when I try to create a new file with name creating. so call dir_register in f_open, then call dir_alloc() in function "dir_register", then call dir_sdi in function "dir_alloc", dir_sdi is Directory handling - Set directory index. So I think there are some issue on directory index. I create the file on the roont directory. Function dir_alloc reserve a block of directory entries. so there are some issue on dynamic memory management issue. Does anybody has the similar issue? and how to fix it.

If I stop FREERTOS and run program. everything work perfectly. and also if I create a empty file on SD card, f_open work perfectly as well. so I have narrowed issue on file name creating in directory index.

Migrate to a Newer version, say a least R0.13c, or why not the current one R0.14b (2021)

Mar 04, 2017 FatFs R0.12c

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

>>Does anybody has the similar issue?

Sure, I've complained about it for 3-4 years, but I'm also not using CubeMX to write my software, so I'm not trapped in ST's laziness to migrate to newer Middleware when that's actually a solution to fixing bugs in said middleware.

I'm also in the minority in actually soak testing the SDMMC/FATFS having filled 200 and 400 GB cards and validated the data and file system integrity on the STM32 and PC's

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

After I add SCB_CleanDCache() before f_open, f_getfree and f_stat. It seems the issue disappear. I will keep my eyes on it whether the same issue will comes out again or not.

Thank you so much!