2025-09-15 12:12 AM
Hello,
I am working on custom bootloader + application setup on a STM32G070CBT6
Currently, I need to store bootloader flag that indicate whether the MCU should jump to the bootloader code or to the application code.
My questions are:
1. Can I use Option Bytes memory area to store the custom flag?
2. If Option Bytes memory area are not suitable ,is there another small memory area(apart from flash)
that is recommended for storing such a small boot flag?
I need only one bit for this flag, but dedicating a full 2KB flash feel inefficient.
2025-09-15 1:31 AM
Does this flag need to be non-volatile ?
2025-09-15 1:35 AM - edited 2025-09-15 2:13 AM
Hello @bhagat and welcome to the community,
Unfortunately, you need to do that when storing that flag in the flash.
Why putting the flag in the flash while you can put it in the RAM?
2025-09-15 1:37 AM
Yes, the bootloader flag must be non-volatile, because I need it to persist across a reset.
2025-09-15 1:45 AM
Hi,
>Are Option bytes writable at runtime
yes ; you could set bootloader/start or not.
+
If you have Vbat/RTC , could use user backup registers, 20 B afair.
2025-09-15 1:45 AM
I’m using the flag for my custom bootloader. Since I need the bootloader to check this flag after a reset, it must be stored in a non-volatile location. If I keep it in RAM, the value will be lost once the MCU resets, so the bootloader wouldn’t see it. That’s why I’m not using RAM for this flag.
2025-09-15 1:51 AM
Sorry boss, but flags (or any variable) in RAM can persist reset (right config) and not persist power down. Then this is primary condition.
2025-09-15 1:53 AM - edited 2025-09-15 2:02 AM
Try to reserve a location to the RAM not defined in the linker and access to that location by address either from the bootloader or the application. The RAM can preserve its content after reset if it was not modified by a configuration in the linker. For sure it won't preserve its content with power cycle.
Why did you accept my answer as solution while you keep asking?
2025-09-15 2:01 AM - edited 2025-09-15 2:15 AM
@bhagat wrote:Yes, the bootloader flag must be non-volatile, because I need it to persist across a reset.
That's a different thing!
Non-volatile means persisting across power loss/removal.
RAM is volatile (loses content with power loss), but it does persist across a reset.
All you need to do is to ensure that your flag does not get cleared by your startup code.
Check your compiler documentation for how to do that.
For GCC, you use a noinit section ...
2025-09-15 2:03 AM
> Try to reserve a location to the RAM not defined in the linker and access to that location by address either from the bootloader or the application.
Recommended, but not absolutely necessary. Application and bootloader can share the same range, i.e. the bootloader can try to access variables (addresses) defined within the application.
But this flag area must be excempted from RAM initialisation that happens almost immediately after the reset vector.
And which is implemented in the startup code, usually in assembler.