I currently have a C project where I have to write a specific value (0xaa) to a specific address (0x3fec0), and I would like to write it during the programming sequence. The solution I have found is the following :
I write another section in the linker file :
/* Custom flag section in linker file */
_flag_start = 0x3fec0;
.flag _flag_start :
{
KEEP(*(.flag));
}
I write the value as a static variable :
static uint8_t flag __attribute__((section (".flag"))) __attribute__((__used__)) = 0xaa;
It works well, and I manage to write the right value at the right address. However it also generates a very heavy binary : because I set this section at 0x3fec0, my binary will be 261824 Bytes (0x3fec0 in decimal), meaning approx 255KB, as if it was filling with empty data until it reaches this address.
My question is : how to perform the same thing, but without impacting the size of the binary file ?
*((*unsigned char)0x3fec0) = 0xaaU;*((unsigned char*)0x3fec0) = 0xaaU;works here.