Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 10 down vote accepted

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.

share|improve this answer
Excellent, Thanks! This was just what I was looking for. – bitsmack Jul 23 '14 at 22:37
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. – Vality Jul 24 '14 at 9:00
@Vality: Can you provide an example of this? – Dave Tweed Jul 24 '14 at 11:20
@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". – Guillermo Prandi Jul 26 '14 at 20:22

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"!

share|improve this answer

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.


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"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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