0
\$\begingroup\$

I'm experiencing a very typical issue with data corruption in a flash chip in a not so typical way. I'm using the M25P16 16Mb serial Flash chip by Micron to log historical data on my device over SPI.

The Logging works wonderfully with one known error, and thats when the power to the device cycles during a Flash Opperation.

I expected the last data block written to the Flash to be corrupted but in reality it seems the entire Sector becomes corrupted!

Here is what I mean by corrupted, every data block I write to Flash recieves a checksum, if a corrupted data block is being read, all the data is correct EXCEPT the low word of the checksum. The low word of the checksum always returns 0x0000.

For example a checksum of 0xA533037E being written to flash will be read as 0xA5330000.

Now for the weird part, if this problem is occuring and NEW DATA is written to flash the same thing happens for the new data!

How I have been solving this problem is by erasing all of the data and starting over. This seems to solve the problem in an not-so-great way.

My Question is this: For Serial Flash, if a corruption occurs, do you think it is the entire sector that becomes corrupted or just a data point? Does this seems like "typical" behavior for corrupted values?

Any input is appreciated :)

Addendum Here is the link to the data sheet for the flash:

Micron - 16Mb Serial NOR Flash

\$\endgroup\$
7
  • \$\begingroup\$ What do you mean by "data block"? Are you referring to the sectors in the datasheet? (From page 6) The memory can be programmed 1 to 256 bytes at a time using the PAGE PROGRAM command. It is organized as 32 sectors, each containing 256 pages. Each page is 256 bytes wide. \$\endgroup\$
    – CHendrix
    Mar 7, 2016 at 18:08
  • \$\begingroup\$ Good Point, "Data Block" is the message I am writing. In this instance the "Data Block" is 64 bytes. So I can write 4 "Data Blocks" per page. \$\endgroup\$
    – R. Johnson
    Mar 7, 2016 at 18:30
  • \$\begingroup\$ @R.Johnson - Is the hardware design of your system (which uses this SPI Flash) still able to be changed? \$\endgroup\$
    – SamGibson
    Mar 7, 2016 at 19:22
  • \$\begingroup\$ How many bits wide your SPI works? Are the checksums at the end of blocks? Where do you end the SPI transaction, at the end of every block? \$\endgroup\$
    – Ayhan
    Mar 7, 2016 at 19:42
  • 1
    \$\begingroup\$ @SamGibson No I'm afraid not \$\endgroup\$
    – R. Johnson
    Mar 7, 2016 at 22:45

1 Answer 1

2
\$\begingroup\$

In order to write to flash memory, an entire page of flash must be erased first, which sets all the bits to 1, and then individual bits are set to 0. The M25P16 (probably) loads the page to be written into RAM, or some other volatile memory, flips bits according to the program command, and then writes that page back into memory.

When you yank power during programming, it's highly likely that you will be corrupting other "data blocks" (as you've defined being 64 bytes). This is because the page size on the M25P16 is 256 bytes. When you write to a data block, you're causing 3 other data blocks to be written as well. The M25P16 takes care of the low level programming details for you, so other data in the page does not get lost. Yanking power when the M25P16 is programming a page will corrupt data in the page, which will include other data blocks.

Moral of the story? Flash does not like to loose power while it is writing. One way to reduce the risk of power loss during programming is to put a few beefy capacitors (maybe even a super cap) on the microcontroller's and M25P16's power rail. Even if someone yanks pulls power, the caps will keep the micro and M25 running long enough to finish what they are doing.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.