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);
/* If the last reset source is WDT Reset, do not reset SRAM */
if(SYS->RSTSRC & SYS_RSTSRC_RSTS_WDT_Msk)
Note: This flow chart is quoted from KEIL website.
For detailed description of Startup flow, please refer to KEIL website: