I am seeing corrupt bytes when I write then examine the built-in flash memory on a SAM E70 (custom) board. Basically, I am writing 2 sectors of the (previously erased) flash at a time (262,144 bytes) with a 1-255 pattern stored in an identically sized (262,144 byte) buffer in SRAM. I am using the ASF built-in flash_write() function to write the flash memory. I then check the flash memory element by element, comparing it to my SRAM buffer. I have verified in the memory view of the debugger that some of the flash bytes are indeed corrupt/wrong.
A few observations:
- The corrupted sections seem to always occur in 4 byte sequences
- These 4 byte sequences are always sequentially increasing (for example [5,6,7,8] or [111,112,113,114])
- The location of the sequences in memory appears random
- Usually only 4 or 8 bytes out of the entire 262,144 bytes originally written are corrupted like this. But it is very repeatable in that it happens very often.
I initialize the flash with 6 wait states:
ul_rc = flash_init(FLASH_ACCESS_MODE_128,FLASH_NUM_OF_WAIT_STATES);
I then unlock the flash:
where UNLOCK_ADDRESS_1= 0x0041fe00 and UNLOCK_ADDRESS_2 = 0x0051ffff and the actual regions unlocked are: actualUnlock1= 0x0041c000 and actualUnlock2 = 0x0051ffff. (They are different but sufficiently large.)
To write the flash, I use:
ul_rc = flash_write(flashAddress, &dataBuffer, numBytesToWrite, false);
where flashAddress = 0x00420000 [in this example, sector 01 of the flash], &dataBuffer = 0x20400d00 [the SRAM buffer with the pattern], and numBytesToWrite = 0x00040000 [262144 bytes]. Even when I see the corruption, ul_rc always returns as FLASH_RC_OK.
I've finally attached a photo highlighting one of the 4 byte sequences of corruption amongst the correct 1-255 pattern, as seen in the memory view of the debugger. Any thoughts?