Option bytes in firmware
Hello,
Device: STM32L443CCU
I am trying set option bytes values in firmware as a ROM constants. The idea is firmware will have option bytes embedded, and when firmware hex will be flashed, it will also flash new option bytes.
So I did following implementation:
- Linker script
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
RAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
FUSES (r) : ORIGIN = 0x1FFF7800, LENGTH = 40 /* Option Bytes (configuration fuses) */
}Then under SECTIONS.,
.fuses :
{
. = ALIGN(4);
KEEP(*(.optionbytes1))
KEEP(*(.optionbytes1Inverted))
KEEP(*(.optionbytes2))
KEEP(*(.optionbytes2Inverted))
KEEP(*(.optionbytes3))
KEEP(*(.optionbytes3Inverted))
KEEP(*(.optionbytes4))
KEEP(*(.optionbytes4Inverted))
KEEP(*(.optionbytes5))
KEEP(*(.optionbytes5Inverted))
. = ALIGN(4);
}>FUSES2. Then in main code., I defined ROM constants with values for option bytes
#pragma GCC push_options
#pragma GCC optimize ("O0")
const uint32_t OptionBytes1Default __attribute__(( section(".optionbytes1") )) = platform::OptionByte1DefaultValue;
const uint32_t OptionBytes1InvertedDefault __attribute__(( section(".optionbytes1Inverted") )) = ~platform::OptionByte1DefaultValue;
const uint32_t OptionBytes2Default __attribute__(( section(".optionbytes2") )) = platform::OptionByte2DefaultValue;
const uint32_t OptionBytes2InvertedDefault __attribute__(( section(".optionbytes2Inverted") )) = ~platform::OptionByte2DefaultValue;
const uint32_t OptionBytes3Default __attribute__(( section(".optionbytes3") )) = platform::OptionByte3DefaultValue;
const uint32_t OptionBytes3InvertedDefault __attribute__(( section(".optionbytes3Inverted") )) = ~platform::OptionByte3DefaultValue;
const uint32_t OptionBytes4Default __attribute__(( section(".optionbytes4") )) = platform::OptionByte4DefaultValue;
const uint32_t OptionBytes4InvertedDefault __attribute__(( section(".optionbytes4Inverted") )) = ~platform::OptionByte4DefaultValue;
const uint32_t OptionBytes5Default __attribute__(( section(".optionbytes5") )) = platform::OptionByte5DefaultValue;
const uint32_t OptionBytes5InvertedDefault __attribute__(( section(".optionbytes5Inverted") )) = ~platform::OptionByte5DefaultValue;
#pragma GCC pop_options3. it builds successfully, and I verified values and addresses in hex file. Looks right.
4. Using STM32 cube programmer, I tried flashing hex file, with the option "Donwload" and with "Verify Programming" ticked.
5. Then cube programmer does erase and write successfully. But for verify it fails for option byte address,
14:35:16:752 : Reading data...
14:35:16:752 : r ap 0 @0x0801C800 0x00000210 bytes
14:35:16:752 : Reading data...
14:35:16:768 : r ap 0 @0x1FFF7800 0x00000008 bytes
14:35:16:768 : Error: Data mismatch found at address 0x1FFF7802 (byte = 0xE9 instead of 0xEF)
14:35:16:768 : Error: Download verification failedSo looks like option byte flash area is not updated. If I do set option bytes manually from "OB" tab of cube programmer it works perfectly. But flashing option bytes via hex file simply fails.
Anybody has idea what could be wrong?
Also, another point, cube programmer uses address 0x40022020, which is NOT option byte area address.
14:37:29:368 : UPLOADING OPTION BYTES DATA ...
14:37:29:368 : Bank : 0x00
14:37:29:369 : Address : 0x40022020
14:37:29:369 : Size : 20 Bytes
14:37:29:369 : Reading data...
14:37:29:369 : r ap 0 @0x40022020 0x00000014 bytes}
