2017-08-28 02:43 AM
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-protection2018-05-24 04:06 AM
Hello,
You can reuse my example code tested on STM32F072-Discovery.
I have posted them on
https://community.st.com/0D50X00009XkYAmSAN
.Best Regards,
Artur