Note: As of January 2020, PEmicro now offers a new method of programming user configuration data through the new Program User Options command. Click here for more details about this command.
PEmicro supports a wide selection of STMicroelectronics' STM32 device families. Many STM32 devices include a set of user configurable option bytes that can control features such as HW/SW watchdog, read protection, and write protection. These options give users a convenient way of changing the settings of their device. Configuring option bytes of a STM32Fx or STM32Lx device is made easy with our PROG software and Cyclone Image Creation Utility software.
Depending on the device, we may provide a separate algorithm for programming the option bytes or a separate set of user commands in the device algorithm to program specific registers of the option bytes. The user commands simplify programming settings such as read and write protection. Devices compatible with object file programming allow users to load files into the option bytes to program many options simultaneously.
Typically, STM32 devices have at least three sections: USER/nUSER, RDP/nRDP, and WRP/nWRP. The USER section will control options such as watchdog type, reset events, and brown out reset levels. The RDP section controls the Read Protection level of the device. There are three protection states: Level 0 for no read protection, Level 1 for temporary read protection, and Level 2 for permanent read protection. The WRP section is for toggling write protection on pages of flash memory. Each bit of WRP will correspond to a specific number of pages, allowing specific memory areas to be write protected while leaving others unprotected.
Devices with a Separate Algorithm
For devices such as the STM32F0, STM32F1, STM32F3, STM32L0, STM32L100, and STM32W1, we have created a separate algorithm file for programming the option bytes. For Cyclone users, a separate “CM ;Choose Module” command will need to be inserted into the image to select the option byte algorithm. Once the option byte algorithm is selected, users will see similar commands to the main flash algorithm.
Generally, the option bytes need to be erased before they can be reprogrammed. Certain devices allow the option bytes to be reprogrammed without being erased, so these algorithms may only have “PM ;Program Module” (like in the above image for the STM32L100). Users can then use a .s19 or .hex object file to program the option bytes. For some algorithms it is required that the “LO ;LAUNCH OPTIONS” command be done after programming to have the options take effect. This can be found under "Algorithm Specific Commands".
Users should reset the option bytes to default prior to programming the main flash of their device. This will ensure that obstructive settings such as read and write protection are removed prior to programming. If the user had set Level 1 Read Protection previously, they are required to use the “RU ;Read Unprotect” command before attempting to program the main flash or option bytes. Setting Read Protection to Level 2 is irreversible, so users should take care when programming Read Protection in the option bytes. Users should program their custom option byte settings after they program the main flash.
Devices with Special User Commands
For other devices such as the STM32F2, STM32F4, and STM32F7, there are ways of setting certain option bytes in the main flash algorithm. These commands will be listed under the “Algorithm Specific Commands” section in PROG. For example, the command “RP ;Read Protect” will prompt the user for a value to be programmed.
In the above example from the STM32F207ZG, there are 4 additional commands for the device that relate to the option bytes. “UP ;Read/Write Unprot.” will remove any read or write protection from the device, “RP ; Read Protect” will set read protection based on user input, “US ;User” will set the user row of the option bytes based on the user input, and “WP ;Write Protection” will set write protection on specific pages based on user input.