cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_FLASH_OB_Launch function trigger software reset

wesleywong
Associate II

Hi ST team,

I am using STM32U5G9 MCU. 

After modifying option bytes, HAL_FLASH_OB_Launch() would be called to apply the changes.

But in the launch function, it states that "Option byte launch generates Option byte reset". I have other tasks need to be done after calling HAL_FLASH_OB_Launch(). I don't want device to be reset after calling HAL_FLASH_OB_Launch() immedately.

Is there a way to trigger reset manually after modifying option bytes?

1. Modify option bytes

2. Call HAL_FLASH_OB_Launch()

3. Reset device manually

Thank you.

2 REPLIES 2
TDK
Super User

You can't change the behavior of HAL_FLASH_OB_Launch. If you have other stuff to do, do it before calling HAL_FLASH_OB_Launch.

If you feel a post has answered your question, please click "Accept as Solution".
Hai
ST Employee

Hi @wesleywong,

Thanks for your pertinent question and for the details.

On STM32U5, the Reference manual explains the Option‑byte loading (OBL) mechanism as follows:

Hai_0-1768249830726.png

This means there are two distinct phases:

  1. Programming the option bytes: what you do with HAL_FLASHEx_OBProgram(), the new values are stored in Flash, but are not yet active.
  2. Loading (reloading) the option bytes: which is the OBL phase, this happens either:
    • When OBL_LAUNCH is set (this is what HAL_FLASH_OB_Launch() does), or
    • Automatically after a power reset (BOR reset, or exit from Standby / Shutdown).

And the important part: OBL is tied to a reset event. When you call HAL_FLASH_OB_Launch(), the HAL sets OBL_LAUNCH, which triggers the option‑byte load sequence and the device reset.

So you cannot have the exact sequence:

  1. Modify option bytes
  2. Call HAL_FLASH_OB_Launch()
  3. Do some extra tasks
  4. Then reset manually

because as soon as step 2 is executed, the hardware will perform the OBL and reset the device.

>> What you can do instead:

If you need to preserve some context across the reset (because HAL_FLASH_OB_Launch() will reset the device), you can backup your application state before triggering the option‑bytes reload. For example:

  • Before calling HAL_FLASH_OB_Launch():
    • Save the minimal context you need into a non‑volatile / backup area:
      • Backup registers (TAMP/RTC backup registers)
      • Backup RAM (if available)
      • Or any other retention mechanism used in your system.
    • Then call HAL_FLASH_OB_Launch() to request the OB reload and reset.
  • After reset (in main() or early init):
    • Read back this saved context from the backup registers / backup RAM / Flash.
    • Decide what to do based on it.

Please feel free to respond and confirm whether this resolves your request or not.

Best regards,
Hai.