Low level SD card logging

Would it be possible to have a very low level file system on an SD card or similar so that one could log simply and not have the SD rewrite the file system every time which can eventually break...The file system would ideally be a byte by byte writing system much like the EPROM chip memory access

It is certainly possible; but there are some limitations - most notably would be that you have to write in 512 byte sector blocks.

You could buffer the data until 512 bytes was received and then write the sector, move to the next sector, etc., or write a padded sector (2 real bytes, then 510 blank bytes).

You may even want to use the start sector to mark which is the current sector in case of power outage, or taking out and later replacing the data card for more logging.

However- remember that any given sector usually has a limit to the number of writes. If the limit for the card technology is 10,000 writes - then you can only write 10,000 sectors before the first sector can't be written to.

Most cards use wear levelling - i.e. you think you are reading/writing to sector 1, but the card maps it somewhere else so the card can exist after more than 10,000 writes.

I have worked on a Unix filesystem with Write-Once Magneto Optical media where the control data is written from the beginning of the media (aka sample date/time) and the data(sample data) is written from the end back until the two meet. In this scenario, any given sector is never overwritten. (With WORM media, you can not overwrite, ever, unlike your SD card.)

So I could do 510byte packages for a 2GB (say) card once or what? Im a little confused...So whatever I write i can only do 10,000 sectors once? The application would only have to do one total write and then one read once in its life as the application is high end.

most notably would be that you have to write in 512 byte sector blocks.

I think you can write individually but only erase in 512 byte sectors.

So whatever I write i can only do 10,000 sectors once?

No you can only write to the same byte in the same sector 10,000 times. Or in other words erase the same sector 10,000 times which amounts to the same thing.

Thanks, this clears that up.. Ive not done any work with SD cards so is there any good places with information as to how to write to them without FAT.

Have a look at:-

or do a Google for “SD card raw write”

It is unlikely that cards with wear levelling will ever break as a result of too many erase/write cycles. The SD specification was written well aware of the fact that cards are typically used with a FAT file system and the onchip controller will distribute data across all sectors to minimize wear for every single sector.

Consider the following:

  • SD card with 2GB capacity
  • Minimum 10,000 erase/write cycles per sector
  • We write 512 bytes or less to the card every second
  • We use FAT16 file system

Less than 3 writes per second on average (file system allocation table, directory record, data record). There are 4 writes when you cross a sector boundary, otherwise 2.

Total number of 512 byte blocks is 4194304 Total number of erase/write cycles is 4194304*10000 Number of seconds until card wears out is 4194304*10000/3

If we calculate above, this equals 443.03 years.

If we log data 10 times as often (or write 5kB every second) the card will still be OK (with respect to the erase/write limitation) for 40+ years. For data volumes higher than this we're likely to run into capacity issues and other limitations before we ever challenge the write/ease limitiation.

Thanks, sounds good. What about Micro SDs (I think this has been answered somewhere else)? Many thanks for the help...

MicroSD/MiniSD or SD dosn't realy matter in this context. The only difference is form factor (physical size). File system, write/erase cycles, speed, interface/protocol is all the same.

The SDHC (high capacity SD) cards however are made to a revised/updated SD specification and I would avoid these unless whatever hardware (interface/breakout design) and software you plan to use specifically states to be compatible with these cards.

I cant find the basic command set to get started with...Im using the mbed so I dont have to work out the whole SPI think to start with...