cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 RDP2 prevents the modification of OPTLOCK?

ppj
Associate

Hi everyone,

we have a bootloader that writes new application code to the flash bank 2 in an STM32H7 and afterwards swaps the banks to execute the new code. The procedure for swapping is something like this:

   unlock OPTLOCK

   set SWAP_BANK_OPT

   set OPTSTART

   lock OPTLOCK

   system reset

This works fine with a Level 0 readout protection (RDP). However it is not working with a RDP level 2.

The reference manual states that only the SWAP_BANK_OPT bit is adjustable when RDP2 is set. It also states that you have to unlock OPTLOCK before changing SWAP_BANK_OPT.

Does this mean if OPTLOCK is set (locked) when RDP2 is active you can not change SWAP_BANK_OPT since you can not modfiy OPTLOCK?

So the solution to use SWAP_BANK_OPT would be to unlock OPTLOCK before activating RDP2?

Is there any other reason that would prevent IAP when RDP2 is set?

2 REPLIES 2

RM doesn't mention any relation (that I can find) between RDP level 2 and OPTLOCK.

OPTLOCK should be unlockable in any level or RDP.

Are you sure you are following the correct procedure?

[Cick Show More]

From RM0433:

To change the SWAP_BANK bit (for example to apply a new firmware update), respect the sequence below:

  1. Unlock OPTLOCK bit, if not already unlocked.
  2. Set the new desired SWAP_BANK_OPT value in the FLASH_OPTSR_PRG register.
  3. Start the option byte change sequence by setting the OPTSTART bit in the FLASH_OPTCR register.
  4. Once the option byte change has completed, FLASH_OPTSR_CUR contains the expected SWAP_BANK_OPT value, but SWAP_BANK bit in FLASH_OPTCR has not yet been modified and the bank swapping is not yet effective.
  5. Force a system reset or a POR. When the reset rises up, the bank swapping is effective (SWAP_BANK value updated in FLASH_OPTCR) and the new firmware shall be executed.

The SWAP_BANK bit in FLASH_OPTCR is read-only and cannot be modified by the application software.

The SWAP_BANK_OPT option bit in FLASH_OPTSR_PRG can be modified whatever the RDP level (i.e. even in level 2), thus allowing advanced firmware upgrade in any level of readout protection.

Also, the errata describes an issue with bank swapping for revision Y parts. Make sure you are not affected.