How to program FLASH_OPTR register to survive system reset?
Hello,
I'm trying to control the boot behavior of my STM32L412 development board which has a floating BOOT0 hardware pin.
I'm trying to clear the SWBOOT0 bit in FLASH_OPTR using firmware. So far I am able to unlock the register and clear the bit. This works while the target is running, but as soon as I do a system reset, the FLASH_OPTR reverts back to a value of 0xFBFFF8AA.
My code to clear the SWBOOT0 bit is below and all runs fine. What can I do to make FLASH_OPTR survive a system reset?
__ramfunc void ClearSWBOOT0Pin()
{
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
CLEAR_BIT(FLASH->OPTR, FLASH_OPTR_nSWBOOT0_Msk);
CLEAR_BIT(FLASH->OPTR, FLASH_OPTR_nBOOT0_Msk);
SET_BIT(FLASH->OPTR, FLASH_OPTR_nBOOT1_Msk);
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
}