cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 SDCard Open File After a specific number of files

Murat
Associate III

Hello, 

I am using STM32F746 MCU and trying to use SDCard in DMA mode using FatFS.

This MCU has Cache also so for any conflict between DMA and the cache, I have disabled the cache. 

I am just trying to create files in an infinitive loop at startup. (Create, Write, Close, Increase File Name). 

But after a while I am not able to create file and f_open() returns DISK_ERROR; It always returns error for the same file number.

If I create files with short file names, it take long time to have the error.

(For example; If file names length is 15, I am starting to have error after 1500th file, but the file names length is 150, having error after the 600th file ).

The format is FAT32 so I would expect to have 65K files in a directory.

What I see, if the file name is aroung 150, after the 600th file, I dont get DMA_Complete Callback(and timeouts) and when I ask the SDCard state using HAL_SD_GetCardState(), it returns HAL_SD_CARD_SENDING.

Any suggestion?

Thank you.

10 REPLIES 10

Yes, but FAT doesn't carry around a file count, or optimize a directory content. A directory can contain empty records or voids when files are deleted. The only practical way is to walk the content and count files, folders, sizes, etc.

The content is also unsorted, so you'd need to build a file list and sort it manually on the MCU.​

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