Unlock:
Code: Select all
if (FLASH->CR & FLASH_CR_LOCK) {
FLASH->KEYR = 0x45670123;
FLASH->KEYR = 0xcdef89ab;
}
Code: Select all
FLASH->CR |= FLASH_CR_PG;
for (i=0;i<len;i++)
((unsigned short *)FLASH_EE_REGION)[i] = ((unsigned short *)data)[i];
FLASH->CR |= FLASH_CR_LOCK;...... once: you need to erase the page if the page is not empty to begin with.
Code: Select all
if (i != len) {
flash_wait_nb ();
FLASH->CR |= FLASH_CR_PER;
FLASH->AR = FLASH_EE_REGION;
FLASH->CR |= FLASH_CR_STRT;
flash_wait_nb ();
FLASH->CR &= ~FLASH_CR_PER;
}
I've added all sorts of "print" statements to debug this. The AR register does not seem to change by my assignment. That is expected, as it is write only.
I've checked a few places for example code, but everybody seems to be following this pattern and claims that it works...