2020-08-12 04:44 AM
__attribute__((section(".myvars.VERSION_NUMBER"))) uint32_t VERSION_NUMBER = 0x12;
__attribute__((section(".myvars.CRC"))) uint32_t CRC16 = 0x12;
__attribute__((section(".myvars.BUILD_ID"))) uint16_t BUILD_ID = 0x12;
__attribute__((section(".myvars.OTHER_VAR"))) uint8_t OTHER_VAR = 0x12;
the mcu is stm32g474mb, please help me, thanks very much!
2020-08-12 05:14 AM
Does the .MAP file indicate the linker placed them somewhere, or discarded them?
Any other references to these variables stopping them from being discarded due to dead code removal?
Might want to work on the fact these sections overlap
2020-08-12 05:24 AM
AFAIK you cannot do it for gcc unless you spectic a secific section in the linker script and use the section attribute.
but, you can use a define like
#define FLASH_START (*((const unsigned long *) 0x08000000))
2020-08-12 06:03 AM
Hello,
As @Community member suggested, it is likely related to dead code removal / unused data removal.
In order to force the linker to keep it I would add the line KEEP (*(.myvars*)) at the begining of .myvars
.myvars :
{
KEEP (*(.myvars*))
*(.myvars.VERSION_NUMBER)
etc...
}
I'm not sure about the KEEP location, i.e. before or after the variables declaration.
Once the compilation is done, open the map file to check that it has been kept.
Best regards.
2020-08-12 05:56 PM
sorry I cant understand, and then how to save data to flash?
thanks
2020-08-12 10:38 PM
Flash is read-only memory unless you use dedicated registers+procedures for erasing and programming it. There is also a HAL_FLASH API for that.