Author Topic: Erasing Flash Memory  (Read 1294 times)

0 Members and 1 Guest are viewing this topic.

Offline mbarszczTopic starter

  • Contributor
  • Posts: 19
  • Country: us
Erasing Flash Memory
« on: April 25, 2020, 09:43:32 pm »
As we know, the default state of erasable memory (EPROMs, NAND flash, etc) is 0xFF,  but are those values what is actually exposed to the PC/device in the case of SD or CF cards?  When a PC writes a file full of zeroes, is that actually writing 0x00 to the flash memory, or is it writing 0xFF?

If you were to look at a brand new SD card with a hex editor on a PC, would it be full of 0x00 or 0xFF?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11903
  • Country: us
    • Personal site
Re: Erasing Flash Memory
« Reply #1 on: April 25, 2020, 09:54:10 pm »
SD Cards are typically sold pre-formatted, so they could contain anything.

SD Card specification actually defines a bit in the status registers that tells the host the values after executing the erase command. So it is up to the card vendor to decide what they want to show as a "erased" state.

Specifically section 4.3.5.1 "Erase" of the "Physical Layer Simplified Specification" (https://www.sdcard.org/downloads/pls/index.html) says this:

Quote
The data at the card after an erase operation is either '0' or '1', depends on the card vendor.
The SCR register bit DATA_STAT_AFTER_ERASE (bit 55) defines whether it is '0' or '1'.
« Last Edit: April 25, 2020, 09:57:34 pm by ataradov »
Alex
 
The following users thanked this post: helius, I wanted a rude username

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2245
  • Country: us
Re: Erasing Flash Memory
« Reply #2 on: April 25, 2020, 10:53:49 pm »
As Alex says, the erased state depends on the manufacturer.  I suspect the actual erased state is always FF, but some manufacturers could have an inverter stuck in there.

The much-hailed SD Formatter app provided by the SD Association offers an "Overwrite" option, which I've confirmed does actually write zeroes to the entire card instead of erasing it.  They don't offer an Erase option, at least not on the Windows version.

If you have a DSLR or other fancy camera that offers a "low level" format, that will erase the card, and then you can look at it in your hex editor and see how it reads back.  In the Arduino world there is a library called SdFat which includes an Example called SdFormatter.ino.  That sketch does erase the card, and tells you what Alex's bit 55 says.


 

Offline mbarszczTopic starter

  • Contributor
  • Posts: 19
  • Country: us
Re: Erasing Flash Memory
« Reply #3 on: April 26, 2020, 08:22:58 pm »
Thanks for the information.  Interesting that it can vary by manufacturer.  I just got a new SanDisk Extreme MicroSD card today, and it was filled with zeros.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf