Skip to main content
Yannek
Associate III
January 25, 2021
Question

PEP in FLASH_0.MCR cleared automatically while EHV=0

  • January 25, 2021
  • 2 replies
  • 918 views

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

    This topic has been closed for replies.

    2 replies

    Erwan YVIN
    ST Technical Moderator
    February 3, 2021

    Hello Yannek ,

    Have you solved your issue ?

    Could you check if you respect the transition ?

    0693W000007Do4vQAC.png 

    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

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
    Yannek
    YannekAuthor
    Associate III
    February 3, 2021

    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