How do I place an INITIALIZED struct on a specific location in RAM?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-30 2: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.
- Labels:
-
STM32F7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-30 4: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-30 4: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.
