cancel
Showing results for 
Search instead for 
Did you mean: 

SM32G071xB Configure option bytes from UART

Amr Abdelghafar
Associate II

I have Nucleo-G071RB board when I flash the Option Bytes to load from system memory (Bootloader) via ST-link it works with just reset and I can access the Bootloader,

But when I try to edit the Option Bytes via UART, I need to power off the board and power it on again to access the bootloader. (to implement the new Option Bytes),

So is this a bug, and is there any way to work around the power cycle to implement the Option bytes via UART?

Option Byte configuration:

nBoot0 from checked to unchecked

2 REPLIES 2
TDK
Guru

Option bytes need loaded by setting OPTSTRT. Not sure if you can set this via the UART bootloader, but it's worth trying.

0693W000006GNZKQA4.png

If you feel a post has answered your question, please click "Accept as Solution".
Amr Abdelghafar
Associate II

Thanks @TDK​  for your answer,

I have tried to configure the Option bytes via software on the stm32g071which implement the same sequence you have mentioned :

Code:

// unlock flash
if (HAL_FLASH_Unlock() == HAL_OK) {
    // unlock option bytes in particular
    if (HAL_FLASH_OB_Unlock() == HAL_OK) {
        // program selected option byte
        HAL_FLASHEx_OBProgram(&OBInit); // result not checked as there is no recourse at this point
        if (HAL_FLASH_OB_Lock() == HAL_OK) {
            HAL_FLASH_Lock(); // again, no recourse
            HAL_FLASH_OB_Launch(); // reset occurs here (sorry, debugger)
        }
    }
}

But actually, this produces the same result, I have to power cycle the board to get the new option bytes implemented.

and I found a small note regarding the FLASH control register (FLASH_CR) bit 27 OBL_LANCH:

0693W000006GPZCQA4.pngwhich is executed by HAL_FLASH_OB_Launch(); to force the option byte loading, that it cannot be written if OPTLOCK is set,

but if you reverse the sequence in your code to call HAL_FLASH_OB_Launch(); function while you unlocking the option bytes, it will generate a reset and prevent you from lock the option bytes again, which will break the board, and you will not able to communicate to your MC any more with anyway and it will not run the software either.

So any suggestions to revive the dead board or implement the Option bytes without power cycle?

Thanks in advance.