SD card - some questions

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all.
I've been reading the SD card spec, and I have some doubts..

I know that the smallest (and default) sector size is 512 bytes. Fine, but... can I read and/or write a sector that is not aligned to a sector address?
for example, may I be able to read 512 bytes starting from address 43d to 555d? And write a complete sector there? I found some info at the spec, but isn't quite clear.
There seems to be a bit at the CSD structure which I think is related to this, but it wouldn't work for me if it changes from SD to SD.

this question is because I have to write the SD sequentially, but writes are not sector-wide, and I don't have enough space to read a sector, then change it and write it again.

Thanks a lot,

Carlos

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Everything is done on a sector basis. With flash technology you have to erase a whole sector, therefore you have to write a whole sector. The address you send to the card is a sector address not a byte address.

If you don't have enough ram to read a sector, modify it, then write a sector then you have problems. However you can be a little creative and arrange your code so that you don't need to do this. Since you have a lot of storage on a SDcard you can usually afford to be a little wasteful - write only what you need to a sector and fill the rest with pad bytes. You can always write a program on the PC to strip these pad bytes out and write the correct data into another file.

There's plenty of tricks you can utilise to achieve a result - for example you don't need to have file system code on your micro to write a PC readable file - have the PC write one large file full of 0xff's and have your code search sequentially through until you hit a sector full of 0xff's - thats the current end of file - your micro can then write its data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have never investigated to find out if there are cards that will allow this, but there are fields within the CSD that are related (WRITE_BLK_MISALIGN and READ_BLK_MISALIGN, bits 78 and 77). These are set to 0 (i.e. NO) in normal cards, but someone, somewhere, sometime, was thinking ahead.

Roger

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well that's very useful info!

So then I will have to make a temporary buffer to read, modify and then write.. I guess there is no other way then.

thanks a lot!

Carlos