Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

6.10.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 (Table 6–7) shows the example of an 8-kilobyte (KB) flash memory comprising two 4-KB blocks. First write 5 KB of all 0xAA to flash memory at address 0x0000, and then write 2 KB of all 0xBB to address 0x1400. 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). 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. After the second write finishes, at time t(4), the 2 KB of 0xFF at address 0x1000 is corrupted.