optimizing SD write access

flok

Well-known member
Hi,

I would like to optimize SD write access.
So ideally I would like to group multiple writes into one that fits in a erase-sector.
For that I need to know what offset ina file is for what erase-sector.
Is it possible to obtain that information somehow?
 
Have you perhaps tried searching "sdcard sector size" in google, bing, duckduckgo, or whatever your favorite search engine is? The answer is that it's going to be at least 512 bytes per sector but it likely erases 256k at once. However, you don't need to exactly match the erase size. Just match sector multiples as much as possible. It's not feasible, generally, to have a 256k buffer in your sketch but something like 8k could work and still, in my experience, works pretty well.
 
Have you tried looking at some of the example sketches that come with SD and SDFat?

Like with SD: Cardinfo.ino
SDFat: Sdinfo.ino
 
Have you tried looking at some of the example sketches that come with SD and SDFat?

Like with SD: Cardinfo.ino
SDFat: Sdinfo.ino

I did. In csdDmp (line 71 of SdInfo.ino) it says "erasesize is ... blocks" but it did not specify how big a block is (as 512 bytes is not a given these days, some media have 4k sectors).
Also it says 64512 blocks. Shouldn't that be a power of 2? Or is there something like error correction codes in there?
 
Last edited:
SD cards always have 512b sectors, 4KB sectors are only used on hard drives.
If it says "64512 blocks" I suspect the output formatting is wrong and it means 64 x 512b blocks.
 
You probably want to read the SD specification as it goes into more detail. It used to be pretty simple but with each new revision of the specification it has gotten more complicated. Recording Unit size, Allocation Unit size, Erase size. But if you are writing via something with a file system layer, just write in larger multiples of 512. 4K, 8K, etc.

Even then the card will occasionally take much longer than usual to complete a write. Made even worse if the file system code decides to update the directory and FAT data.
 
Back
Top