<?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>Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/116408/unresponsive-device-when-flashing-after-disabling-appprotect</link><description>Hi, 
 I&amp;#39;m developing on the current setup: 
 
 nRF52840 
 Soft Device 140 version 7.2.0 
 SDK 17.1.0 
 MDK: 8.51 
 Segger v4.52c 
 Secure bootloader (DFU) 
 
 I don&amp;#39;t define ENABLE_APPROTECT in the preprocessor and I&amp;#39;ve followed this guide: Working with</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 18 Nov 2024 15:48:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/116408/unresponsive-device-when-flashing-after-disabling-appprotect" /><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510933?ContentTypeID=1</link><pubDate>Mon, 18 Nov 2024 15:48:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8352c26b-6392-4cd4-997a-3107ad8e5f50</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Oh ok I think that explains 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: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510913?ContentTypeID=1</link><pubDate>Mon, 18 Nov 2024 14:18:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69dfc7a9-18af-4d4d-bdf8-a895ab4f7778</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The bootloader code always executes before the main application. The boot sequence is: MBR -&amp;gt; Bootloader -&amp;gt; SoftDevice -&amp;gt; Application. This means that the APPROTECT will be locked if a debugger attaches to the target after a reset, but before the bootloader branches to the main application.&lt;/p&gt;
