Forum: System Workbench for STM32

Write option bytes

I know that the ST-LINK Utility from ST is capable of editing the Option Bytes.
Option Bytes

In my experience System Workbench is not capable of doing so. Plus System Workbench is not the tool I planned to use in production. Two good reasons to find an other way to flash the Option Bytes: embed them into the binary file.

Here is an extract of my source code:

// 0x 1FFF F800 -> Option Byte 1 (nUSER, USER, nRDP, RDP)
const uint32_t optionbytes1 attribute(( section(“.optionbytes1”) )) = 0x20DF55AA;
// 0x 1FFF F804 -> Option Byte 2 (nData1, Data1, nData0, Data0)
const uint32_t optionbytes2 attribute(( section(“.optionbytes2”) )) = 0x00FF00FF;
// 0x 1FFF F808 -> Option Byte 3 (nWRP1, WRP1, nWRP0, WRP0)
const uint32_t optionbytes3 attribute(( section(“.optionbytes3”) )) = 0x00FF00FF;
// 0x 1FFF F80C -> Option Byte 4 (nWRP3, WRP3, nWRP2, WRP2)
const uint32_t optionbytes4 attribute(( section(“.optionbytes4”) )) = 0x00FF00FF;


Here is an extract of my Linker script:

MEMORY
{
...
FUSES (r) : ORIGIN = 0x1FFFF800, LENGTH = 16 /* Option Bytes (configuration fuses) */
...
}

SECTIONS
{
...
.fuses :
{
. = ALIGN(4);
KEEP(*(.optionbytes1))
KEEP(*(.optionbytes2))
KEEP(*(.optionbytes3))
KEEP(*(.optionbytes4))
. = ALIGN(4);
} >FUSES
...
}


In the end I obtain a binary file that embeds a section relative to the Option Bytes.
Here is an extract of my *.hex file:

:020000041FFFDC
:10F80000AA55DF20FF00FF0000FF00FFFF00FF0000


Doing like that allows you to flash your Option Bytes from System Workbench!