2020-05-18 09:55 PM
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();
}
Solved! Go to Solution.
2020-05-20 02:28 AM
I think follwoing the reference manual e.g. for the STM32L412 RM0394 "3.4.2 Option bytes programming" is quite good at explaining.
2020-05-19 02:01 AM
when is OPTSTART set?
2020-05-19 10:50 AM
Thank you for the reply, Uwe. I wasn't setting OPTSTRT in my initial attempt.
After trial and error, I found that setting the FLASH_CR->OPTSTRT bit *before* writing to the FLASH_OPTR allows the contents to survive a power cycle or a system reset.
I know ST's answer to this will be to only program the option register bits using the ST-LINK tool and a software utility, but it would be really nice if the full sequence to write these bits in a non-volatile fashion were documented somewhere.
rgds,
Gary
2020-05-20 02:28 AM
I think follwoing the reference manual e.g. for the STM32L412 RM0394 "3.4.2 Option bytes programming" is quite good at explaining.
2020-05-22 03:21 PM
Thank you again for the reply Uwe. I am following the exact recipe in "3.4.2" and now it appears to be working. I had issues with my prototype board's power supply which I believe were causing issues with reset and FLASH_OPTR values. Working with a newer set of prototype boards, I now have no problems programming FLASH_OPTR.
best,
Gary