<?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>Implications of turning off read access</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108564/implications-of-turning-off-read-access</link><description>Using nRF52840 and SES with SDK 15.3.. I&amp;#39;ve got this speaking BLE and it has a bootloader on it so 4 sections of memory being used (the 4th is the section the softdevice uses to keep track of connection information). 
 In this post devzone.nordicsemi</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 Feb 2024 15:12:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108564/implications-of-turning-off-read-access" /><item><title>RE: Implications of turning off read access</title><link>https://devzone.nordicsemi.com/thread/470799?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 15:12:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a5e1b70-1cc4-4492-98fa-bb0afde6f273</guid><dc:creator>Randy Lee</dc:creator><description>&lt;p&gt;Beauty... That looks like that got it. Once I come back from the reset, the debugger is lost and I can&amp;#39;t get it to work like that again till I reflash the part (F5)&amp;nbsp; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implications of turning off read access</title><link>https://devzone.nordicsemi.com/thread/470637?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 08:57:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bc0629b-37f0-4a1d-b922-73334bbf5b91</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Yes. Perhaps I was a bit fast.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You will still be able to debug after enabling APPROTECT, but only until the next reboot. I don&amp;#39;t remember if you need to power cycle, or just a reset. You can experiment with this.&amp;nbsp;&lt;/p&gt;
[quote user="Randy Lee"]I get an infinite loop, at least doing debug and the register is always reading as 0xFFFFFFFF[/quote]
&lt;p&gt;I guess the APPROTECT register doesn&amp;#39;t get time to update before you reset.&lt;/p&gt;
&lt;p&gt;WARNING: Read the last part before testing this.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	uint32_t Protected = NRF_UICR-&amp;gt;APPROTECT;
	if (Protected != 0x00){
		debug(&amp;quot;Protected=%X&amp;quot;,Protected);
		NRF_UICR-&amp;gt;APPROTECT = 0x00;
		while (NRF_UICR-&amp;gt;APPROTECT != 0x00)
		{
		    // Wait for the register write to finish.
		}
		NVIC_SystemReset();
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It might be a good idea to add a small delay (1 second or so) when experimenting with this. If something goes wrong and you enter a very fast reset loop with the APPROTECT enabled, it may be difficult for your debugger to be able to connect to the device. This would cause it to be hard to --recover it as well. When everything is working as expected, you can remove the delay.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, when you are working with the UICR registers, you need to make sure that it is set to write mode. Please look at how this is done in the system_nrf52.c, e.g. if the CONFIG_GPIO_AS_PINRESET is set.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Therefore, it should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        nrf_delay_ms(2000);                 // Use this for easier recovery while experimenting. Needs: #include &amp;quot;nrf_delay.h&amp;quot;
        if (NRF_UICR-&amp;gt;APPROTECT == 0xFF)
        {
            NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Wen &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos;
            while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_BUSY){}
            NRF_UICR-&amp;gt;APPROTECT = 0x00;
            while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_BUSY){}
            nvmc_config(NVMC_CONFIG_WEN_Ren);
            while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_BUSY){}
            while (NRF_UICR-&amp;gt;APPROTECT != 0x00)
            {
                // Wait.
            }
            NVIC_SystemReset();
        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implications of turning off read access</title><link>https://devzone.nordicsemi.com/thread/470495?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 14:54:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c6f04f3-9793-4271-9d6c-cad69023f87d</guid><dc:creator>Randy Lee</dc:creator><description>&lt;p&gt;One thing here:&amp;nbsp; I&amp;#39;m doing this as one of the first things in code:&lt;/p&gt;
&lt;p&gt;NRF_UICR-&amp;gt;APPROTECT = 0x00;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t get a fault for it or anything but I can continue to debug in that session or any other session which, according to your note #1 above, I shouldn&amp;#39;t be able to do.&lt;/p&gt;
&lt;p&gt;In fact, with this code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	uint32_t Protected = NRF_UICR-&amp;gt;APPROTECT;
	if (Protected != 0x0){
		debug(&amp;quot;Protected=%X&amp;quot;,Protected);
		NRF_UICR-&amp;gt;APPROTECT = 0;
		NVIC_SystemReset();
	}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I get an infinite loop, at least doing debug and the register is always reading as 0xFFFFFFFF&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implications of turning off read access</title><link>https://devzone.nordicsemi.com/thread/470461?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 13:04:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf85746c-3b25-4257-ab98-9a6dc825bce3</guid><dc:creator>Randy Lee</dc:creator><description>&lt;p&gt;Thank you... this is instructive.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implications of turning off read access</title><link>https://devzone.nordicsemi.com/thread/470407?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 09:44:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:797168be-4418-400e-9b76-e2c79fc39aed</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]1) Does this stop the debugger from doing things like breakpoints? Or Disassembly?[/quote]
&lt;p&gt;Yes. If you enable APPROTECT you will no longer be able to debug (set breakpoints, etc.). You will also not be able to program the device without running a recovery, which will erase the flash before unlocking the APPROTECT.&lt;/p&gt;
[quote user=""]2) What effect, if any, does this have on the bootloader operation? Can it go and erase place and reprogram those? I&amp;#39;m assuming the new program would then set that register again.[/quote]
&lt;p&gt;The bootloader will still have access to update the FW, since it is not dependent on a physical programmer. It is only the external programmer port that is disabled (or restricted, really. You can still do the recover command). The APPROTECT is stored in UICR, so it will remain enabled until you recover the chip. No need to enable it from every new application after DFU.&lt;/p&gt;
[quote user=""]3) Any other sideaffects this action creates to watch out for?[/quote]
&lt;p&gt;Other than the fact that you will not be able to access the device with a debugger, there is not really that much to look out for. Just be aware that if you encounter any issues out in the field (after selling/deploying the device), in case something bad happens, you will not be able to debug the application without completely re-programming it without the APPROTECT enabled.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>