For Teensy 4.1, I like to see some RAM values in custom sections to be kept after reset (not power off). The following is my code and linker script. What I can see from this code is that v1 and v2 always get random value after reset, rather than the previously assigned value. Is that the correct behavior? Is there any other way to reset the controller so the v1, v2 will be kept?
Code:
. . .
__attribute__((used)) __attribute__((section(".myRAMData1"))) int v1;
__attribute__((used)) __attribute__((section(".myRAMData2"))) int v2;
extern "C" int main(void)
{
Serial.begin(230400);
char buf[100];
sprintf(buf,"after reset: v1=%d, v2=%d",v1,v2);
Serial.println(buf);
v1 = 100;
v2 = 108;
sprintf(buf,"assigned: v1=%d, v2=%d",v1,v2);
Serial.println(buf);
delay(1000);
Serial.println("restart");
delay(1000);
SCB_AIRCR = 0x05FA0004; // firmware reset
}
Code:
. . .
SECTIONS
{
.text.progmem : {
KEEP(*(.flashconfig))
FILL(0xFF)
. = ORIGIN(FLASH) + 0x1000;
KEEP(*(.ivt))
KEEP(*(.bootdata))
KEEP(*(.vectors))
KEEP(*(.startup))
*(.flashmem*)
*(.progmem*)
. = ALIGN(4);
KEEP(*(.init))
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
__init_array_start = .;
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(16);
} > FLASH
.text.itcm : {
. = . + 32; /* MPU to trap NULL pointer deref */
*(.fastrun)
*(.text*)
. = ALIGN(16);
} > ITCM AT> FLASH
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > ITCM AT> FLASH
.text.itcm.padding (NOLOAD) : {
. = ALIGN(32768);
} > ITCM
.data : {
*(.rodata*)
*(.data*)
. = ALIGN(16);
} > DTCM AT> FLASH
.bss ALIGN(4) : {
*(.bss*)
*(COMMON)
. = ALIGN(32);
. = . + 32; /* MPU to trap stack overflow */
} > DTCM
[COLOR="#FF0000"] .my_data1 (NOLOAD) : {
KEEP(*(.myRAMData1))
} > RAM[/COLOR]
.bss.dma (NOLOAD) : {
*(.dmabuffers)
. = ALIGN(32);
} > RAM
.bss.extram (NOLOAD) : {
*(.externalram)
} > ERAM
[COLOR="#FF0000"] .my_data2 (NOLOAD) : {
KEEP(*(.myRAMData2))
} > RAM
[/COLOR]
. . .