how to initialize (erase) an SD card

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to initialize (erase) an SD card

Jump to solution
1,690 Views
MPotts
Contributor III

Hi,

 

I have mnaged to get the sample MQX SPI and SDcard drivers working and can fread() and fwrite() sectors to an SD card with no problems (so far). I also need to erase the card but I don't think there is any facility to do this at the SDcard driver level. I assume I will have to drop back to SPI level and send some low-level SD/SPI commands. Does anyone have experience with this that they could share.

 

Thanks,

Mark

Labels (1)
Tags (1)
0 Kudos
1 Solution
685 Views
PetrM
Senior Contributor I

Hello,

 

well, there are 3 options:

1) Don't erase anything, just format the drive/paritition, which means normal write to few first sectors with partition information, FAT table and root directory. That's what MFS does during format. The old data are not accesible anymore.

2) Simply write some pattern (zeros) all over the SD card space.

3) Add support for SD SPI erase commands that should behave similarly to CMD24 which is already there. And there should be new erase IOCTL command at generic SD card level calling the new low level SD SPI commands.

 

Regards,

PetrM

 

View solution in original post

0 Kudos
2 Replies
686 Views
PetrM
Senior Contributor I

Hello,

 

well, there are 3 options:

1) Don't erase anything, just format the drive/paritition, which means normal write to few first sectors with partition information, FAT table and root directory. That's what MFS does during format. The old data are not accesible anymore.

2) Simply write some pattern (zeros) all over the SD card space.

3) Add support for SD SPI erase commands that should behave similarly to CMD24 which is already there. And there should be new erase IOCTL command at generic SD card level calling the new low level SD SPI commands.

 

Regards,

PetrM

 

0 Kudos
685 Views
MPotts
Contributor III

Hi Petr,

 

Thanks for the adv ice. I am not using a file system but rather using the entire card as a giant hash table. This means that option 1 would not help and option 2 would be very time consuming. I will try option 2 to perform a low-level SPI erase and let you know the result. I will look at CMD24 as a guide.

 

Thanks,

Mark

0 Kudos