2021-01-25 03:52 AM
Hi,
The PEP flag (of FLASH_0.MCR) should be set when I try to write to protected block of flash.
I observe, that this flag is cleared automatically at the moment of clearing EHV flag.
Is it intended and should be written in RM? Or do I do something wrong?
uint8_t DoFlashing (void ) {
// clear potential error flags
FLASH_0.MCR.R |= FLASH_0_MCR_ERROR_FLAGS;
// start erasing/program
FLASH_0.MCR.B.EHV = 1; // here PEP gets 1 because flash is LOCKED
// active wait to be finished
while (!FLASH_0.MCR.B.DONE) {}
FLASH_0.MCR.B.EHV = 0; // here PEP returns to 0
FLASH_0.MCR.B.ERS = 0;
FLASH_0.MCR.B.PGM = 0;
if (FLASH_0.MCR.B.PEP) {
// DOES NOT WORK !!!
return FALSE;
}
return FLASH_0.MCR.B.PEG;
}
Best,
Yannek
2021-02-03 07:04 AM
Hello Yannek ,
Have you solved your issue ?
Could you check if you respect the transition ?
Have you unlocked the flash ?
// unlock all
FLASH_0.LOCK0.R = 0;
FLASH_0.LOCK1.R = 0;
FLASH_0.LOCK2.R = 0;
FLASH_0.LOCK3.R = 0;
Best regards
Erwan
2021-02-03 09:01 AM
Hi Ervan,
Of course I have not unlocked the flash, because I am testing the PEP flag, not ERS. My purpose is to report failure due to attempt to write or erase locked flash.
I have discovered that I need check read PEP flag before I clear EHV. Otherwise PEP gets cleared as soon as I clear EHV. Afterwards I can't check why flash write/erase failed.
I'm finding this ambiguous: manual says that I have to clear this flag before another flashing, but this never happens, because UC clears PEP itself.
Best,
Yannek