2023-08-30 02:32 AM
I'm working with the STM32F7 microcontroller and I compile using STM32CubeIDE. I want to place myStruct on a specific location in RAM and I want it be initialized automatically:
MEMORY {
...
MY_STRUCT_MEMORY(rwx): ORIGIN = 0x20007BA0 LENGTH = 8
...
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2097152
}
SECTIONS {
...
.myStructSection :
{
. = ALIGN(4);
KEEP(*(.myStructSection))
*(.myStructSection .myStructSection.*)
. = ALIGN(4);
} >MY_STRUCT_MEMORY
...
}
typedef struct { int myInt1; int myInt2; } MyStruct_s;
__attribute__ ((section(".myStructSection"),used)) MyStruct_s myStruct = {12345, 67890};
Does anybody know what I'm missing?
Solved! Go to Solution.
2023-08-30 04:51 PM
You're missing that the startup file is only programmed to initialize the default data section, between _sdata and _edata.
You're also missing that it should be ">MY_STRUCT_MEMORY AT> FLASH" since the data needs to be stored in flash before it's sent to RAM.
If you do that and modify your startup script to initialize the new section it'll work. Will need to define some new symbols. But the linker won't write a new startup file for you.
2023-08-30 04:51 PM
You're missing that the startup file is only programmed to initialize the default data section, between _sdata and _edata.
You're also missing that it should be ">MY_STRUCT_MEMORY AT> FLASH" since the data needs to be stored in flash before it's sent to RAM.
If you do that and modify your startup script to initialize the new section it'll work. Will need to define some new symbols. But the linker won't write a new startup file for you.