[quote user="Federico"]This would suggest that the bootloader.hex code is running before flashing the app.hex file? Like in-between Additional Loads.[/quote]
&lt;p&gt;The CPU is halted while the images are loaded. Execution&amp;nbsp;is started after all hex files have been programmed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510883?ContentTypeID=1</link><pubDate>Mon, 18 Nov 2024 12:48:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17644830-2d8c-4d11-9b7d-a7310843cbb0</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Hi Vidar, yes I can confirm that by disabling the &amp;quot;bootloader.hex&amp;quot; Additional Load, it works fine. But we do need to load it.Based on what you said, I modified the bootloader project to run&amp;nbsp;&lt;span&gt;approtect_disable in main and now the issue seems to be gone.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This would suggest that the bootloader.hex code is running before flashing the app.hex file? Like in-between Additional Loads. Does that make sense? I&amp;#39;m still not sure I understood everything.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510841?ContentTypeID=1</link><pubDate>Mon, 18 Nov 2024 08:25:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd2c75cd-715b-4209-b22c-f1e159c22786</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks for the summary. The UICR will be cleared every time the bootloader FW is loaded. As a result the, the APPROTECT mechansim will not become unlocked until the program reaches&amp;nbsp;the&amp;nbsp;approtect_disable() call in app main().&amp;nbsp;To confirm this, you can remove the bootloader hex from the &amp;quot;&lt;span&gt;Additional Load&amp;quot; field.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510734?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 14:31:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11548c80-9f4d-4bac-bbf1-b298cd4eb527</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;The short answer is that it only reaches that point after a recover, and the value is actually 0x5A. If I try to flash again, it will not even reach main, it gets stuck somewhere else.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think I haven&amp;#39;t explained myself clearly. I&amp;#39;ll try to put a detailed sequence here:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nrfjprog --recover&lt;/li&gt;
&lt;li&gt;Download &amp;amp; debug from segger.&amp;nbsp;Segger is configured to &amp;quot;Additional Load&amp;quot; other hex files, which are the soft device, Bootloader and dfu settings, in that order.&lt;/li&gt;
&lt;li&gt;This reaches main and executes without issues.&lt;/li&gt;
&lt;li&gt;Goes through the approtect_disable function and leaves NRF_APPROTECT-&amp;gt;DISABLE in 0x5A and NRF_UICR-&amp;gt;APPROTECT in 0xFF.&lt;/li&gt;
&lt;li&gt;Debugger works too, even through device resets.&lt;/li&gt;
&lt;li&gt;Stop debugging session&lt;/li&gt;
&lt;li&gt;Download &amp;amp; Debug again (no prompt to recover)&lt;/li&gt;
&lt;li&gt;Now the execution never reaches main, it&amp;#39;s stuck somewhere that appears invalid code, as I showed in the original post.&lt;/li&gt;
&lt;li&gt;&lt;span&gt;FORCEPROTECT shows as 1 (0x40000550)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;NRF_APPROTECT-&amp;gt;DISABLE shows as 1 (0x40000558)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;NRF_UICR-&amp;gt;APPROTECT shows as 0xFF (0x10001208)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Stop debugging session&lt;/li&gt;
&lt;li&gt;Download and Debug again. This prompts for a recovery, press OK and now it works.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So, it seems to be working every other time. I was under the impression that I could only make it work again with &amp;quot;nrfjprog --recover&amp;quot;, but now Segger is prompting me for recovery so it seems to work. Not sure what changed.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510698?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 13:19:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5dc459d2-797c-4734-804d-4eb6711ac48c</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It should be set to 0x5a after the approtect_disable() function has been executed. Can you place a breakpoint after this function call to confirm?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510696?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 13:16:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2a3eb02-eaac-4993-a971-0e39428aa8fe</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Sorry I posted the wrong register. Here&amp;#39;s the right one, I hope. 0x10001208 is set to 0xFF. What does this mean?&lt;br /&gt;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731676510540v1.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510694?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 13:11:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e27f36c-dbef-409a-adbc-308bea30fda2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The problem is the&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/uicr.html#register.APPROTECT"&gt;UICR.APPROTECT&lt;/a&gt;&lt;span&gt;&amp;nbsp;register @ 0x10001208. The programmer will erase the UICR section before writing&amp;nbsp;to&amp;nbsp;0x10001014 and&amp;nbsp;&amp;nbsp;0x10001018 when loading the bootloader image. However, the code snippet you posted should take care of this. Can you check if the&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/uicr.html#register.APPROTECT"&gt;UICR.APPROTECT&lt;/a&gt;&amp;nbsp;is 0x5a?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510689?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 13:04:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fec98fb-f7f3-4229-8d67-51549cba1e0c</guid><dc:creator>Federico</dc:creator><description>&lt;p&gt;Hi Vidar, thanks for the answer.&lt;/p&gt;
&lt;p&gt;At that point, the register window in Segger shows this:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731673725366v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t fully understand your logic regarding the bootloader overwriting the &lt;span&gt;NRF_APPROTECT-&amp;gt;DISABLE. Wouldn&amp;#39;t it happen too in this sequence?:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;nrfjprog --recover&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;download &amp;amp; debug from segger&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;Load soft device&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;load dfu settings&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;load bootloader&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;load app&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;If the bootloader overwritting&amp;nbsp;&lt;span&gt;NRF_APPROTECT-&amp;gt;DISABLE is the issue, can I modify the bootloader project to have the 0x5A be part of the hex file that is being burned? I see the hex file includes contents for&amp;nbsp;0x10001014 and 10001018, but I couldn&amp;#39;t find in the code where this is defined.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unresponsive device when flashing after disabling APPPROTECT</title><link>https://devzone.nordicsemi.com/thread/510674?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2024 12:09:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b0fd9ce-730f-4db4-a202-f25149cd576b</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The nrfjprog --recover procedure differs from the JLink unsecuring procedure in that it will also write 0x5A to the &lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/uicr.html#register.APPROTECT"&gt;UICR.APPROTECT&lt;/a&gt; register and load a small FW image that will unlock approtect in SW (i.e. write 0x5A to the NV&amp;nbsp;NRF_APPROTECT-&amp;gt;DISABLE register) after the ERASEALL.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The problem is that the bootloader includes data in the UICR region (@0x10001014 and 10001018) which causes the UICR section to be erased when you program the bootloader image. This means the&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/uicr.html#register.APPROTECT"&gt;UICR.APPROTECT&lt;/a&gt;&amp;nbsp;will be set to &amp;#39;0xff&amp;#39; again, causing 0xFF to be written to&amp;nbsp;&lt;span&gt;NRF_APPROTECT-&amp;gt;DISABLE in your startup code before reaching main().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731672244701v1.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1731672376470v2.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/dif.html"&gt;https://docs.nordicsemi.com/bundle/ps_nrf52840/page/dif.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]After including this code, I no longer get the message and traces keep working even after a reset. However, if I try to download &amp;amp; debug again, the code doesn&amp;#39;t run and the uC seems to be stuck at a random location:[/quote]
&lt;p&gt;Are you able to read out the&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/uicr.html#register.APPROTECT"&gt;UICR.APPROTECT&lt;/a&gt;&amp;nbsp;register at this point?&amp;nbsp;&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>