I'm programming STM32L432KC and I want to put it in standby mode which preserves SRAM2
content. To do that I created a separated section in memory by separating the SRAM1
from SRAM2
.
In this chip, the SRAM1
and the SRAM2
can be treated as a continuous memory region, so originally the memory was mapped like that in the linker script:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
}
I changed it to separate the SRAM1
and SRAM2
:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K
}
The region 0x2000C000 - 0x20010000
is mapped to 0x10000000 - 0x10004000
by default.
Then I mapped a section to the new memory region in the linker script:
.sram2 :
{
. = ALIGN(4);
_ssram2 = .;
*(.sram2)
*(.sram2*)
. = ALIGN(4);
_esram2 = .;
} > SRAM2
And then put an initialized global variable in the new section:
static unsigned test_var __attribute__((section(".sram2")) = 10;
The problem is that I didn't edit the startup code to copy the initialized data into the SRAM2
, but when I debug I can see that the variable gets initialized and I think it shouldn't.
The question is: why it is initialized?
I wonder if STLinkV2 apart from flashing the device it also initializes the RAM region.