AnsweredAssumed Answered

STM32F1 - ROP & Bootloader issues

Question asked by MWP on Nov 6, 2013
Latest reply on Nov 11, 2013 by damh
Greetings all,

I have the problem where i need to updated the bootloader on my STM32F103 using the bootloader already present on it.

The first thing the current bootloader does on startup is check the ROP flag, and if it is not set, then it sets it and restarts the micro.

The problem is that setting ROP also sets write protection for the pages the bootloader is present in.

The STM32F10x flash manual says:
Case 2: Read protection maintained active after the write unprotection, useful for in-application programming with a user boot loader:
– Erase the entire option byte area by using the OPTER bit in the Flash memory control register (FLASH_CR)
– Reset the device (system reset) to reload the option bytes (and the new WRP[3:0] bytes), and to disable the write protection.

Ive tried this with the following code:
if (FLASH_GetWriteProtectionOptionByte() & FLASH_WRProt_Pages0to1)
    FLASH->CR |= CR_OPTER_Set;
    status = FLASH_WaitForLastOperation(EraseTimeout);

Is this code performing the operation the flash manual describes correctly?
It appears it isnt working correctly, as its getting stuck in a reset loop.

Thanks for any help in advance!