<?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 to enable/disable UICR custom registers writes through APPROTECT?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61017/how-to-enable-disable-uicr-custom-registers-writes-through-approtect</link><description>Hello Devzone: 
 Would I be correct if I assume enabling APPROTECT should prevent writes into UICR? - for other readers, NO, IT CANNOT PROTECT AGAINST SOFTWARE READS/WRITES, ONLY DEBUGGER 
 Based on this assumption I wrote the following code to enable</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 May 2020 17:36:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61017/how-to-enable-disable-uicr-custom-registers-writes-through-approtect" /><item><title>RE: How to enable/disable UICR custom registers writes through APPROTECT?</title><link>https://devzone.nordicsemi.com/thread/248295?ContentTypeID=1</link><pubDate>Tue, 05 May 2020 17:36:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d268210-40ee-44f0-a4d2-a1ecbe9b311c</guid><dc:creator>wpaul</dc:creator><description>&lt;p&gt;Just to be very clear:&lt;/p&gt;
&lt;p&gt;The UICR locations are not just arbitrarily writable. Initially the UICR locations are in the erased state (shows 0xFF when read). Individual locations can be written to set their values. But once written, a location can&amp;#39;t be modified again _unless_ you issue the ERASEUICR command to return the entire UICR to the erased state and then program it all over again.&lt;/p&gt;
&lt;p&gt;Enabling the APPPROTECT feature requires writing a 0x00 to NRF_UICR-&amp;gt;APPROTECT. So once you do that, the only way to change it back to 0xFF is to erase the UICR.&lt;/p&gt;
&lt;p&gt;Note that the reset pin selection is also stored in the UICR, so if you erase it, you should remember to restore it, otherwise the external reset button will stop working.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s an example of the code I wrote once for the nRF52840 to erase and reprogram the UICR:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/netik/dc27_badge/blob/master/software/firmware/badge/main.c#L352"&gt;https://github.com/netik/dc27_badge/blob/master/software/firmware/badge/main.c#L352&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also, enabling the APPROTECT feature does not &amp;quot;prevent writes to the UICR.&amp;quot; What it does is disable the CPU&amp;#39;s debug access port (DAP) so that you can no longer issue commands via the SWD pins to debug the CPU. This blocks the debugger from accessing anything on the CPU, not just the UICR fields.&lt;/p&gt;
&lt;p&gt;In order to recover a device which has been setThis this way (and where the firmware loaded into the device has no option to do it for you), you have to issue an ERASEALL command via the CTRL-AP port (which is a vendor-specific access port separate from the debug AP). The ERASEALL command will blank both the flash and the UICR (i.e. returns the chip back to its &amp;quot;fresh off the assembly line&amp;quot; state). You can issue an ERASEALL command via the NVMC registers too, but if the APPROTECT feature is turned on, the NVMC registers will also be inaccessible via the debug port. The CTRL-AP access mechanism provides an alternate way to reset the chip. The difference is that while this lets you recover a locked device, it doesn&amp;#39;t allow you to download the contents of the flash first (i.e. software in a locked device is still protected from unauthorized access).&lt;/p&gt;
&lt;p&gt;Most of the time if you ask how to do this, you will be told to use the nrfjprog utility. However there are other ways to issue this command with a debugger. Here&amp;#39;s an example of how to do it with OpenOCD and an arbitrary JTAG/SWD debugger:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/netik/dc27_badge/blob/master/hardware/programming/debug.txt#L41"&gt;https://github.com/netik/dc27_badge/blob/master/hardware/programming/debug.txt#L41&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to enable/disable UICR custom registers writes through APPROTECT?</title><link>https://devzone.nordicsemi.com/thread/248204?ContentTypeID=1</link><pubDate>Tue, 05 May 2020 13:39:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40dd991b-e05b-4acb-ba80-f4897ccec88a</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Yes, access port protection blocks the debugger from read and write access to all CPU registers and memory-mapped addresses.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Access port protection is disabled by issuing an ERASEALL command via CTRL-AP. This command will erase the flash, UICR, and RAM.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to enable/disable UICR custom registers writes through APPROTECT?</title><link>https://devzone.nordicsemi.com/thread/248030?ContentTypeID=1</link><pubDate>Mon, 04 May 2020 23:16:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8cbb0e5-30cd-44e3-a9b4-090204815a12</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;UICR works like a flash page - you can erase it &lt;em&gt;all at once&lt;/em&gt; only. Changing bits 1-&amp;gt;0 is called &amp;quot;writing&amp;quot; but 0-&amp;gt;1 can only be done with &amp;quot;erase&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>