2010-02-09 04:02 AM
Illegal Flash Memory writes possible?
2011-05-17 04:39 AM
so, finally I've got the bug :) and it was in my code.
The problem is, that after programming the Programm bit in the FLASH_CR register is still set and even if the FPEC is deactivated by setting the LOCK bit int the FLASH_CR register all further write to the memory will still be possible. So you must clear the programming bit to protect from accidently write operations to the flash. IMHO this is not exactly clear if you read the programming manual, further informations would be nice here. best regards thomas2011-05-17 04:39 AM
Yes, the general rule of thumb is to bracket any changes you make to the register, so you leave it in the state you found it.
FLASH->KEYR = KEY1; FLASH->KEYR = KEY2; FLASH->CR |= CR_PG; // Flash Stuff, write one word, multiple words, or the whole enchilada FLASH->CR &= ~CR_PG; FLASH->KEYR = 0; The Locking/Unlocking control access to the registers, they do not enable/disable the flash controller. The idea being that if your code runs amok it is not going to enable the controller, set it up, and trash itself. Or at least make the probability of that occurring pretty small. It is also possible to reprogram the entire flash memory while PG is enabled, it does not need to be toggled for every word written to memory, the library examples are not very efficient in this regard. -Clive