<?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>Hardfault handler implementation - changing SP in case of stack overflow</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66211/hardfault-handler-implementation---changing-sp-in-case-of-stack-overflow</link><description>Hello, 
 I currently designing fault handling for a firmware for nrf52840 in SES for SDK16. 
 At line number 68 in the hardfault_handler_gcc.c, assuming a stack overflow happened and we want to reset the SP pointer, shouldn&amp;#39;t BHI (Unsigned comparison</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Sep 2020 10:04:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66211/hardfault-handler-implementation---changing-sp-in-case-of-stack-overflow" /><item><title>RE: Hardfault handler implementation - changing SP in case of stack overflow</title><link>https://devzone.nordicsemi.com/thread/270786?ContentTypeID=1</link><pubDate>Tue, 22 Sep 2020 10:04:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8112d805-8cca-40b0-846c-8bf5eb34d987</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Nope. That check in line 68 checks if the SP was &lt;em&gt;bigger&lt;/em&gt; than&amp;nbsp; __StackTop, which is equal to end-of-RAM in most cases. That indicates something has completely trashed the SP value altogether, and it is unusable. Hence the jump to &amp;quot;_MoveSP&amp;quot;, which just uses __StackTop in order to keep the remaining C code form generating &lt;em&gt;another&lt;/em&gt; hard fault (would result in lockup reset).&lt;/p&gt;
&lt;p&gt;Also note that this code won&amp;#39;t work properly with PSP (e.g. RTOS) setups, as it assumes one single stack between __StackTop and __StackLimit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>