I tested my theory by with an example program that tries to write successive words while leaving the others alone.
I added this to the end of the iap_flash.c in example project "lpcxpresso804_iap_flash":
for (int woff = 0; woff < FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES / 4; woff++)
{
memset(&s_PageBuf[0], 0, sizeof(s_PageBuf));
s_PageBuf[woff] = 0x11111111 * woff;
PRINTF("\r\nWriting flash sector %d:", DEMO_IAP_FLASH_SECTOR);
for (i = 0; i < FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES / 4; i++)
{
PRINTF(" %8X", s_PageBuf[i]);
}
/* write a page */
IAP_PrepareSectorForWrite(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
IAP_CopyRamToFlash(s_IapFlashPage * FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, &s_PageBuf[0],
FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, SystemCoreClock);
PRINTF("\r\nReading flash sector %d:", DEMO_IAP_FLASH_SECTOR);
uint32_t *read_ptr = (s_IapFlashPage)*FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES;
for (i = 0; i < FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES / 4; i++)
{
PRINTF(" %8X", *read_ptr++);
}
}
I expected the result to be 00000000 11111111 22222222 33333333 444444444 ....
Unfortunately it doesn't work as it appears that the chip is actually erasing the page each time. So what's the point of telling us to do an explicit erase before writing then? I wonder if that will actually do 2 erases?
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 11111111 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 11111111 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 22222222 0 0 0 0 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 22222222 0 0 0 0 0 0 0 0 0 0 0 0 00
Writing flash sector 14: 0 0 0 33333333 0 0 0 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 33333333 0 0 0 0 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 44444444 0 0 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 44444444 0 0 0 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 55555555 0 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 55555555 0 0 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 66666666 0 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 66666666 0 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 77777777 0 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 77777777 0 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 88888888 0 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 88888888 0 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 99999999 0 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 99999999 0 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 AAAAAAAA 0 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 AAAAAAAA 0 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 BBBBBBBB 0 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 BBBBBBBB 0 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 CCCCCCCC 0 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 CCCCCCCC 0 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 DDDDDDDD 0 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 DDDDDDDD 0 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 EEEEEEEE 0
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 EEEEEEEE 0
Writing flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FFFFFFFF
Reading flash sector 14: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FFFFFFFF