AnsweredAssumed Answered

Problem with Automatic Write Protection & Bootloading

Question asked by hart.gordon on Dec 18, 2012
Latest reply on Jun 28, 2013 by damh
Hi All

I have an '105 running a bootloader & application.  The bootloader is stable and I regularly release updates for products in the field.  I recently had a requirement to upgrade the bootloader in the field and wrote an application to do this. (The app contains a binary array of the bootloader, and attempts to over-write the original)

It all works great until I attempt to upgrade a device which has read protection enabled, which it fails miserably.  After quite a bit of hair pulling I found the following on page 17 on the PM0042 Programming manual:

2.4.1 Read protection
The read protection ... ...Once the protection byte has been programmed:
● Main Flash memory read access is not allowed except for the user code (when booting
from main Flash memory itself with the debug mode not active).
● Pages 0-3 (for low- and medium-density devices), or pages 0-1 (for high-density and
connectivity line devices) are automatically write-protected.
The rest of the memory can
be programmed by the code executed from the main Flash memory (for IAP, constant
storage, etc.), but it is protected against write/erase (but not against mass erase) in
debug mode or when booting from the embedded SRAM.

Which essentially means I cannot erase and then write the first page of the bootloader.

Reading on I find (on page 18)

2.4.2 Write protection
In high-density ...

Unprotection
To disable the write protection, two application cases are provided:
● Case 1: Read protection disabled after the write unprotection:
– Erase the entire option byte area by using the OPTER bit in the Flash memory
control register (FLASH_CR)
– Program the correct RDP code 0x00A5 to unprotect the memory. This operation
first forces a Mass Erase of the main Flash memory.
– Reset the device (system reset) to reload the option bytes (and the new WRP[3:0]
bytes), and to disable the write protection
Case 2: Read protection maintained active after the write unprotection, useful for inapplication
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.



Using Case 2 (underlined) I have attempted to unprotect the flash, but without luck.

Does anyone know if there is a workaround to get the first page(s) unlocked?

And moving forward (or alternatively) how to prevent the automatic write protection in the first place?  

We only implement read protection on our production devices, so this was rather unexpected.

Thanks
Gordon

Outcomes