cancel
Showing results for 
Search instead for 
Did you mean: 

Unlock readout protection

CW Fu
Associate
Posted on August 28, 2017 at 11:43

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();

#locking-unlocking-protection
1 REPLY 1
Artur IWANICKI
ST Employee
Posted on May 24, 2018 at 13:06

Hello,

You can reuse my example code tested on STM32F072-Discovery.

I have posted them on

https://community.st.com/0D50X00009XkYAmSAN

.

Best Regards,

Artur