Accessing a memory section defined in the linker script
[Apologies in advance if this question has been asked a thousand times. I just didn't know how to search to get the answer that I'm looking for.]
I defined a section in the linker script to store version information. However, I'm unable to figure out how to read this memory from the c/c++ code side.
In the linker script, I defined it in the 2nd section after the .isr_vector, ie:
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* Version Data Into Flash */
.version :
{
. = ALIGN(4);
KEEP(*(.version))
KEEP(*(.version*))
. = ALIGN(4);
} >FLASH
.
.
}
In the main.c, I was able to set the version by:
static const char version[] __attribute__((used)) __attribute__((section (".version"))) = "v0.1.0";
Elsewhere in the code, I want to get the version string. I tried the following but the debugger shows the memptr pointer is 0x0:
const char* __attribute__(( section(".version") )) memptr;
I know the version was written correctly as I confirmed by looking at the memory map using STMCubeProgerammer and the memory address of the ".version" is 0x8000298.
I don't want to hard code since that address can change. Any assistance is appreciated. Thanks.