Initialized variable at specific location optimized out?
Hi,
I need to place a initialized variable at the beginning of RAM. This variable won't be read or modified by the application, it's only read by the ST-Link during programming operation.
So I modified the linker script by adding a section PRJINFO (project info):
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
KEEP(*(.PRJINFO*)) /* project information */
. = 0x20;
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASHThis area is 32 byte in size and the linker shouldn't throw away this section. I created a C file which contains a 32-byte array containing some information:
uint8_t ProjectProgramVersion[32] __attribute__((section(".PRJINFO"), used)) = {
(PRJ_SW_VER >> 20) & 0xFF,
(PRJ_SW_VER >> 28) & 0x0F,
(PRJ_SW_VER >> 12) & 0xFF,
(PRJ_SW_VER >> 8) & 0x0F,
(PRJ_SW_VER) & 0xFF,
(PRJ_SW_VER_INDEV) * 0x0E
};This should place this array in the project info section, optimizing out should be prevented by linker (KEEP keyword) and compiler (attribute used). However, it only works in the debug build. Linking the release build gives garbage when reading out the memory locations.
Any ideas what might go wrong?
Regards
