Question
Stm32f030c8 Flash write protection error
Posted on March 16, 2015 at 10:58
Hi,
I'm wrtiting a bootloader for updating an embedded product. Bootloader sequence seems correct now and I want to protect from writing the bootloader flash addresses. Using the snippets of code from St this is my code:void Check_Write_Protection( void )
{
// unlock the Flash Program Erase Controller (FPEC)
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
ProtectedPages = FLASH_OB_GetWRP();
// pages are not write protected
if(ProtectedPages == 0xFFFFFFFF)
{
FLASH_OB_Unlock();
res = FLASH_OB_EnableWRP(OB_WRP_Pages0to3|OB_WRP_Pages4to7);
FLASH_OB_Lock();
NVIC_SystemReset();
}
}
the problem is when I call the
FLASH_OB_EnableWRP,
the flag for write protectione seems unlocked but i have a FLASH_PROGRAM_ERROR when I call :
if(WRP0_Data != 0xFF)
{
OB->WRP0 = WRP0_Data;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
}
OB->WRP0 = WRP0_Data
set PGERR = 1 in SR register and so memory is non protected.
Any suggestion? What am I missing?? Thanks a lot