<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How can I get the stack pointer from the program?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57699/how-can-i-get-the-stack-pointer-from-the-program</link><description>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.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 Feb 2020 09:18:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57699/how-can-i-get-the-stack-pointer-from-the-program" /><item><title>RE: How can I get the stack pointer from the program?</title><link>https://devzone.nordicsemi.com/thread/233898?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 09:18:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84e8de76-3c3b-4f03-8f4a-ec5c96d81882</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The watchdog will not reset the RAM, but it might be corrupted, as per this instance table (see the note):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html?cp=4_2_0_17_7#unique_832471788"&gt;https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html?cp=4_2_0_17_7#unique_832471788&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you are to store the stack, you should store it into a non inited global section from the watchdog event handler.&lt;/p&gt;
&lt;p&gt;The watchdog interrupt handler will execute approx. 2 RTC cycles before a reset occurs, so you do not have much time.&lt;/p&gt;
&lt;p&gt;If possible, you should also add a simple checksum on the content you&amp;#39;re storing, to ensure that it has not been corrupted after wdt reset.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s a thread, with an example on dumping the stack:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/30075/saving-the-location-of-watchdog-timeout"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/30075/saving-the-location-of-watchdog-timeout&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Note that the .non_init section is defined by default in SES, so you don&amp;#39;t need to add it manually in flash_placement.xml&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>