STM32G070 flash option bytes (for bootloader) reset after power cycle
Hi,
I want ot use the UART bootloader to program a STM32G070RB (with the Nucleo board). I've used the following code to activate the pin Boot0 to access the bootloader (some of it may be useless):
while(FLASH -> SR & FLASH_SR_BSY1);
FLASH->KEYR = KEY1;
FLASH->KEYR = KEY2;
while(FLASH -> SR & FLASH_SR_BSY1);
FLASH-> OPTKEYR = OPTKEY1;
FLASH-> OPTKEYR = OPTKEY2;
while(FLASH -> SR & FLASH_SR_BSY1);
FLASH->CR |= FLASH_CR_OPTSTRT;
while(FLASH -> SR & FLASH_SR_BSY1);
FLASH->OPTR |= FLASH_OPTR_nBOOT0;
FLASH->OPTR |= FLASH_OPTR_nBOOT1;
FLASH->OPTR &= ~FLASH_OPTR_nBOOT_SEL;
for(unsigned long i = 0;i<2000000;i++)
if(!(FLASH -> SR & FLASH_SR_BSY1))
break;
FLASH->CR |= FLASH_CR_OBL_LAUNCH;
It works fine, and I can program the board several times, even after a reset, without having to rerun this code since the option bytes stay set.
However, when I power down and back up the board, I have to run the code again to activate the Boot0 pin. But I don't see any difference when looking at the flash registers in the debugger: in particular, BOOTSEL stays at 0 even after powering up, so the Boot0 pin should already be active. Running the sequence seems to reactivate the Boot0 pin, but without changing the registers.
What is the reason for this? Is there a way to ensure the Boot0 pin stays active forever, even after a power cycle? In my final application the UART will be the only way to program the STM32, so I don't want to accidentally brick it by programming it with a bugged program that can't properly do the Flash option bytes sequence.
Thanks
