Go Down

Topic: "Erasing" an SD card (Read 513 times) previous topic - next topic

ShermanP

For data logging, I would like the SD card to be in the erased state except for the quick format entries setting up the file system.  Then when file data needs to be written, it should not be necessary to erase flash memory before writing because it's already erased.  I hope that would decrease needed write time. At least that's my assumption.

But everything I've found so far, including the above recommended SD Formatter from the SD Association, appears to "erase" by overwriting the entire card.  The Formatter gives you the option of a Quick format or an Overwrite format.  Other utilities from Minitool, EaseUS, etc. seem to be the same - offering to do a "secure erase" with ones, zeros, random data, or even 43 cycles of random data.  But that's not what I want.  I want the memory to just be erased, and not overwritten with anything.

The only exception I've found is the SDFormatter.ino example in the SDFAT library.  It actually uses CMD38 to erase the card, at least as far as I can tell from the source code.  Does anybody know of a Windows utility that does the same thing?

Actually, I'm not really sure it makes any difference in the end.  I have this picture of the SD card's controller having a flag for each sector as to whether it is currently erased or not, and only doing an erase before writing if it needs to write to a sector which is not erased.  But even if this is true, it may be complicated by the fact that erase blocks are much larger than a sector (like 4K or so).  Anyway, I don't know if my understanding of the controller setup is even close to correct.

One other thing is that you can't tell whether a sector is erased by reading it.  In some cards, an erased sector reads as all ones, but in others it reads as all zeros.  In fact, there's a flag somewhere in an SD command response that tells you which it is for that card.

Well, if anyone has words of wisdom on this, or useful links, please post.


Manuel_o

I dont know if it helps. But i delete my files on my SD card via a button.

There i have files called file_x.txt. So i iterate through my files and delte them via SD.remove

Code: [Select]
void resetlogYesPopCallback(void *ptr)                                                                   
{                                                                                                                                                           
  char file_Name[13] = {'/','f','i','l','e','_',0x00,'.','t','x','t'};     
  for (int i = 0; i < 100; i++)
  {
    sprintf(file_Name, "/file_%d.txt", i);
    Serial.println(file_Name);
    boolean fileFLAG = SD.exists(file_Name);
    if (fileFLAG)
    {
      SD.remove(file_Name);
      Serial.println("deleted");
    }
  }
  init_1._filenumber = 0;
  init_1._readingID = 0;
                                                                           
}


best regards

jremington

Quote
I want the memory to just be erased
What do you think this means?

A memory cell can hold a 1 or a 0.

ShermanP

#3
Feb 02, 2020, 01:04 am Last Edit: Feb 02, 2020, 01:05 am by ShermanP
Quote
I want the memory to just be erased
What do you think this means?

A memory cell can hold a 1 or a 0.
Flash memory erases to one state, and can then be written to the other state.  If it erases to all ones, you can only write zeros to it.  You cannot change a zero to a one except by erasing, which has to be done in blocks.  An erased block would have all ones, including all ones in the ECC bits used for error correction.  If you erase a block, then "write" all ones to it, it is no longer erased because the ECC and any other flag bits might have zero bits written to them even though the visible bits are still all ones.

So to erase a card you have to actually electronically erase all the blocks.  You can't overwrite it with ones.


Go Up