20
\$\begingroup\$

An easy question, I hope! I'm not finding any definitive answers...

I'm writing drivers for a SST25VF064C flash memory chip. It communicates via SPI.

Like all flash memory (that I know of), it needs to be erased (all bits = 1) before it can be written (bits = 0). For this chip, the smallest area that can be erased is 4kB.

Its memory is divided into 256-byte pages. With one instruction, I can write anywhere from one byte to 256 bytes into a specified page. I don't have to start on a page boundary: the first location to be programmed can be anywhere within a page.

The general rule is to make sure that the page is erased before writing into it. But, can I write into a previously-written page, if I avoid the already-written areas? For example, say that I store data into bytes 0-127. Can I later write another 128 bytes into the same page, if I start at byte 128?

\$\endgroup\$

3 Answers 3

16
\$\begingroup\$

Yes, after any erase, you can use any number of separate operations to write data (changing bits from 1 to 0) before the next erase operation.

You can even rewrite a previously-written location, as long as you are only clearing more bits. This can be handy for maintaining things like allocation bitmaps.

\$\endgroup\$
4
  • \$\begingroup\$ Note that some chips do not like you writing an earlier byte after a later one from looking at various data sheets, however this seems to vary across devices. \$\endgroup\$
    – Vality
    Jul 24, 2014 at 9:00
  • 1
    \$\begingroup\$ @Vality: Can you provide an example of this? \$\endgroup\$
    – Dave Tweed
    Jul 24, 2014 at 11:20
  • 3
    \$\begingroup\$ @DaveTweed NXP LPC21xx and LPC23xx MCUs have a checksum byte for every 16 bytes of memory; you must write all 16 bytes at once because the checksum is written in that operation. If you come later and attempt to write zeros in the same "line", the zeros are written, but a new checksum is written over the previous as well; chances are that it has some 1's where the previous had 0's, so the checksum becomes invalid. I don't remember if the MCU permits you to read a line with a bad checksum. Anyway, that would be an example of "vary across devices". \$\endgroup\$ Jul 26, 2014 at 20:22
  • 1
    \$\begingroup\$ " any number of separate operations to write ... the next erase operation." Note that some parts, particularly embedded flash memories in MCUs, will state a maximum number of writes before an erase is required. Presumably violating this limit will risk corrupting other areas of memory, so it's important to watch out for such limits. \$\endgroup\$
    – ajb
    Jun 22, 2019 at 20:07
9
\$\begingroup\$

can I write into a previously-written page, if I avoid the already-written areas?

If I understand p. 16 of the datasheet correctly, it is saying: With this particular chip, you must not write into a previously-written page, even if you avoid the already-written areas.

details

The SST25VF064C flash memory chip datasheet on p. 16 says "The page-Program instruction programs up to 256 bytes of data in the memory. The selected page address must be in the erased state (FFH) before initiating the Page-Program operation."

I assume that therefore "The entire selected page must be in the erased state (every byte on the page FFh) before initiating a Page-Program operation." Has SST or Microchip released any documentation clarifying this maddeningly ambiguous sentence?

In my experience, the manufacturer of all MLC flash chips and some newer SLC flash chips mandates that once a page has been written, the page must be erased before that page is written again, even if you only want to change some 1 bit to a 0 bit. (This is called the "write-once rule" in the YAFFS article.)

In my experience, all of the older flash chips allow you to change any 1 bit to a 0 bit without an erase cycle, even if that bit is in a page or even a byte that has already had other bits programmed to zero -- a page of flash can be programmed multiple times between erases. (This is called "multiple-write" in the YAFFS article).

The manufacturer's datasheet is a conditional promise the manufacturer makes to you. As long as you follow all the datasheet recommendations, the manufacturer promises that the chip will operate as specified. I suspect that if you program a previously-written page, avoiding the already-written areas, there is a good chance than an immediate read-back might give the data you expect -- the newly-written bytes are the values you just wrote, and the other bytes are likely unchanged. However, because this doesn't follow the datasheet recommendations, you can no longer rely on all the promises in the datasheet. I hear rumors that such non-sanctioned activity causes data retention time and endurance to suffer, because of program disturb, over-programming, charge trap, effects similar to DRAM row hammer, etc.

"The memory use scheme influences the bit error rate. Partial-page programming, non-sequential pages programming within the block, excessive read per block without erase as well as non-equal number of read operation within a single block increase number of the read disturb errors." -- Michal Jedrak. "NAND Flash memory in embedded systems".

"Program disturb occurs when a bit is unintentionally programmed from a “1” to a “0” during a page-programming event. This bit error may occur either on the page being programmed or on another page in the block. Bias voltage conditions in the block during the page programming can cause a small amount of current to tunnel into nearby memory cells. Repeated partial page programming attempts will continue to aggravate this condition." -- Douglas Sheldon and Michael Freie. "Disturb Testing in Flash Memories". p. 8, 9.

"Program disturb happens when a bit is unintentionally programmed (1 to 0) during a programming operation. ... This condition is made worse by random programming in the block and by applying multiple partial writes to the pages." "Yaffs NAND flash failure mitigation"

\$\endgroup\$
0
1
\$\begingroup\$

It is highly likely that the programming software that you are using is already writing the "required" 256 bytes. It "appears" like its is giving you the capability of writing from one to 256 bytes, but I suspect that what it is doing is OR-ing the byte(s) you want with a "mask" of 256 "FF." If this is correct, then you can "safely" write any byte once, without having to erase the whole 4K bytes. If a checksum is written outside of your control, then, most likely, an invalid checksum will be created when you write another byte into a previously written segment. The implications of this, is chip dependent.

If your programming software, does not do the "OR-ing," you can do it yourself. Clear a 256 byte segment, write the byte(s) into the correct position(s), OR with a 256 byte mask of FFs, and write the segment to the desired page.

Whether either method works with any particular chip, can be easily determined by you. Write to the first 128 bytes, write to the second 128 bytes, verify that the first 128 bytes are NOT "messed up"!

\$\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.