How to keep the status of SRAM and do not initialize it when chip is reset?

Post Reply
a_ziliu
Posts: 208
Joined: 20 Mar 2017, 10:52

31 May 2021, 16:24

To take the watchdog reset of M031 as an example.
When chip is reset, CPU will start to run code from “startup_M031Series.s”. In this code, program counter will jump to “startup_M031Series.c” and execute the System_Init function. After executing, the program counter will jump to __main function.

LDR R0, =SystemInit // Setting R0 as the address of SystemInit
BLX R0 // Jump to address of R0 and execute Thumb command
LDR R0, =__main // Setting R0 as address of __main
BX R0 // Jump to address of R0

__main function is built from compiler automatically. This function will initialize the SRAM. This initialization includes copy RW-data and ZI-data to SRAM, initialize the ZI-data to 0 and so on. After executing the __main, the program counter will jump to __rt_entry function.
__rt_entry function is built from compiler automatically, too. This function will setup the environment of executing the program. The setup includes initialize the Stack, Heap, Library and so on. After executing the __rt_entry, the program founter will jump to main() function.

If user wants to keep the SRAM status when chip is reset, it just needs to jump to main() function before entry __main function.

extern int32_t main(void);
void SystemInit(void)
{
/* If the last reset source is WDT Reset, do not reset SRAM */
if(SYS->RSTSRC & SYS_RSTSRC_RSTS_WDT_Msk)
{
main();
}
……
}

Note: This flow chart is quoted from KEIL website.

For detailed description of Startup flow, please refer to KEIL website:

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests