cancel
Showing results for 
Search instead for 
Did you mean: 

SMT32CubeIDE - How to store a const struct at a specific flash memory address?

ERODR.1
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
ERODR.1
Associate III

Thanks for your input. I created a new section in the linker as suggested.

ERODR.1
Associate III

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
};