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:

This means there are two distinct phases:
- Programming the option bytes: what you do with HAL_FLASHEx_OBProgram(), the new values are stored in Flash, but are not yet active.
- 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:
- Modify option bytes
- Call HAL_FLASH_OB_Launch()
- Do some extra tasks
- 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.