2013-11-06 08:21 AM
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_Unlock();
FLASH->OPTKEYR = FLASH_KEY1;
FLASH->OPTKEYR = FLASH_KEY2;
FLASH->CR |= CR_OPTER_Set;
status = FLASH_WaitForLastOperation(EraseTimeout);
NVIC_SystemReset();
}
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!
2013-11-06 11:05 AM
It's certainly something you're likely to bury man-days of effort into.
Consider /* Erase all the option Bytes */ FLASHStatus = FLASH_EraseOptionBytes(); STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\FLASH\Write_Protection\main.c As a general rule you'd want to be very careful to clear out any pending status in the flash controller, and watch for debugger interference.2013-11-07 12:16 AM
Yeah, i can see this could be rather tricky :(
So when ROP is enabled, are the appropriate WRP bits also enabled?Or does ROP being enabled just imply that write protection is also enabled?Basically, i would like to know how i can confirm that ROP is enabled, but write protection is disabled.Thanks again.2013-11-07 07:26 AM
To expand on this a little...
ROP is enabled.FLASH_GetWriteProtectionOptionByte() reports 0xFFFFFFFF (no write protect enabled?).When i try to erase flash at 0x8000000, FLASH_ErasePage() fails with FLASH_ERROR_WRP.2013-11-11 03:07 AM
ROP enables a special write-protection. Write-protection options bits cannot deactivate it!
If ROP is enabled, you cannot write pages 0-1 or 0-3 (flashsize depended). Disabling ROP, needs a Reset. After this reset, the flash will be empty (mass erase). You have to have the boot-pins set to boot from RAM or internal bootloader. Otherwise the mcu will be stopped. => You have to have a possibility to control the boot-pins (beyond the reset!) => You have to have a possibility to recover your firmware out of RAM. You probably get larger problems, if power fails ;) => if you can relinquish this ROP-write-protected area, you can put there a static bootloader and after this area you put your dynamic updateable bootloader. 1) static bootloader, which only checks which dynamic bootlaoder to run 2) dyn. bootloader 1 3) dyn bootloader 2 4) application You can exchange the bootloader 1 or 2 in your application without problems, if power fails, because one bootloader should always be in OK state.