<?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 without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24113/hardfault-without-debugger---simple-toggle-io-program</link><description>Hi guys, 
 I&amp;#39;m trying to start with a simple IO toggle program on the nRF52 on a Thingy52 board. I have erased the micro so there is no soft device. I&amp;#39;m working in Eclipse Neon 3 using ARM Cross Compiler plugin. 
 #include &amp;quot;nrf.h&amp;quot; 
#include &amp;quot;nrf_delay</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Aug 2017 00:35:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24113/hardfault-without-debugger---simple-toggle-io-program" /><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94942?ContentTypeID=1</link><pubDate>Wed, 09 Aug 2017 00:35:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d8018db-efdf-4971-8cd5-ff86bbedbe8a</guid><dc:creator>SParker</dc:creator><description>&lt;p&gt;I copied my program into the evaluation version of Keil and it just worked. I might try another GCC version at a later date.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94946?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 04:38:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d31dd77b-87f2-4c82-9451-d3efe303ee3f</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;so why is the memory at 0x20000000 + 328 zero-filled when you&amp;#39;re using the debugger but not later? There should be a piece of code in crt0 which zero-fills the .bss segment. If you hit the reset handler and it&amp;#39;s already zero-filled, then the debugger is doing it (check by setting it to something and re-debugging).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94945?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 04:26:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54e6115c-1d63-4bc8-a905-467337953ead</guid><dc:creator>SParker</dc:creator><description>&lt;p&gt;00000544:   ldr     r3, [pc, #164]  ; (0x5ec &amp;lt;__register_exitproc+188&amp;gt;)
Load from 0x5ec into r3 =&amp;gt; r3 = 0xd24
00000546:   ldr     r4, [r3, #0]
Load from 0xd24 into r4 =&amp;gt; r4 = 0x2000000
00000548:   ldr.w   r3, [r4, #328]  ; 0x148
Load from 0x2000000+328 into r3 =&amp;gt; r3 = 0
0000054c:   cmp     r3, #0
Compare is true
0000054e:   beq.n   0x5ce &amp;lt;__register_exitproc+158&amp;gt;
Take branch which populates r3 with 0x2000014c&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94944?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 04:02:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42b52472-be63-4c04-8d37-c9c045065a13</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I&amp;#39;m pretty out of new ideas here. I assume those &amp;#39;correct&amp;#39; values are loaded via that sequence I detailed above, load from 0x5ec, add 328, load from there. I can&amp;#39;t at this point suggest why the debugger or lack thereof makes a difference. Guess you have to go all the way back to the reset_handler, set the locations to something invalid, find what writes them (with memory access breakpoints).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94943?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 03:59:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9754c541-2ff4-4229-b944-c48cf79fc441</guid><dc:creator>SParker</dc:creator><description>&lt;p&gt;Using the debugger when it gets to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;00000550:   ldr     r2, [r3, #4]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;r0 = 536872028 = 0x2000 045C,
r3 = 536871244 = 0x2000 014C&lt;/p&gt;
&lt;p&gt;These are valid areas in RAM. Without the debugger r0 and r3 become invalid.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94937?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 02:46:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a64abef-3ec0-4126-81fb-a08efbd6399f</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;well go stick a breakpoint there and see what happens when you DO run under the debugger, perhaps that will hint what&amp;#39;s going on. If it were a different debugger (like Segger Embedded or something) I&amp;#39;d suggest that perhaps it wasn&amp;#39;t going from the reset handler and was doing something odd, but I&amp;#39;m reasonably sure gdb via gdbserver is pretty plain vanilla.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94947?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 01:46:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68fd7ea5-80c3-44e3-8a53-ebd8f98db848</guid><dc:creator>SParker</dc:creator><description>&lt;p&gt;Yeah, thanks for taking a look! I might have to compare my compiler stuff with different example code. It&amp;#39;s gotta be something...
FYI 0x02AE is inside _start as a call to __libc_init_array&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve also tried changing to newlib-nano and have exactly the same symptoms and still crashes inside __libc_init_array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94939?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 01:14:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d2829c1-b74c-4007-800d-179c190a508d</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;ok there&amp;#39;s more to it then. Firstly I was wrong, hardfault is a precise fault so 0x0550 is the instruction which was executing (not the return-to address). So you were doing &lt;code&gt;ldr r2, [r3,#4]&lt;/code&gt;. No shock that faulted, r3 is 0xbb7dfffb which is rubbish.&lt;/p&gt;
&lt;p&gt;So r3 was loaded with (I think) 0x5ec. , r4 was loaded from that address, r3 was loaded from r4 + 328 and that was probably 0xbb7dfffb and that&amp;#39;s not zero so the branch wasn&amp;#39;t taken and then you HF at 0x0550 trying to load from that address + 4.&lt;/p&gt;
&lt;p&gt;At this point, that&amp;#39;s all I can tell.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94938?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 00:58:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54198d7f-05d2-42b8-b869-729b772a2504</guid><dc:creator>SParker</dc:creator><description>&lt;p&gt;The code around here is c library code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;          __register_exitproc:
00000530:   stmdb   sp!, {r3, r4, r5, r6, r7, r8, r9, lr}
00000534:   ldr     r5, [pc, #176]  ; (0x5e8 &amp;lt;__register_exitproc+184&amp;gt;)
00000536:   mov     r6, r0
00000538:   ldr     r0, [r5, #0]
0000053a:   mov     r8, r3
0000053c:   mov     r7, r1
0000053e:   mov     r9, r2
00000540:   bl      0x528 &amp;lt;__retarget_lock_acquire_recursive&amp;gt;
00000544:   ldr     r3, [pc, #164]  ; (0x5ec &amp;lt;__register_exitproc+188&amp;gt;)
00000546:   ldr     r4, [r3, #0]
00000548:   ldr.w   r3, [r4, #328]  ; 0x148
0000054c:   cmp     r3, #0
0000054e:   beq.n   0x5ce &amp;lt;__register_exitproc+158&amp;gt;
00000550:   ldr     r2, [r3, #4]
00000552:   cmp     r2, #31
00000554:   bgt.n   0x590 &amp;lt;__register_exitproc+96&amp;gt;
00000556:   add.w   lr, r2, #1
0000055a:   cbz     r6, 0x57a &amp;lt;__register_exitproc+74&amp;gt;
0000055c:   add.w   r1, r3, r2, lsl #2
00000560:   movs    r4, #1
00000562:   str.w   r9, [r1, #136]  ; 0x88
00000566:   ldr.w   r0, [r3, #392]  ; 0x188
0000056a:   lsls    r4, r2
0000056c:   orrs    r0, r4
0000056e:   cmp     r6, #2
00000570:   str.w   r0, [r3, #392]  ; 0x188
00000574:   str.w   r8, [r1, #264]  ; 0x108
00000578:   beq.n   0x5c2 &amp;lt;__register_exitproc+146&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The application ends at 0x0D32, above that is blank flash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94941?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 00:20:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18db0455-c57d-4013-8b3c-0704f0ca7606</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;let&amp;#39;s see what we can pick out of here. An exception was taken and stacked. R0, R1, R2, R3, R12 are unchanged from their stacked values, expected, the HF handler does nothing. LR is 0xFFFFFFF9 which is a standard return from exception. The stack has the return to PC and also the LR at the time of the exception. PC is 0x0550, LR was 0x0545. So likely scenario is a branch to a routine which returned to 0x5045 (0x5044 really as that odd bit just denotes thumb), then ran to the instruction before 0x0550 (probably 0x054E) and then hardfaulted.&lt;/p&gt;
&lt;p&gt;So what code&amp;#39;s around 0x0540 onwards for 16 or so bytes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94936?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2017 23:28:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bfcab70-dbeb-4caa-9035-6bb16b89e9d7</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;no _0xFFFFFFF9 is just an exception return marker - nothing wrong with that at all. I&amp;#39;ll have a look at the rest later.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94935?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2017 23:23:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:167883a5-9f6c-4dc3-b1b4-33bc0671da3e</guid><dc:creator>SParker</dc:creator><description>&lt;p&gt;Here are the CPU registers during the fault, the stack pointer looks OK to me. Trying to execute something at 0xFFFFFFFF9 looks bad though!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;r0	4063042862	
r1	1269	
r2	0	
r3	3145596923	
r4	536870912	
r5	536871976	
r6	0	
r7	1269	
r8	0	
r9	0	
r10	536870912	
r11	0	
r12	0	
sp	0x2000ffc0	
lr	4294967289	
pc	0x61e &amp;lt;HardFault_Handler&amp;gt;	
xpsr	2701131779	
msp	536936384	
psp	0	
primask	0	
basepri	0	
faultmask	0	
control	0	
fpscr	0
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94934?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2017 21:15:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:198dd32f-bd48-479f-8405-06013dbe9765</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Can we get a register dump after you get to hardfault? Knowing where the SP is would be helpful for one. That stack trace looks as if the first call (ie first branch link) has stacked the return address, done the work and then returned to nowhere and faulted. The most likely cause of that is a stack pointer not initialised correctly on startup without the debugger.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Hardfault without debugger - simple toggle IO program</title><link>https://devzone.nordicsemi.com/thread/94940?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2017 12:58:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a78f7221-ecc5-4cfb-ba79-1cd277bd5652</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Show us the &lt;code&gt;blinky_gcc_nrf52.ld&lt;/code&gt; file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>