AnsweredAssumed Answered

Stm32f030c8 Flash write protection error

Question asked by pinese.lucio on Mar 16, 2015
Latest reply on Mar 16, 2015 by Clive One

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)
  ProtectedPages = FLASH_OB_GetWRP();
  // pages are not write protected
  if(ProtectedPages == 0xFFFFFFFF)
    res = FLASH_OB_EnableWRP(OB_WRP_Pages0to3|OB_WRP_Pages4to7);

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