<?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>Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck</link><description>Hi, 
 Once in a while, the Serial DFU stuck in flash erase. Did I do something wrong? 
 Background: Currently I am unable to put breakpoint in the Bootloader component that I imported from SDK 15.3.0, but it&amp;#39;s a separate issue that I posted in a separate</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 25 Jun 2020 22:28:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck" /><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/257022?ContentTypeID=1</link><pubDate>Thu, 25 Jun 2020 22:28:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:139e5ef0-73ae-42d6-81d0-d577c841e36d</guid><dc:creator>Harry</dc:creator><description>&lt;p&gt;Thanks Vidar. Btw, I&amp;#39;m running it on a custom board, not dev kit.&lt;/p&gt;
&lt;p&gt;Also, I found that it&amp;#39;s been running fine from debugger. So, my breakpoints are pointless. Now I have to go back to debugging using debug messages.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256827?ContentTypeID=1</link><pubDate>Thu, 25 Jun 2020 08:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a26ca34-8d52-4471-af2b-0741857124a8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I&amp;#39;m glad to hear that you found it helpful, thanks. I can try to debug this on my side as well if the project can be run on a Nordic dev kit without external dependencies.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256786?ContentTypeID=1</link><pubDate>Wed, 24 Jun 2020 23:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61c4335e-ccea-4b00-afc5-371bdb4ab608</guid><dc:creator>Harry</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Thank you so much for all your help. I&amp;#39;ll mark your last reply as the answer. I hope I&amp;#39;ll find the root cause soon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256727?ContentTypeID=1</link><pubDate>Wed, 24 Jun 2020 13:58:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c03a19ae-0558-4f03-8934-63f3fde567c5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Serene_Guy"]I am not quite sure regarding the difference. Btw, I run it using the debugger, on both register readouts. I captured the screenshot first actually, from Keil IDE. And then I used nrfjprog.[/quote]
&lt;p&gt;There is no valid application to boot according to the RTT log, which is why I&amp;#39;m not expecting the CPU to execute code from the application region as the register readout shows. The registers must be read while the bootloader is stuck. Any unintentional reset before doing the readout will likely be enough to recover the device back into a normal state. Anyway, I think we can move on from this troubleshooting step now as you have managed to resolve the issue with the breakpoints.&lt;/p&gt;
[quote user="Serene_Guy"]Thanks for your suggestion, I added HardFault library, now I saw it stopped at the Bootloader, not in MBR anymore. Please see the register readout below:[/quote]
&lt;p&gt;To be sure the correct hard fault handler is included, please make sure hardfault_handler_keil.c and hardfault_implementation.c are both included in the build and also enabled in sdk_config ( the handler should not appear greyed out in the Keil editor).&amp;nbsp; Once this is done you can place a breakpoint at the end of HardFault_c_handler() and see if you can replicate the problem where the bootloader gets stuck after a flash erase. I&amp;#39;m still suspecting it&amp;#39;s a hard fault. I hope is that the HardFault_c_handler() will log more information about what&amp;#39;s triggering the fault exception.&lt;/p&gt;
[quote user="Serene_Guy"]Are you saying if it&amp;#39;s pre-compiled, then I won&amp;#39;t be able to set breakpoint?[/quote]
&lt;p&gt;I haven&amp;#39;t tried it myself, but I think it should be possible. I guess one potential problem is that a pre-compile library may use different source paths, though it should be possible to edit those in Keil.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256560?ContentTypeID=1</link><pubDate>Wed, 24 Jun 2020 04:58:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:763210c9-1e1b-4b72-bd07-e597fb49880a</guid><dc:creator>Harry</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck/256370"]Maybe the device has gone into a boot loop, and the program just happened to be inside the MBR when you ran --readregs? Or does the device seem to recover if you perform a reset after getting stuck?[/quote]
&lt;p&gt;I am not quite sure regarding the difference. Btw, I run it using the debugger, on both register readouts. I captured the screenshot first actually, from Keil IDE. And then I used nrfjprog.&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck/256370"]I&amp;#39;m also wondering if you have defined your own Hardfault handler in your bootloader? The weakly declared hardfault in arm_startup_nrf52840.s will make the program hang until it&amp;#39;s reset. Either way, it can be very helpful to use the SDK&amp;#39;s &lt;span class="item"&gt;&lt;a title="HardFault handling library" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/lib_hardfault.html?cp=7_1_3_22"&gt;HardFault handling library &lt;/a&gt;&lt;/span&gt;&lt;span class="item"&gt;to find out what triggered the exception.&lt;/span&gt;[/quote]
&lt;p&gt;Thanks for your suggestion, I added HardFault library, now I saw it stopped at the Bootloader, not in MBR anymore. Please see the register readout below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;R0:   0x00008DF4
R1:   0x40002000
R2:   0x00000008
R3:   0x2000A85A
R4:   0x00000001
R5:   0x000003E8
R6:   0x0000FA00
R7:   0x000E3FF1
R8:   0x00000000
R9:   0x00000000
R10:  0x000E4D5C
R11:  0x00000000
R12:  0x80000000
SP:   0x2002B7E0
LR:   0x000DC3EF
PC:   0x000E3FF0
xPSR: 0x21000000
MSP:  0x2002B7E0
PSP:  0x00000000&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck/256370"]Does the main project enable debug information for the output file as shown below? This is one thing that could explain why you&amp;#39;re unable to place breakpoints[/quote]
&lt;p&gt;Yes, I already checked that. Btw, I found that after merging the Keil uVision project (from the Bootloader example and mine), I can set breakpoints now. The other problem I have is, the error is different when I run it from debugger vs. freerun. I still need to rely on debug messages to find the root cause.&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck/256370"]So just for my understanding, and please correct me if I&amp;#39;m wrong, but it sounds like in your case that the bootloader components are being pre-compiled into a library and then imported to another existing Keil project?[/quote]
&lt;p&gt;You are absolutely correct. I have a thin layer of application (handshaking) and then it calls the Bootloader SDK. SO, the Bootloader SDK is part of the project.&lt;/p&gt;
&lt;p&gt;Regarding pre-compiled, I don&amp;#39;t think so. I inherited this project from another team member, and as far as I can tell, the make file includes the source code (*.c files) as well as the library path, and refer to those libraries as *.ext files. Does it mean it&amp;#39;s pre-compiled? My understanding is if it&amp;#39;s pre-compiled, then they will be in *.a files format. (I&amp;#39;m not super familiar with Nordic yet).&lt;/p&gt;
&lt;p&gt;Are you saying if it&amp;#39;s pre-compiled, then I won&amp;#39;t be able to set breakpoint?&lt;/p&gt;
&lt;p&gt;P.S.: The MBR I used is version 2.4.1. The SDK is 15.3.0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256370?ContentTypeID=1</link><pubDate>Tue, 23 Jun 2020 09:58:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e7f7bbe-515a-4396-93eb-e72b11286444</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the updates. The first register readout shows the program being in the Hardfault interrupt context somewhere inside the MBR. So something is causing a fault exception to occur during DFU. Although I&amp;#39;m a bit surprised to see that the program counter (PC) is inside the MBRs memory range as all interrupts shall be forwarded to the bootlaoder. Maybe the device has gone into a boot loop, and the program just happened to be inside the MBR when you ran --readregs? Or does the device seem to recover if you perform a reset after getting stuck?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m also wondering if you have defined your own Hardfault handler in your bootloader? The weakly declared hardfault in arm_startup_nrf52840.s will make the program hang until it&amp;#39;s reset. Either way, it can be very helpful to use the SDK&amp;#39;s &lt;span class="item"&gt;&lt;a title="HardFault handling library" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/lib_hardfault.html?cp=7_1_3_22"&gt;HardFault handling library &lt;/a&gt;&lt;/span&gt;&lt;span class="item"&gt;to find out what triggered the exception.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As for the second readout from Keil, it appears to be taken while the CPU executes code from the main application. It&amp;#39;s not inside any interrupt context either. Could it be that it&amp;#39;s different because Keil, by default, re-loads the app image resets the target when attaching the debugger?&lt;/p&gt;
[quote userid="90336" url="~/f/nordic-q-a/62855/serial-dfu-flash-erase-stuck/256273"]A separate update, regarding setting the breakpoints on Bootloader components from SDK, I added the reference to the libraries, I can put breakpoint but only before I start debugging. It seems to hit them, but they&amp;#39;re not visible (no red dot - only yellow arrow). Please see the screenshot below from Keil uVision:[/quote]
&lt;p&gt;Does the main project enable debug information for the output file as shown below? This is one thing that could explain why you&amp;#39;re unable to place breakpoints.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1592905442009v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;The bootloader is usually built using the project files provided by the SDK. So just for my understanding, and please correct me if I&amp;#39;m wrong, but it sounds like in your case that the bootloader components are being pre-compiled into a library and then imported to another existing Keil project?&lt;/p&gt;
&lt;p&gt;&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: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256273?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2020 17:12:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:413bdcf6-9908-4bfb-b963-6aff78b64210</guid><dc:creator>Harry</dc:creator><description>&lt;p&gt;Hi Vidar, the IDE/toolchain that I used is Keil uVision.&lt;/p&gt;
&lt;p&gt;Btw, a side note, I put the Bootloader at address 0xD6000, and I have MBR.&lt;/p&gt;
&lt;p&gt;I noticed that some registers are different, comparing the values I got from nrfjprog and from Keil IDE. I run it via J-Link. Or perhaps do I need to run it without J-Link?&lt;/p&gt;
&lt;p&gt;Please find below is the CPU register readout, as well as the screenshot from:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;R0:   0x00000000
R1:   0x20002774
R2:   0x00000040
R3:   0x0000B635
R4:   0x200257D4
R5:   0x00000040
R6:   0x0000006E
R7:   0x00000000
R8:   0x20002774
R9:   0x00000000
R10:  0x200257D4
R11:  0x00000000
R12:  0x00000000
SP:   0x20025670
LR:   0xFFFFFFE9
PC:   0x000003CE
xPSR: 0x61000003
MSP:  0x20025670
PSP:  0x00000000&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x800/__key/communityserver-discussions-components-files/4/2020_2D00_06_2D00_22_5F00_10_2D00_47_2D00_29.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;A separate update, regarding setting the breakpoints on Bootloader components from SDK, I added the reference to the libraries, I can put breakpoint but only before I start debugging. It seems to hit them, but they&amp;#39;re not visible (no red dot - only yellow arrow). Please see the screenshot below from Keil uVision:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/0601.2020_2D00_06_2D00_22_5F00_17_2D00_50_2D00_24.jpg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Serial DFU Flash erase stuck</title><link>https://devzone.nordicsemi.com/thread/256107?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2020 07:46:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:732469f7-b313-49a1-a019-809ef00a60b7</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;This is not a known issue, but I suspect it may have something to do with the integration or implementation of the bootloader since it doesn&amp;#39;t fail consistently every time. As a start, please run &amp;#39;nrfjprog --readregs&amp;#39; to get a CPU register readout when it&amp;#39;s stuck and post the result here. Or look up the PC value to find out where in the program it gets stuck.&lt;/p&gt;
[quote user=""]Background: Currently I am unable to put breakpoint in the Bootloader component that I imported from SDK 15.3.0, but it&amp;#39;s a separate issue that I posted in a separate post. So, I can only do black-box debugging with debug messages for now.[/quote]
&lt;p&gt;&amp;nbsp;This is often a sign of missing debug symbols in the output executable (*.elf, *.out,..). Which IDE/toolchain are you using to build the bootloader?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>