<?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 distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27014/how-can-i-distinguish-the-reason-for-hardfault</link><description>Using SDK 7.2 and S110 7.1 
 
 
 IDE : IAR 7.1 
 
 
 Board : PCA10001 (Revision 2 MCU) 
 
 
 Hi, regardless of the example, when I add some codes of my own, 
 there are some cases when the firmware falls into HardFault_Handler 
 (or other Handlers</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 Jul 2015 08:53:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27014/how-can-i-distinguish-the-reason-for-hardfault" /><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105984?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2015 08:53:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc07b6ab-1705-4e70-bab6-353216dfd2bf</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;ARMs documentation is awesome, but it&amp;#39;s very, very, very, VERY long. All this stuff is in the ARM V6M Reference, which is 600 pages long, the V7 one is 1100 pages long. There&amp;#39;s a couple of books, The Definitive Guide to The ARM Cortex M0 (and M3, M4 etc) which are pretty good if you want to get a good understanding, then you can dip into the manual later for the details. Mostly you don&amp;#39;t need to know it however.&lt;/p&gt;
&lt;p&gt;ARM also has their infocenter which has the same stuff, but indexed and with a few pretty diagrams, probably as part of a similar but different target user manual (the generic user guide). The stack picture is here &lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/Babefdjc.html"&gt;infocenter.arm.com/.../index.jsp&lt;/a&gt;, the PSP register details are elsewhere, you can piece it slowly together.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105982?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2015 08:39:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88401bc5-90b2-442d-a7ef-0f716ded50c4</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Wow, it sure is painful...&lt;/p&gt;
&lt;p&gt;I should have read both your answer and the &lt;a href="http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/DUI0497A_cortex_m0_r0p0_generic_ug.pdf"&gt;Cortex M0 manuscript &lt;/a&gt;from ARM more carefully,&lt;/p&gt;
&lt;p&gt;but where did you get these infos?&lt;/p&gt;
&lt;p&gt;Like &lt;code&gt;The word after the PC, that&amp;#39;s the PSP&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;, &lt;code&gt;R1 is also stacked by the interrupt routine at SP&lt;/code&gt;,&lt;/p&gt;
&lt;p&gt;and &lt;code&gt;an unaligned load&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;I lack of many basic knowledge of Cortex M0 architecture.&lt;/p&gt;
&lt;p&gt;So I was curious that where did you received all these infos.&lt;/p&gt;
&lt;p&gt;Also, about the unaligned load, you mean the code loaded from R0 + 0x04 was not even, right?&lt;/p&gt;
&lt;p&gt;Always appreciate your help and nice guess.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105983?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2015 08:32:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32e643c6-bb90-47a4-8be5-e03d4afcf242</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Well I tried :).&lt;/p&gt;
&lt;p&gt;Ok you can see why that crashes, r0 is 0x00000001 (that&amp;#39;s also stacked by the interrupt routine at 0x200032D0) and 0x00000001 + 4 == 0x00000005 and that&amp;#39;s an unaligned load. On the nRF52 that would have given you a better fault AND a nice error code, except it wouldn&amp;#39;t have as that allows unaligned loads unless you turn that off.&lt;/p&gt;
&lt;p&gt;So now you just have to work out why the head timer isn&amp;#39;t TIMER_NULL but the timer table contains totally bogus addresses like 0x00000001. That shouldn&amp;#39;t be too hard.&lt;/p&gt;
&lt;p&gt;And now you know how to track 2-level deep stacked interrupts. Painful isn&amp;#39;t it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105979?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2015 06:46:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:baba7d16-a3f0-4c5b-b0c5-7de0f39a15d6</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;edited.. thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105980?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2015 06:24:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c4c2aab-c241-4eb2-b275-0d6aa6d72df4</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;[ 0x200032D0 + 0x18 ] .. I think&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105981?ContentTypeID=1</link><pubDate>Thu, 23 Jul 2015 06:23:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4c02e4b-1517-47ae-9220-844b01b59910</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Doing it as an answer even though it&amp;#39;s not because the comments are restricted to about 2 lines!&lt;/p&gt;
&lt;p&gt;01 00 00 00 in little endian is neither of the above, it&amp;#39;s 0x00000001. Anyway that&amp;#39;s not where you came from.&lt;/p&gt;
&lt;p&gt;SP is 0x200032D0, so the return PC at exception time is stacked at that +0x18 = 0x200032E8 which has contents 0x00019b5a.&lt;/p&gt;
&lt;p&gt;The link register is 0xFFFFFFF1 which means return to handler, which means you hardfaulted inside an interrupt handler .. but which one.&lt;/p&gt;
&lt;p&gt;The word after the PC is at 0x200032EC and is 0x01000021, that&amp;#39;s the PSP. Bit 24 is set telling you you came from Thumb mode, well we knew that. The lower 5 bits are 0x21 which is 33 which is the number of the interrupt being processed. Interrupts start at &amp;#39;1&amp;#39; for the reset handler, the first user interrupt is 16 so this is user interrupt ( 33 - 16 ) = 17. Interrupt 17 is RTC1.&lt;/p&gt;
&lt;p&gt;So it looks like there was something which caused a hardfault inside some code called by the RTC1 interrupt handler (ie I guess a timer) the instruction causing the fault was at 0x00019b5a.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll hazard a wild guess that instruction turns out to be SVC .. see if I&amp;#39;m right.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105978?ContentTypeID=1</link><pubDate>Wed, 22 Jul 2015 09:46:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d160e25-29d3-4b2b-9c0a-66c67b9cd8b3</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;No, you have to look what inside the memory location of where SP is pointing to.
That is check the memory contents of 0X200032D0, to the contents add 0X18 (add to the contents of memory location pointed by SP)
You just added 0X200032D0+0X18 &amp;lt;-- This is wrong
you must do [0X200032D0 + 0X18], then you will get the instruction address that caused the hardfault.
you can check where this instruction lies my checking the .map file generated in _build folder&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105977?ContentTypeID=1</link><pubDate>Wed, 22 Jul 2015 09:05:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4124142d-0231-44fd-98e2-9750cc7ef4b1</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Using the picture where it shows the registers,&lt;/p&gt;
&lt;p&gt;then at Memory 0x20032E8, there&amp;#39;s the instruction that caused the exception?&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t tried it but won&amp;#39;t there be similar instructions?&lt;/p&gt;
&lt;p&gt;For instance, if the instruction was &amp;quot;MOV&amp;quot; at 0x20032E8,&lt;/p&gt;
&lt;p&gt;how could I found that instruction&amp;#39;s location?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I distinguish the reason for hardfault?</title><link>https://devzone.nordicsemi.com/thread/105976?ContentTypeID=1</link><pubDate>Wed, 22 Jul 2015 07:19:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6f422ba-b50a-4af3-a304-876f509d1c65</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;One way to do it is like this.&lt;/p&gt;
&lt;p&gt;Check this
&lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/Babefdjc.html"&gt;infocenter.arm.com/.../index.jsp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can see that on Cortex-M0, on Exception entry (like Hardfault) the address of instruction that caused the exception is pushed onto stack at SP+0X18.
You can check the symbol table, .map file,  and find out which function caused it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>