<?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>NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/73301/nrf52840-app---random-hard-fault</link><description>Hi, 
 
 My application has hard faults sometimes, and I&amp;#39;m trying to figure out the reason. 
 When it occurs - I have a hard fault log, but p_stack-&amp;gt;pc is 0. I can&amp;#39;t understand what is the problematic code line. 
 Do I have another ways to catch the issue</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 01 May 2021 18:08:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/73301/nrf52840-app---random-hard-fault" /><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/307768?ContentTypeID=1</link><pubDate>Sat, 01 May 2021 18:08:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea36c933-d383-4576-bea5-2f770ec6a604</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;
&lt;p&gt;The hard fault occurs in a function which has a lot of external flash write and erase actions (via SPI interface). Hence - I think it may be the reason.&lt;/p&gt;
&lt;p&gt;Do you have any ideas?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/307733?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 22:27:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61c251ad-c7cb-4890-9fab-ded25bc88946</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Maybe the issue is with an interrupt allocating too much stack space by using (say) a print buffer inside the interrupt, so the interrupt generates the hard fault in &amp;quot;random&amp;quot; foreground code locations since the buffer is allocated on the stack in the interrupt before the interrupt code executes, which generates another hard fault interrupt. This probably only happens under worst-case stack usage scenarios, so rare. This is what Susheel is driving at, I think.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;Pointer to the stack bottom. This pointer might be NULL if the HardFault was called when the main stack was the active stack and a stack overrun is detected. In such a situation, the stack pointer is reinitialized to the default position, and the stack content is lost.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In such a case, examine all interrupt (event) handlers and remove any buffers and instead set a flag and process in (say) the main loop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;A second (classic) scenario is that a function allocates a local buffer on the stack using a variable parameter as the size of the stack; IAR would warn against that but SES does not. If the is an error in that parameter then the stack blows up. No good checking the parameters since the stack blows up before the parameters can be checked. Some of the TWI example code has this &amp;quot;feature&amp;quot; (or used to).&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/307730?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 21:01:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78a91993-938b-474a-8a99-2e4898d4c6ac</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you please tell me where can I increase beffurs size in sdk_config.h?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/303470?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 11:49:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2c7dd02-8d70-4ebe-9d25-53618328f3bc</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="Roei"]It&amp;#39;s not a function from the SDK of Nordic solution - it&amp;#39;s a new function which make a lot of job - writing and erasing a lot of pages from an external flash (using SPI protocol).[/quote]
&lt;p&gt;&amp;nbsp;In that case, this memory corruption is hard to track from our side as these seems to be introduced with your changes. And with the minimal information given and no way to reproduce on our end, it is very hard for me to narrow down the problem for you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/303455?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 11:24:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13a4c675-8547-4217-ac0a-1a2b708cfae9</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;It&amp;#39;s not a function from the SDK of Nordic solution - it&amp;#39;s a new function which make a lot of job - writing and erasing a lot of pages from an external flash (using SPI protocol).&lt;/p&gt;
&lt;p&gt;Already tried to debug and didn&amp;#39;t find any specific line. It is also occurs not very often.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/303452?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 11:21:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb37091d-55a2-45c9-988d-ca167d8289a2</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="Roei"]In addition - the hard fault occurs in a specific function[/quote]
&lt;p&gt;&amp;nbsp;Is this a function from a Nordic solution? Which function is it?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Roei"]When testing performance of this function - I&amp;#39;ve noticed that CPU usage of one of the services if very high (about 800%).[/quote]
&lt;p&gt;the percentage of CPU usage should not be the reason for the hardfault. It might be the memory usage by that function. But if you know the function that causes this hardfault, then you can step in and debug to see which line exactly causes this. If this function is from the the Nordic solution (SDK) then i might be able to help you debug it if you help me reproduce it at my desk.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/303428?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 10:00:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c74a03e-41e0-44ef-84f0-94d028c08ecf</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;In addition - the hard fault occurs in a specific function.&lt;/p&gt;
&lt;p&gt;When testing performance of this function - I&amp;#39;ve noticed that CPU usage of one of the services if very high (about 800%).&lt;/p&gt;
&lt;p&gt;Can it be related to the hard fault?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/303376?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 07:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8b445dd-0852-4abc-aee9-cd8c49207ad5</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t understand which buffers can be changes in sdk_config.h.&lt;/p&gt;
&lt;p&gt;Can you please explain?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/302942?ContentTypeID=1</link><pubDate>Sun, 04 Apr 2021 15:56:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff0848ae-f8d3-4564-bf42-bf2614abc09e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The hardfault stack frame seems incorrect, that means that wrong stack frame might have been popped into the registers. Which means that some of the stack buffers might have overflowed causing the the next stack frame to get corrupted.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Trying disabling logs to see if logs buffers are overflowing (disabling logs should fix the issue if logs buffers are too small for your application). If that does not help, then try to increase the buffer size of modules (in sdk_config.h) one by one to figure out which module&amp;#39;s buffer is overflowing. Unfortunately, this could be a tedious debugging session.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/302652?ContentTypeID=1</link><pubDate>Tue, 30 Mar 2021 19:07:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:273897a8-8ca3-476b-b776-0cdfa8ad0c83</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;In addition - I have a log of the following lines:&lt;/p&gt;
&lt;p&gt;HARD FAULT at 0x00000000&lt;br /&gt;R0: 0x00000010 R1: 0x00000000 R2: 0x20007908 R3: 0x00000000&lt;br /&gt;R12: 0x20011F34 LR: 0x0003262F PSR: 0x00000000&lt;/p&gt;
&lt;p&gt;Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can it help me?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/302501?ContentTypeID=1</link><pubDate>Tue, 30 Mar 2021 08:18:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eadde61e-4840-4965-a4b7-60c648fcb9e0</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;The problem that it occurs randomly, and it doesn&amp;#39;t happen due to specific code lines (already tried the hard way). Can it be related to memory space? Maybe increasing memory can solve the issue?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 app - random hard fault</title><link>https://devzone.nordicsemi.com/thread/302500?ContentTypeID=1</link><pubDate>Tue, 30 Mar 2021 08:13:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:569d453b-dc51-4e66-a465-953f3094178d</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;if the PC value in the stack frame for the hardfault reads 0, then it is very likely that you had a memory corruption that contributed to the hardfault. You need to debug such scenarios by stepping through the code until you understand the context of the hardfault (the hard debugging way)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>