2019-08-14 04:09 PM
Wondering why I'm getting a hard fault when writing to the FLASH option key register on an STM32G071RBT6 (Nucleo board).
I first make this call, (running from flash):
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_FLASH);
Then, running from RAM, do the following:
if (READ_BIT(FLASH->OPTR, FLASH_OPTR_nBOOT_SEL) != 0)
{
// Unlock flash option bytes
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
The READ_BIT operation works fine, but I get a fault writing the OPTKEYR register.
The key values are defined as follows:
#define FLASH_OPTKEY1 0x08192A3B
#define FLASH_OPTKEY2 0x4C5D6E7F
The register address is resolving to 0x4002200C, which I believe is correct.
Any thoughts?
Thanks.
Solved! Go to Solution.
2019-08-15 11:37 AM
The solution is to unlock the flash before attempting to unlock the flash option register, (as detailed in the reference manual).
2019-08-15 11:37 AM
The solution is to unlock the flash before attempting to unlock the flash option register, (as detailed in the reference manual).
2021-05-10 01:05 PM
Confirmed on L471. I ported working M7 code to L4 and this is one of the differences. The other is that OB Launch triggers a reset.