cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid damaging SD card for large writes?

FLast.11.69
Associate II
Posted on January 29, 2016 at 09:44

I'm doing a project,needing to write the data at 400hz frequency ,that mean I have to write 1024 Byte to the card within 2.5ms ,and I must  ensure that data are written to the card even accident occur ,such as power outages,so I use f_sync after f_write every cycle,to save the data to card ,but  f_sync cost about 1.6ms ,it is too long ,is any people encountered such a problem,giving me some advices about this,i would appreciate that(sorry for my bad english)

#fatfs #sd #sdio #dma #stm32
4 REPLIES 4
carl2399
Associate II
Posted on January 29, 2016 at 10:17

You will have a much better model of how an SD card works if you imagine that you are interfacing to a computer (and not memory). SD card's are capable of high performance, but not always when you want it. You need to lower your expectations, and would be better off if you can have half a second (or even more) of buffering when writing to the SD card. 

1) Writing large amounts of sequential data is generally quite efficient. You should be able to get sustained write rates of almost megabytes per second.

2) Writing smaller amounts of sequential data (and expecting the sort of response that you want) is nowhere near as efficient - as you've already found!

3) Reversing direction and writing bytes earlier in a memory sector after having written bytes later in the sector is a disaster (100's of milliseconds of dead time as the SD ''computer'' deletes and rewrites the sector). 

This is true any time you access SD memory - it is not unique to the STM32, but is a characteristic of how SD memory works.

If at all possible - stick with writing large blocks of sequential data!

FLast.11.69
Associate II
Posted on January 29, 2016 at 12:25

First of all, I must thank you CJacobs,

nice fourm,and nice man,

I have benefited a lot from after your advices whilch 

makes me to a new understanding of how to use the sdcard

thanks a lot

Posted on January 29, 2016 at 21:39

The 1K Write/Flush is just a very poor strategy, if losing data to a primary power outage is the issue, perhaps you should focus on a graceful shutdown methodology that can detect the power going away with sufficient time to spend a couple of milliseconds to actually close the file properly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FLast.11.69
Associate II
Posted on February 01, 2016 at 01:55

Hello clive !After reading your advises,i think i should change my method now,by the way,my source code come you,thanks a lot