<?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>Pinpointing hard faults caused during SoftDevice execution more effectively</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106377/pinpointing-hard-faults-caused-during-softdevice-execution-more-effectively</link><description>Hi, I&amp;#39;m working on integrating the reference secure DFU bootloader from the nRF5 SDK (nRF5_SDK_17.1.0_ddde560/examples/dfu/secure_bootloader/pca10100_s140_ble_debug/armgcc) to my application, which is running on a custom nRF52833 board with SoftDevice</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Dec 2023 06:58:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106377/pinpointing-hard-faults-caused-during-softdevice-execution-more-effectively" /><item><title>RE: Pinpointing hard faults caused during SoftDevice execution more effectively</title><link>https://devzone.nordicsemi.com/thread/459274?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2023 06:58:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b396e68a-2d73-473d-8849-a974d24feee3</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;oldmud0,&lt;/p&gt;
&lt;p&gt;A great number of times I have had been dealing with stack corrupted hardfaults and hence was thinking in that direction aswell. I haven&amp;#39;t used the GDB that much myself but I believe that you have seen this message about &amp;quot;backtrace stopped&amp;quot; enough number of times with valid stack frames. So I trust you and believe that the stack frame is still sane.&lt;/p&gt;
[quote user="oldmud0"]Maybe in the future, I should try unwinding the stack pointed to by the PSP and seeing what&amp;#39;s there, since that&amp;#39;s application code and it&amp;#39;ll give me the general area of where the fault occurred on the application side.[/quote]
&lt;p&gt;OK, you seem to know your stuff. That might be helpful actually if you put a breakpoint&amp;nbsp;in&amp;nbsp;components\libraries\hardfault\nrf52\handler\hardfault_handler_gcc.c and get the application context from there instead of the softdevice context that caused this hardfault.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pinpointing hard faults caused during SoftDevice execution more effectively</title><link>https://devzone.nordicsemi.com/thread/459247?ContentTypeID=1</link><pubDate>Wed, 06 Dec 2023 17:33:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94dbbc67-7f3f-42d6-8833-ee33881806b6</guid><dc:creator>oldmud0</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;Thanks for your answer. This reference bootloader already contains an app_error_fault_handler method (main.c:86). It was not triggered.&lt;/p&gt;
&lt;p&gt;When the error message says &amp;quot;return address in the stack frame is not related to the instruction that caused the error,&amp;quot; I believe it is referring to the fact that this data bus error is an asynchronous bus fault (IMPRECISERR) and therefore the instruction that the processor stopped at may not have been the instruction that caused the error.&lt;/p&gt;
&lt;p&gt;&amp;quot;Backtrace stopped: previous frame identical to this frame (corrupt stack?)&amp;quot; is a generic note from GDB, and it doesn&amp;#39;t mean that the stack was corrupted. The stack can change due to context switches, and I usually ignore this message unless the backtrace looks really messed up with garbage addresses. As the SoftDevice is a hard real time system that raises and handles interrupts, it makes sense to me that the stack only traces back to the SoftDevice.&lt;/p&gt;
&lt;p&gt;Maybe in the future, I should try unwinding the stack pointed to by the PSP and seeing what&amp;#39;s there, since that&amp;#39;s application code and it&amp;#39;ll give me the general area of where the fault occurred on the application side.&lt;/p&gt;
&lt;p&gt;Apparently, the switch between PSP and MSP does trip people up and cause them to believe that the stack might have been messed up somehow.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pinpointing hard faults caused during SoftDevice execution more effectively</title><link>https://devzone.nordicsemi.com/thread/459139?ContentTypeID=1</link><pubDate>Wed, 06 Dec 2023 10:49:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd821401-a61d-4f57-a6dd-13396c1a2561</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""]However, it seems like the SoftDevice doesn&amp;#39;t have a way of signaling clearly, &amp;quot;Hey, this hard fault happened during X operation.&amp;quot; Or, when flash erase/writes are happening, the SoftDevice should handle hard faults momentarily to catch the error so it can be sent back as an event. Otherwise, the context of the error is lost.[/quote]
&lt;p&gt;Softdevice do have a way to signal faults through the&amp;nbsp;app_error_fault_handler if the softdevice has asserted or there is a hardfault in the softdevice. But I think in this case the whole debug method is based on the fact that you think the hardfault info that is pulled from the stack is uncorrupted.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Both the logs and you GDB tells you that the stack frame does not look sane&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;error&amp;gt; hardfault: Cause: Data bus error (return address in the stack frame is not related to the instruction that caused the error).

Backtrace stopped: previous frame identical to this frame (corrupt stack?)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;These normally means that the stack frame does not look sane and most likely corrupted. In such cases hardfault debugging becomes even more manual and there is given way to debug. The stack frame could be corrupted by many reasons and it is not necessarily caused by softdevice.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>