cancel
Showing results for 
Search instead for 
Did you mean: 

Random high write times on SD card with STM32 and FileX

Benjamin_ls
Visitor

I am doing a datalogger application with a custom piece of hardware using STM32 and FileX middleware. While datalogging, it occassionally experiences a spike in write and flush times that seems to be random to me. So I tried to make a simple application just to test it.

The setup: The custom board uses STM32H563 MCU directly connected to the SD card slot hardware component. I generated my code using STM32CubeMX with FileX in standalone mode. So I am not using LevelX or ThreadX (from Azure RTOS). The SDMMC peripheral has a clock speed of 25MHz, with 0 SDMMC clock divide factor. This gives me the maximum SD default speed according to the reference manual. The SD cards used are FAT32 with 4096KB sector size.

For debugging and testing purposes, I am continuously logging an array of 32768 bytes that is in the program. I have given the media file 102400 bytes that is aligned to 32 bytes. The code is simple. With the media and file open, the code writes the 32KB of data and immediately flush the data repeatedly. I time the write and flush operations with a timer and log it into the array that I can see when I pause the debugging. For all tests, I run them in debug mode with a ST link V2 clone.

What I found and thought so far: The write and flush times are consistent. Until randomly, the write and flush time spikes up. As an example, it normally takes 40ms per write and flush, and when it spikes, it takes 800ms instead.

I have done the test with and without formatting the SD card and it seems the time spikes occur after a similar number of writes, but never really the same.

The frequency of this happening seems to be significantly higher on an unbranded SD card. On branded SD cards, it happens rarely, like once every 3000+ writes. The size of the spike also varies, it could be 200ms to 800ms.

The datalogger has suffcient writing speed for my application. However, when a spike in time like this occurs, my buffers may overflow. I would like to understand what are these spikes in time, and if there is any way to avoid it other than to increase my buffers.

My questions are: Could they be caused by the attached debugger? Is this the result of some garbage collection, SD FAT table udpates or bad sectors? Is this spike in time similar for other applications? I do not have any other possible datalogger in my possession right now.

0 REPLIES 0