AnsweredAssumed Answered

Unlocking flash memory (PELOCK bit) on STM32L051T6

Question asked by Damiano Balzani on Mar 28, 2018

Hi eveerybody,

I'm tryng to use the protections against unwanted write/erase operations reported on 3.4.3 of Reference manual.

 

When my program runs the memory is locked (PELOCK BIT = 1) and i want to unlock it.

There is an examole code on reference manual. I copied it on my code but it doesn't work.

 

This is my code:

while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (1) */
{

   add here time-out management */
}

if ((FLASH->PECR & FLASH_PECR_PELOCK) == 0) /* (2) */
{
     if ((FLASH->PECR & FLASH_PECR_PRGLOCK) != 0) /* (3) */
    {
         FLASH->PRGKEYR = 0x8C9DAEBF; 
         FLASH->PRGKEYR = 0x13141516;

 

         FLASH->PECR &= !FLASH_PECR_PELOCK;
     }
}

Do i miss something? clocks or enable maybe??

Generally how can i access to FLASH -> PECR register?

 

Thanks in advance

 

Damiano

Outcomes