Nios® V Processor Software Developer Handbook

ID 743810
Date 10/12/2024
Public
Document Table of Contents

7.8.2. Block Erasure or Corruption

Generally, flash memory is divided into blocks. alt_write_flash() might need to erase the contents of a block before it can write data to it. In this case, it makes no attempt to preserve the existing contents of the block. This action can lead to unexpected data corruption (erasure), if you are performing writes that do not fall on block boundaries. If you wish to preserve existing flash memory contents, use the fine-grained flash functions. These are discussed in the following section.
The Example of Writing Flash and Causing Unexpected Data Corruption table shows the example of an 8-kilobyte (KB) flash memory comprising two 4-KB blocks.
  1. First write 5 KB of all 0xAA to flash memory at address 0x0000, and then write 2 KB of all 0xBB to address 0x1400.
  2. After the first write succeeds (at time t(2)), the flash memory contains 5 KB of 0xAA, and the rest is empty (that is, 0xFF).
  3. Then the second write begins, but before writing to the second block, the block is erased. At this point, t(3), the flash contains 4 KB of 0xAA and 4 KB of 0xFF.
  4. After the second write finishes, at time t(4), the 2 KB of 0xFF at address 0x1000 is corrupted.