Restoring the STM32 option bytes to their factory settings using STM32CubeProgrammer
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content
on 2025-02-11 7:38 AM
Introduction
Sharing a MCU board between multiple users may be sometimes challenging when someone makes a modification on the board or in the MCU option bytes and doesn’t notify about it. Additionally, the board owner might forget the changes applied previously to his board or in the option bytes. These situations often result in unexpected behavior of the application, leading to significant time being wasted.
If you have recovered a board from your colleague that you use for a test or a development, the first recommended thing to do is to restore the option bytes to their factory values.
For this reason, two features have been implemented in STM32CubeMX. This article describes how to restore the option byte factory reset configuration. This feature is available starting from STM32CubeProgrammer V2.18.0.
Note that not all options bytes are restorable. For example, the RDP lever from RDP L2 to 0 is not possible. This is by product construction.
1. Import/Export option bytes feature
This option supposes that you did not modify the option bytes on the MCU. This is especially useful after purchasing a new STM32 MCU or new STM32 based board where you can export the factory option bytes to save them elsewhere. Afterwards, you can import them when you need to restore the option bytes factory values.
1.1 Saving the option bytes (export option)
Connect to the STM32 with STM32CubeProgrammer either with ST-LINK or with bootloader, and:
- Go to the option bytes menu “OB”.
- Click the arrow behind the [Read] button then click [Export current MCU option bytes].
- Browse to the location where you need to save the option file config. The file format is JSON.
- Give a name to the file and click [Save].
Figure 2. Saving the option bytes file config
At this stage, the factory option bytes values are stored on your hard drive. You will use it when needed.
1.2 Option bytes factory reset (import option)
Consider you did some modifications in the option bytes and you need to restore it without taking care about all the modifications you performed previously. In this section, we describe how to restore the MCU option bytes to the factory reset values with the import option.
Connect to the STM32 with STM32CubeProgrammer either with ST-LINK or a bootloader, and:
- Go to the option bytes menu “OB”.
- Click the arrow behind the [Read] button then click [Import current MCU option bytes].
- Browse to the location where you saved the option file config (the factory values).
- Click [Open].
- Click [Apply].
Figure 3. Importing option bytes in “OB” menu
Figure 4. Opening the option bytes file config
Figure 5. Applying the new option bytes config (factory values)
At this stage, the option bytes have been restored to their factory values.
2. Using the “Reset MCU to Factory Settings” option
This option is very simple to use as it is done in a simple click without any other operation.
Note that this option has occurred in the STM32CubeProgrammer V2.18.0 and available only for the STM32U5 family for now. But it will be deployed gradually on other STM32 MCU families in the future.
All you need to do is to connect the MCU to the STM32CubeProgrammer,
- Go to the option bytes menu “OB".
- Click on [Reset MCU to Factory Settings].
- Click on [Start Factory Reset].
- Wait until all operations are complete.
Figure 6. Using “Reset MCU to Factory Settings” option
Figure 7. Applying the option factory settings
Figure 8. Waiting for the operations to complete
Conclusion
In this article two methods to restore the option bytes to their factory reset have been described step by step. One is based on the Export/Import feature and the other is based on the [Reset MCU to Factory Settings] option.