AnsweredAssumed Answered

Unlock readout protection

Question asked by CW Fu on Aug 28, 2017

Hi Everybody,

 

I have problem unlock readout protection with HAL library on STM32F030F4.

My application need to apply lock / unlock by programming. 

The lock code works fine. After running lock code, RDPLevel shown in ST Utility becomes OB_RDP_LEVEL_1.

But unlock code doesn't work. Readout protection cannot be changed to OB_RDP_LEVEL_0.

Anything I missed?

 

//LOCK 

HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();

FLASH->CR |= FLASH_CR_OPTPG;
OB->RDP = OB_RDP_LEVEL_1;
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
    FLASH->CR &= ~FLASH_CR_OPTPG;
}

HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();

//UNLOCK

HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();


HAL_FLASHEx_OBErase();

FLASH->CR |= FLASH_CR_OPTPG;
OB->RDP = OB_RDP_LEVEL_0;
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
    FLASH->CR &= ~FLASH_CR_OPTPG;
}

 

HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();

Outcomes