After watchdog reset, I want to record the last program counter from the stack. So I want to know how can I get the stack pointer from the program.
After watchdog reset, I want to record the last program counter from the stack. So I want to know how can I get the stack pointer from the program.
Hi,
The watchdog will not reset the RAM, but it might be corrupted, as per this instance table (see the note):
If you are to store the stack, you should store it into a non inited global section from the watchdog event handler.
The watchdog interrupt handler will execute approx. 2 RTC cycles before a reset occurs, so you do not have much time.
If possible, you should also add a simple checksum on the content you're storing, to ensure that it has not been corrupted after wdt reset.
Here's a thread, with an example on dumping the stack:
https://devzone.nordicsemi.com/f/nordic-q-a/30075/saving-the-location-of-watchdog-timeout
Note that the .non_init section is defined by default in SES, so you don't need to add it manually in flash_placement.xml
Kind regards,
Håkon