cancel
Showing results for 
Search instead for 
Did you mean: 

How to store a 1-bit bootloader flag without wasting 1 Flash page

bhagat
Associate II

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.

  • Since the movement i am reserving 1 flash page(2KB) ,just to store single flag bit.
  • This feels like a waste of memory, since I only need 1 bit of storage.

My questions are:

     1. Can I use Option Bytes memory area to store the custom flag? 

  • Are Option bytes  writable at runtime for application/bootloader use, or are they limited to ST system configurations (e.g., RDP, WRP, BOR levels)?

      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.

28 REPLIES 28

Thanks, that’s a good point. In my case, I need the bootloader flag to survive a full power cycle as well, not just a reset.


@bhagat wrote:

Thanks, that’s a good point. In my case, I need the bootloader flag to survive a full power cycle as well, not just a reset.


Along the discussion, you didn't mention any case the Power Cycle, you mentioned only Reset. Which make a big difference here.

Next time, please be more accurate in the description to avoid unnecessary ping pongs.

Thank you.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Apologies for not being precise in my initial description. Thank you for highlighting the distinction between reset and power cycle.

> Along the discussion, you didn't mention any case the Power Cycle, you mentioned only Reset. Which make a big difference here.

Yes, exactly. This is a totally different issue.

@bhagat 

Except for your very much disliked Flash/EEPROM option you have two alternatives, unless you consider another MCU. But both involve additiona hardware.
One option is a backup battery, and to utilize a RAM / registers in the backup area of the MCU.
The second one is external NVM, like serial EEPROM or Flash via I2C or SPI, or FRAM.

My company mostly uses the second option, since the respective controller/ECU board is just a small component in a larger system, and this system needs persistent settings anyway.

Consider keeping your EEPROM/Flash method, and add some further persistent data.

@bhagat only said it needs to survive reset:

From all he said I had a good guess that it was not so! :D

TDK
Super User

You can use option bytes if you find one that won't cause other issues. For example, you can use NBOOT0 freely if NBOOT_SEL = 0. There are no free bits.

Note that writing option bytes also uses a page of flash internally and that interrupting the process due to a power loss can cause them to be corrupted.

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

Dear @bhagat,

All the quick actions are described here: FAQs.

More on this particular action, you can also find on these guidelines: Help others to solve their issues.

Let me know if you will need any help either here or via DM. 

Regards,
Lina



In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Thank you for offering help. Yes, I’d like to discuss here.

Try explain why you require this flag after power cycle ?