<?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>Wierd hardfault</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75722/wierd-hardfault</link><description>I have a bit of an odd one, and would appreciate any input. We have a fairly complex project, which does various things, but some of the time, I get a hardfault. The issue appears to be a instruction access violation (MMFSR-&amp;gt;IACCVIOL = 1). Working backwards</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Jun 2021 18:26:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75722/wierd-hardfault" /><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/316349?ContentTypeID=1</link><pubDate>Mon, 21 Jun 2021 18:26:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c72e2ad-7c3f-47b6-ab0e-7b9e4d6547de</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Alison,&lt;/p&gt;
&lt;p&gt;Thanks for the update! I&amp;#39;m glad to hear that it fixed the problem. Will definelty remember keep this in mind next time I encounter a hardfault like this. And I agree,&amp;nbsp; too long charging time of the cap seems to be the most likely explanation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/316312?ContentTypeID=1</link><pubDate>Mon, 21 Jun 2021 14:50:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0559553b-f38e-4922-8255-7477e35a924a</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve done a number of different tests across several boards, and the DEC1 decoupling cap looks like our answer.&amp;nbsp; Dropping it to the 100nF it was supposed to be seems to have made all the hardfaults go away completely.&lt;/p&gt;
&lt;p&gt;I guess that the issue was more obvious at lower powers, possibly due to the cap not charging / discharging fast enough, and causing clock / rail skew, to the point where the core got really unhappy.&amp;nbsp; Hence always happening after a WFI, and being so sensitive to which peripherals were enabled or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Either way, excellent spot, and thank you for your help!&amp;nbsp; Beers on us next time you&amp;#39;re in London...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/315447?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 14:24:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:345a3f55-3671-4726-8781-3e05fc412d27</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Alison,&lt;/p&gt;
&lt;p&gt;I have actually seen reports of similiar behaviour before for boards that have been fitted with a too large capacitor on DEC1, so I think we may finally have found a root cause. I hope this is it.&lt;/p&gt;
[quote userid="52927" url="~/f/nordic-q-a/75722/wierd-hardfault/315444#315444"]Putting the chip into constant latency mode makes the hardfault problem go away (or, at least, I haven&amp;#39;t been able to reproduce it now).[/quote]
&lt;p&gt;I think a possible explanation for this is that constant latency prevents the system from entering its lowest power state (min. idle current is ~500 uA with constant latency enabled).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/315444?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 14:15:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed8dbb3a-f6d7-433a-b96b-5711537aed79</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Although our original design was incorrect with regard to the decoupling layout, this board has been updated to match configuration 6 WLCSP from the datasheet (and your link).&amp;nbsp; However, on careful examination, it looks like the cap fitted to DEC1 (C4 in the reference) is considerably too large - 2.2uF instead of 100nF.&amp;nbsp; I&amp;#39;ll get our electronics chap to break out the fine soldering iron and change it, and let you know if that makes any difference.&lt;/p&gt;
&lt;p&gt;Also of note, we&amp;#39;re running without any crystals - as we&amp;#39;re not doing any BLE etc, the timing accuracy isn&amp;#39;t critical, and fewer external components is hugely helpful in our application.&amp;nbsp; We&amp;#39;re using the internal RCs for both HF and LF clocks.&lt;/p&gt;
&lt;p&gt;Putting the chip into constant latency mode makes the hardfault problem go away (or, at least, I haven&amp;#39;t been able to reproduce it now).&lt;/p&gt;
&lt;p&gt;I can provide the code and schematic privately, although most of the code won&amp;#39;t run without the custom hardware.&amp;nbsp; I will also need to excise some third-party code, as we&amp;#39;re not authorised to share that, which will of course change the behaviour and timing somewhat.&amp;nbsp; Running on a DK has similar issues, although we can at least bolt on a lot of the necessary bits externally.&amp;nbsp; I&amp;#39;ll have a look at porting the codebase over if changing the DEC1 cap doesn&amp;#39;t improve things.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/315357?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 11:07:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8ff7ac2-2938-4e55-a32e-497f3a6a7d10</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for confirming. So the 52833 is not impacted by errata 220. Though I expect the workaround for it could change the behaviour slightly like workaround for errata 87 did if the problem is indeed timing related.&lt;/p&gt;
&lt;p&gt;Could you please try to put the chip in constant latency mode on startup and see if it makes any difference? Constant latency mode (see&amp;nbsp;&lt;span&gt;&lt;a title="Sub-power modes" href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/power.html?cp=4_1_0_4_2_3_0#unique_96010932"&gt;Sub-power modes&lt;/a&gt;&lt;/span&gt;) should have similiar effect on interrupt latency as as putting the chip in debug mode has (both modes keep the HF clock running in sleep).&lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void main(void)
{
    NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;With regards to __WFI vs__WFE, I think Anders gives a good summary of it in this post: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/490/how-do-you-put-the-nrf51822-chip-to-sleep/2571#2571"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/490/how-do-you-put-the-nrf51822-chip-to-sleep/2571#2571&lt;/a&gt;. The main difference is basically that __WFE enters sleep conditionally based on the internal event register, while __WFI does not. The reason for using one over the other is if implemention will be subjected to race conditons or not.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit: &lt;/strong&gt;Would you be able to share the full source code here or in a private support ticket so I can try to debug it here, or does it require your custom HW to run it?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit 2 :&amp;nbsp; &lt;/strong&gt;Have you tested this on a nordic DK? I&amp;#39;m starting to think that this may be a HW issue. I&amp;#39;d suggest suggest to go over the decoupling caps used on your board and see if they match the values we recommend in our reference design here:&amp;nbsp; &lt;span class="item"&gt;&lt;a class="" title="Reference circuitry" href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/ref_circuitry.html?cp=4_1_0_6_2"&gt;Reference circuitry&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/315355?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 10:57:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7cef6516-bc08-40ee-8164-6ce644aceb16</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Ok, I&amp;#39;ve reduced hmolesworth&amp;#39;s suggested code to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk;
  __disable_irq();
  __WFE();
  __WFE();
  __NOP(); __NOP(); __NOP(); __NOP();
  __enable_irq();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;so we&amp;#39;re just looking at the errata 220 stuff.&amp;nbsp; This doesn&amp;#39;t produce a noticable difference in behaviour - we&amp;#39;re back to an IACCVIOL hardfault, but the behaviour is otherwise the same.&amp;nbsp; The LR and top of stack return point to probably-junk places outside normal values.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/315205?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 15:17:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:baf19e1a-1946-4ea5-93bf-ce3507a3a932</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar and hmolesworth,&lt;/p&gt;
&lt;p&gt;We&amp;#39;re definitely using the &amp;#39;833 - NRF52833-CJAA-A0 if it makes any difference.&amp;nbsp; &lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52833_Rev1/ERR/nRF52833/Rev1/latest/err_833_new.html"&gt;https://infocenter.nordicsemi.com/topic/errata_nRF52833_Rev1/ERR/nRF52833/Rev1/latest/err_833_new.html&lt;/a&gt; suggests that errata 220 doesn&amp;#39;t apply, but I&amp;#39;ll give the code you&amp;#39;ve suggested a go when I&amp;#39;m next in front of the board.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Errata 87 does apply, however, hence the code snippet above.&lt;/p&gt;
&lt;p&gt;The debug seems to be pointing to the __WFI() call causing the issues here, although that may be masking something else.&amp;nbsp; That would be consistent with the issue not showing up during debug, as WFI/WFE behaviour is presumably slightly different when a debugger is attached, to not cause dropouts.&lt;/p&gt;
&lt;p&gt;On a related note, my understanding of how the ARM core in the nRF52 is used is that the WFI and WFE instructions are almost the same, with the difference that one normally uses WFE with SEV to ensure the core actually goes to sleep:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;__SEV();
__WFE(); // clear SEV bit
__WFE(); // actually go to sleep&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Further reading here: &lt;a href="https://developer.arm.com/documentation/dui0553/a/"&gt;https://developer.arm.com/documentation/dui0553/a/&lt;/a&gt; .&lt;/p&gt;
&lt;p&gt;Is this correct?&amp;nbsp; Is there a good reason to use WFE instead of WFI in the Nordic chips?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/315090?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 11:09:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fb956ef-96dc-493a-a4a9-59c4023161bc</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I was a bit confused too, I thought Ozone was displaying the stack trace in a reversed order, because it didn&amp;#39;t match your observation otherwise. But I should have realized it was wrong after having seen the stack frame addresses. Anyway. It&amp;#39;s good to have cleared that up.&lt;/p&gt;
[quote user="alison.lloyd"]Commenting it out made it obvious, as then the PC ends up pointing to the nrf_gpio_pin_* functions, which are setting the LEDs.&amp;nbsp; This also caused the resultant hardfault to change to an IBUSERR instead - the call stack included a call to __WFI(), which is slightly different.[/quote]
&lt;p&gt;I think the the address/fault change is a result of the project being re-built with slighlty modified code. I don&amp;#39;t see any other reason for why adding clearing of the FPU pending bit should make a difference. &lt;strong&gt;Edit: &lt;/strong&gt;maybe you see the same effect if you change the compiler optimization settings? &lt;/p&gt;
&lt;p&gt;I see you have tagged the post with &amp;#39;nRF52833&amp;#39;, can you confirm that this is the chip you are using? I&amp;#39;m asking because if you are using 5283&lt;strong&gt;2&lt;/strong&gt;, you may be impacted by errata 220 as&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/hmolesworth"&gt;hmolesworth&lt;/a&gt;&amp;nbsp;suggested.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
[quote userid="52927" url="~/f/nordic-q-a/75722/wierd-hardfault/314981#314981"]The Hardfault library stack frame snapshot now looks like this:[/quote]
&lt;p&gt;The last byte of the PSR register (&lt;a href="https://developer.arm.com/documentation/dui0552/a/the-cortex-m3-processor/programmers-model/core-registers?lang=en"&gt;Interrupt Program Status Register field&lt;/a&gt;) indicate the ISR number if the program was running in an interrupt context. Since it reads zero it does not appear to have been in an interrupt handler before the fault occurred.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/314986?ContentTypeID=1</link><pubDate>Fri, 11 Jun 2021 19:47:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f98707c4-bab6-44ac-ad7d-ffce0c773a89</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Assuming you haven&amp;#39;t tried the workarounds for the LR corruption bug try this instead of just WFI, maybe insert immediately before the WFI:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if defined(SOFTDEVICE_PRESENT) &amp;amp;&amp;amp;  (NRF_SD_BLE_API_VERSION&amp;gt;=7)
    // Now using sd_app_evt_wait() which has the same workaround; it is softdevice dependant when BLE is used
    sd_app_evt_wait();
#else
    // Errata 220: CPU: RAM is not ready when written - Disable IRQ while using WFE
    // Symptoms - Memory is not written in the first cycle after wake-up
    // Consequences - The address of the next instruction is not written to the stack. In stack frame, the link register is corrupted
    // Workaround
    // ==========
    // Enable SEVONPEND to disable interrupts so the internal events that generate the interrupt cause wakeuup in __WFE context and not in interrupt context
    // Before: ENABLE_WAKEUP_SOURCE -&amp;gt; __WFE -&amp;gt; WAKEUP_SOURCE_ISR -&amp;gt; CONTINUE_FROM_ISR  next line of __WFE
    // After:  ENABLE_WAKEUP_SOURCE -&amp;gt; SEVONPEND -&amp;gt; DISABLE_INTERRUPTS -&amp;gt; __WFE -&amp;gt; WAKEUP inside __WFE -&amp;gt; ENABLE_interrupts -&amp;gt; WAKEUP_SOURCE_ISR
    // Applications must not modify the SEVONPEND flag in the SCR register when running in priority levels higher than 6 (priority level numerical
    // values lower than 6) as this can lead to undefined behavior with SoftDevice enabled
    //
    // Errata 75: MWU: Increased current consumption
    // This has to be handled by turning off MWU but it is used in SoftDevice
    // see https://infocenter.nordicsemi.com/index.jsp?topic=%2Ferrata_nRF52832_EngB%2FERR%2FnRF52832%2FEngineeringB%2Flatest%2Fanomaly_832_75.html
    //
    // Errata 220: Enable SEVONPEND
    SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk;
    __disable_irq();
    // Errata 75: MWU Disable
    uint32_t MWU_AccessWatchMask = NRF_MWU-&amp;gt;REGIONEN &amp;amp; MWU_ACCESS_WATCH_MASK;
    // Handle MNU if any areas are enabled
    if (MWU_AccessWatchMask)
    {
        NRF_MWU-&amp;gt;REGIONENCLR = MWU_AccessWatchMask; // Disable write access watch in region[0] and PREGION[0]
        __WFE();
        __WFE();
        __NOP(); __NOP(); __NOP(); __NOP();
        // Errata 75: MWU Enable
        NRF_MWU-&amp;gt;REGIONENSET = MWU_AccessWatchMask;
    }
    else
    {
        __WFE();
        __WFE();
        __NOP(); __NOP(); __NOP(); __NOP();
    }
    __enable_irq();
#endif
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/314981?ContentTypeID=1</link><pubDate>Fri, 11 Jun 2021 18:00:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e48edaf8-8faf-42f4-8351-bd5272d6a6fd</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Ok, the delay_ms call was a red herring, and obvious in retrospect - that&amp;#39;s being called from the hardfault handler (to flash an LED), so it&amp;#39;s not where the problem is ocurring.&amp;nbsp; Doh.&lt;/p&gt;
&lt;p&gt;Commenting it out made it obvious, as then the PC ends up pointing to the nrf_gpio_pin_* functions, which are setting the LEDs.&amp;nbsp; This also caused the resultant hardfault to change to an IBUSERR instead - the call stack included a call to __WFI(), which is slightly different.&lt;/p&gt;
&lt;p&gt;We do use __WFI() a fair bit to cause the CPU to sleep (and consume less power) when waiting for things to happen.&amp;nbsp; Most timing is provided via an RTC, plus a few external interrupts.&amp;nbsp; As above, we don&amp;#39;t use a softdevice, so it shouldn&amp;#39;t be a problem to call __WFI() directly, but a bit of digging around suggested that the following is better (we do use the FPU):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static inline void sys_sleep (void)
{
#if (__FPU_USED == 1)
  __set_FPSCR(__get_FPSCR() &amp;amp; ~(0x0000009F)); 
  (void) __get_FPSCR();
  NVIC_ClearPendingIRQ(FPU_IRQn);
#endif
  __WFI();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Replacing the WFI calls with that changed the hardfault to an UNDEFINSTR error instead.&amp;nbsp; Looking at the top of the call stack, I now seem to be somewhere in the heap, I think?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/673x977/__key/communityserver-discussions-components-files/4/pastedimage1623432217650v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;So yes, that&amp;#39;s probably not a valid instruction.&amp;nbsp; But how did we end up there in the first place?&amp;nbsp; That particular address happens to be the m_mem_pool long, from the Nordic mem_manager library (which we use to provide pseudo-dynamic memory allocation).&amp;nbsp; Looking through mem_manager.c, I don&amp;#39;t see anything obvious that could turn into a &amp;quot;JMP &amp;amp;m_mem_pool&amp;quot; or similar - it&amp;#39;s a status flags bitmap, so the usage is all setting and checking bits.&lt;/p&gt;
&lt;p&gt;The Hardfault library stack frame snapshot now looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1623433560109v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;with the LR pointing to the WFI instruction in the above sys_sleep code.&amp;nbsp; So it seems to be something to do with the WFI call.&lt;/p&gt;
&lt;p&gt;Does anything in the above jump out at you as obviously suspicious or worth pulling at some more?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/314885?ContentTypeID=1</link><pubDate>Fri, 11 Jun 2021 11:12:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd333a9c-faba-4622-9712-ccec8d6e5b38</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I agree, it doesn&amp;#39;t sound like you have had stack overflow, but the PC value (0xFB04F85C) on stack is clearly invalid, so that must be the reason for the hardfault.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s intereseting that you&amp;#39;re not able to replicate this in debug mode. Have you tried to comment the sleep/idle function in your application to see if that may have the same effect as being in debug mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/314655?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 10:19:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4feea84-90ac-40c5-8f37-63b0096cfd19</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Unfortunately, having any sort of debugger attached while running prevents the hardfault showing up at all, which would tend to suggest some sort of timing issue.&amp;nbsp; Using a UART has the same effect.&amp;nbsp; I can attach to the running chip after the hardfault has happened, to see the state of things, but I can&amp;#39;t watch the fault happen (which also means not getting the debug output).&lt;/p&gt;
&lt;p&gt;The stack frame passed to my HardFault_process function looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/debug_5F00_frame.png" /&gt;&lt;/p&gt;
&lt;p&gt;And the CPU registers (according to Ozone) are:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/b721c9409302c4d35b0f26bc13f70c6c.png" /&gt;&lt;/p&gt;
&lt;p&gt;As the stack guard library uses the MPU, wouldn&amp;#39;t it basically show the same symptom, i.e. an instruction access violation, if the stack was triggered?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve had a go at the old-fashioned &amp;quot;write DEADBEEF to the stack at start-up&amp;quot; method, and that suggests that this code isn&amp;#39;t actually over-running the stack.&amp;nbsp; At the point a hardfault has ocurred, connecting after the fact via Ozone shows that 0x2001E000 is all DEADBEEF still.&amp;nbsp; I&amp;#39;ve also confirmed again via MPU_CTRL that the MPU definitely doesn&amp;#39;t think it&amp;#39;s enabled.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/MPU_5F00_stack.png" /&gt;&lt;/p&gt;
&lt;p&gt;So, all in all, it doesn&amp;#39;t look like stack overflow is the issue here.&amp;nbsp; Which brings us back to a wierd hardfault that doesn&amp;#39;t seem to have any obvious cause, but occurs repeatably.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/314642?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 09:21:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30f03bc7-a642-4a13-aa57-25446beb15f5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Your understanding is correct, the pointer will be set to NULL if there is a stack overflow, but only if there is a stack overflow while the hardfault exception is raised. And a stack overrun doesn&amp;#39;t necessarily trigger a fault immediately (if at all). To catch a stack overflow early you can use the &lt;span&gt;&lt;a title="Stack guard" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_stack_guard.html?cp=8_1_3_51"&gt;Stack guard&lt;/a&gt;&lt;/span&gt; library or try to set a data breakpoint at the bottom of the stack.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Setting data breakpoint in Ozone&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1623316767679v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;Did the hardfault handler print the debug messages? It would be interesting to see the CPU register values that were pushed on stack before the hardfault exception.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/314547?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 16:41:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e5a3f41-8b3c-412d-9a44-00d03ee9f7be</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve pulled in the Nordic hardfault library, which doesn&amp;#39;t seem to point to a stack overrun directly - if I understand correctly, the call to HardFault_process() should pass NULL if it&amp;#39;s a stack overrun, and that doesn&amp;#39;t seem to be happening.&amp;nbsp; I get a valud pointer to a debug stack.&lt;/p&gt;
&lt;p&gt;Some quick calculations: this project has a stack size of 8192 bytes (8k), which given RAM starts at 0x20000000, should give a stack placement of 0x2001E000 to 0x20020000 (128kB RAM).&amp;nbsp; At the point of the hardfault, according to Ozone, the SP (R13) is pointing to 0x2001FF28, which should still be a legal bit of stack.&amp;nbsp; It&amp;#39;s getting close to the edge, mind, which is concerning, but not actually over.&lt;/p&gt;
&lt;p&gt;The pointer the Nordic hardfault library gives me is 0x2001FF80, so a little higher than where Ozone says the SP is, which seems reasonable - I guess it&amp;#39;s pointing a little higher up the call chain.&lt;/p&gt;
&lt;p&gt;Unfortunately, we&amp;#39;re really tight for RAM in this project, hence the 8kB stack.&amp;nbsp; This means I can&amp;#39;t easily bump up the stack to see if the problem goes away.&amp;nbsp; Does this look like stack overrun issues, based on the above, or should we hunt elsewhere?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/313869?ContentTypeID=1</link><pubDate>Mon, 07 Jun 2021 09:59:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:773f80e3-f742-443d-bfd3-74519843b0e8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Alison,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think there is anything that points directly to the FPU at this point, but it may be related (e.g. contribute to a stack overflow). Could you maybe try with our &lt;span&gt;&lt;a title="HardFault handling library" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_hardfault.html?cp=8_1_3_22"&gt;HardFault handling library&lt;/a&gt;&lt;/span&gt; and see if it too points to the same address (i.e. PC value on stack)? The ARM documentation indicates that this fault doesn&amp;#39;t neccessarly require the MPU to be enabled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/313681?ContentTypeID=1</link><pubDate>Fri, 04 Jun 2021 12:51:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2f23084-0878-445f-8c59-cd2c43725224</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;I checked this today, and the MPU is disabled (checking the MPU_CTRL register via Ozone).&amp;nbsp; We&amp;#39;re also not using a softdevice in this project at all, so not that.&amp;nbsp; I&amp;#39;m not directly using the MPU or stack guard libraries.&lt;/p&gt;
&lt;p&gt;Could this be related to FPU operation somehow?&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Alison&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/312800?ContentTypeID=1</link><pubDate>Tue, 01 Jun 2021 09:28:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdfba67d-7b18-40ac-a78f-2f7a51ae2658</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Alison,&lt;/p&gt;
&lt;p&gt;We are only using the MPU in our &lt;span&gt;&lt;a title="MPU driver" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_mpu.html?cp=8_1_3_33"&gt;MPU driver&lt;/a&gt;&lt;/span&gt; and &lt;span&gt;&lt;a title="Stack guard" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_stack_guard.html?cp=8_1_3_51"&gt;Stack guard&lt;/a&gt;&lt;/span&gt; library as far as I&amp;#39;m aware, but I would recommend you check the MPU enable bit in the MPU-&amp;gt;MPU_CTRL&amp;nbsp; register (@ address 0xe000ed94) to be absolutely sure it&amp;#39;s disabled in your project.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;nrfjprog --memrd 0xe000ed94 // Should return 0x0 if MPU is disabled. Should probably be read after the fault exception has occurred too.&lt;/p&gt;
&lt;p&gt;The MWU should not cause the hardfault handler to get invoked. The Softdevice reserves this peripheral for its &lt;span&gt;&lt;a title="Memory isolation and runtime protection" href="https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/sd_mgr/mem_isolation_runtime_protection.html?cp=4_7_4_0_4_3"&gt;Memory isolation and runtime protection&lt;/a&gt;&lt;/span&gt; mechanism which will invoke the SDKs fault handler callback whenever an access violation is detected.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/312715?ContentTypeID=1</link><pubDate>Mon, 31 May 2021 18:13:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73d26361-fadb-4d35-8e93-c439bed51854</guid><dc:creator>alison.lloyd</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Thanks for the article link, I&amp;#39;d actually already run across it (it&amp;#39;s super useful for figuring out the debug).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We are not directly using either the Cortex MPU or the Nordic MWU.&amp;nbsp; Are either of those used by any Nordic libraries or drivers?&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Alison&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wierd hardfault</title><link>https://devzone.nordicsemi.com/thread/312448?ContentTypeID=1</link><pubDate>Fri, 28 May 2021 16:05:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:953a0c24-bb28-4409-a0ec-eecc7af9038d</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Not sure if I have encountered this type of fault before, but I found a blog post that suggests that this error is raised when the CPU attempts to execute code from a memory protected region.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;code&gt;IACCVIOL&lt;/code&gt; - Indicates that an attempt to execute an instruction triggered an MPU or Execute Never (XN) fault. We’ll explore an example &lt;a href="https://interrupt.memfault.com/blog/cortex-m-fault-debug#bad-pc-mpu-fault"&gt;below&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;a href="https://interrupt.memfault.com/blog/cortex-m-fault-debug"&gt;https://interrupt.memfault.com/blog/cortex-m-fault-debug&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Could this be it, or are you not using the MPU in your project?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>