2021-11-21 11:55 AM
I'm trying to store a const struct at a specific flash memory location using the STM32CubeIDE. I tried appending the __attribute__((at(address))) to the struct initialization, but the compiler ignores it: "warning: 'at' attribute directive ignored [-Wattributes]"
const runtimeParams params __attribute__((at(0x0801F800))) = {
// ... initialization values
};
What would be the correct way to accomplish this?
Solved! Go to Solution.
2021-11-21 12:19 PM
There's not an easy way to do this in GCC. You either need to create a separate section in the linker to place the code, or use a pointer to store it somewhere directly while ensuring nothing else lives in that space.
2021-11-21 12:19 PM
There's not an easy way to do this in GCC. You either need to create a separate section in the linker to place the code, or use a pointer to store it somewhere directly while ensuring nothing else lives in that space.
2021-11-21 02:21 PM
Thanks for your input. I created a new section in the linker as suggested.
2021-11-21 02:25 PM
For anybody else wondering how to do it. I edited the STM32F072CBTX_FLASH.ld to add a new section as below:
/* Runtime parameters section in FLASH */
_params_start_address = 0x0801F800;
.params _params_start_address :
{
. = ALIGN(4);
KEEP (*(.params))
} >FLASH
And then specified the section attribute in the const initialization as follows:
const runtimeParams __attribute__((section (".params"))) params = {
// ... Initialization values
};