I have a program where 3 Flash pages are being written (4 if you include the userpage) in sequence, because the data doesn't fit in one page.
When I start the MCU and run it, everything seems to be written correctly to flash.
But if I want to clear and overwrite it, the program fails to do so.
There is no error showing up, no exception, nothing that would indicate a failure. The data is simply not re-written in flash (checked with atmel studio debugger).
I'm also fully aware, that with a write operation, only ones can be turned to zeroes and not the other way around. (I'm always calling the clearing command to restore the 0xff .... state.)
After a restart it works again for exacly 1 page written. The passed address is correct I verified that, I'm not violating reserved flash or something like that.
Any ideas why it's failing? What could I do?
A hint may be, that, when I put a breakpoint somewhere before the write command, it fails completely and doesn't even write once (race condition?).
This is the relevant code:
void writeNormalFlashPage(uint32_t*data, uint16_t wordcount, uint32_t destinationAddr)
uint32_t *psrc, *pdest ;
uint8_t timeout = 0;
volatile uint32_t dAC = destinationAddr;
psrc = (void*) (&(data));
pdest = (void*) destinationAddr ;
*pdest++ = *psrc++ ;
dAC = destinationAddr;
while(!flashc_erase_page(dAC/512,true) && timeout < 250)
if(timeout >= 250)
flashc_write_page(dAC/512); // transfer all data from page buffer to flash
void KMS_FLASH_saveSettingsFileToFlash(uint32_t*settingsFile, uint16_t fileLen)
writeNormalFlashPage(&(settingsFile), 72, FLASH_FilterSlot0);
writeNormalFlashPage(settingsFile + 79, 72, FLASH_FilterSlot1); // + 79
writeNormalFlashPage(settingsFile + 151, 72, FLASH_FilterSlot2); // + 151
void flashc_write_page(int page_number)