<?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>APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12484/approtect-and-dap</link><description>Hi, 
 I have a JLink script which sets APPROTECT in the UICR to enable readback protection and disable the debug interface. 
 For development purposes, I would like to be able to clear these. The process seems to be to write certain values to the CTRL</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Sep 2017 16:57:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12484/approtect-and-dap" /><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47300?ContentTypeID=1</link><pubDate>Fri, 29 Sep 2017 16:57:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c03160fb-f770-4c79-92a1-8e6d8a6adf75</guid><dc:creator>Eric Stutzenberger</dc:creator><description>&lt;p&gt;In our factory programming script, we do the following with via JLink:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;//Clear App Protect and Erase All
SWDSelect //Selects the SWD Interface
SWDWriteDP 1 0x50000000 //Enables power
SWDWriteDP 2 0x01000000 //Selects the 0x01XXXXXX Access Port and 0xXXXX00XX Register bank in the access port
SWDWriteAP 1 0x00000001 //CTRL-AP Bank 0, register offset 1 (ERASEALL 0x004): Erase all command
sleep 1000 
SWDReadAP 2 //CTRL-AP Bank 0, register offset 2 (ERASEALL 0x008): Erase all command status
SWDReadAP 2 //Second read returns the value
SWDWriteAP 0 0x00000001 
SWDWriteAP 0 0x00000000 
SWDWriteAP 1 0x00000000 
SWDReadAP 3 //CTRL-AP Bank 0, register offset 3 (APPROTECTSTATUS 0x00C): Access port protection status
SWDReadAP 3 //Second read returns the value: 0: enabled 1: not enabled
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;Eric&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47299?ContentTypeID=1</link><pubDate>Fri, 29 Sep 2017 07:47:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42459aad-f2d7-4249-bfb0-aff4936ff1e1</guid><dc:creator>Michael</dc:creator><description>&lt;p&gt;Hi Eric!&lt;/p&gt;
&lt;p&gt;Did you find a solution for your problem? I get the same ERROR when trying to erase the chip with the JLink Commander.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47302?ContentTypeID=1</link><pubDate>Tue, 22 Mar 2016 16:58:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:275fb2b2-7016-40e9-9972-c22cd8c8e62d</guid><dc:creator>Eric Stutzenberger</dc:creator><description>&lt;p&gt;JLink Erase script for locked NRF52: &lt;a href="http://pastebin.com/zChcyMtN"&gt;http://pastebin.com/zChcyMtN&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47301?ContentTypeID=1</link><pubDate>Tue, 22 Mar 2016 16:55:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1e8fdc4-ea60-41c2-ab1c-60015b7bb678</guid><dc:creator>Eric Stutzenberger</dc:creator><description>&lt;p&gt;I figured out the solution:&lt;/p&gt;
&lt;p&gt;You cannot ask JLink Commander to connect to the device after APPROTECT is set.  This causes commander to switch to some state where SWDWriteDP/SWDReadDP always fails with an error.  I don&amp;#39;t fully understand what state the connect command causes in JLink Commander.  Instead, after starting JLInk Commander send only the SWDSelect command.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start JLink Commander&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SWDSelect -&amp;gt; Selects SWD Interface&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SWDWriteDP 1 0x50000000 -&amp;gt; Enable power (as suggested by Segger response)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SWDWriteDP 2 0x01000000 -&amp;gt; Seleect CTRL-AP Bank 0&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SWDWriteAP 1 0x00000001 -&amp;gt; Full Chip Erase&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SWDReadAP 2 -&amp;gt; Repeat until 0&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SWDReadAP 3 -&amp;gt; Two reads show 0x00000001 meaning protection cleared&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Thanks for the help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47298?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 18:48:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9985c46-32d3-4728-addc-2dde2699dab8</guid><dc:creator>Eric Stutzenberger</dc:creator><description>&lt;p&gt;Hi RK, thanks for the comments.&lt;/p&gt;
&lt;p&gt;Since I have many eval board around for our module, I was able to lock one of them for this testing.  After enabling APPROTECT the SWDWriteDP, SWDWriteAP, and their respective read commands all return something in the form of &lt;code&gt;Write DP Register x = &amp;lt;data&amp;gt; ***ERROR&lt;/code&gt; or &lt;code&gt;Read AP register x = ERROR&lt;/code&gt;.  The &lt;code&gt;erase&lt;/code&gt; command returns &lt;code&gt;ERROR: Erase returns with error code -1.&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I know it is possible to recover devices using nrfjprog but that doesn&amp;#39;t help me in this case since I am trying to support many different system types.  Since there isn&amp;#39;t an answer from Nordic here, I will ask them directly and post back with the result.&lt;/p&gt;
&lt;p&gt;Thanks again for the help so far.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47297?ContentTypeID=1</link><pubDate>Sat, 12 Mar 2016 03:31:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab110e04-4418-480d-9bfd-5882b8a373c7</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Did it work?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: APPROTECT and DAP</title><link>https://devzone.nordicsemi.com/thread/47296?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 01:29:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fd74452-41b2-468c-8ef8-13880968a910</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;DAP isn&amp;#39;t memory-mapped (well it&amp;#39;s allowed to be but it&amp;#39;s implementation defined if it is or not). You use the JLink SWDReadDP/AP SWDWriteDP/AP commands to read and write the coresight registers. The nrf51 data sheet isn&amp;#39;t going to help you there, you need to read the ARM v7m reference manual and the ARM ADIv5 manual to get very far.&lt;/p&gt;
&lt;p&gt;I hadn&amp;#39;t looked at the nRF52 CTRL-AP, a quick poke around with JLink and some notes I made after reading the ADIv5 manual last year seems to indicate it&amp;#39;s a second AP entirely and doesn&amp;#39;t show up in the ROM table ... I guess it wouldn&amp;#39;t if the DAP is disabled, not going to disable mine to work it out. The following, checking register 0x0FC of AP number 1 (normal DP is number 0) seems to give the correct AP ID, ie the one in the manual 0x02880000&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SWDWriteDP 2 0x010000f0
SWDReadAP 3
SWDReadAP 3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;note the double-read as data is returned on the second one.&lt;/p&gt;
&lt;p&gt;So if that&amp;#39;s the right AP, APPPROTECTSTATUS is at 0x00C, reading that on mine with the following&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SWDWriteDP 2 0x01000000
SWDReadAP 3
SWDReadAP 3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;gives&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Read AP register 3 = 0x00000001
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which seems correct as indeed protection is off on my chip, you should get 0x00000000&lt;/p&gt;
&lt;p&gt;keeping going .. reading the ERASEALLSTATUS just requires reading register 0x008&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SWDReadAP 2
SWDReadAP 2

Read AP register 2 = 0x00000000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;seems right, the chip isn&amp;#39;t erasing currently&lt;/p&gt;
&lt;p&gt;Resetting the chip you want to write 0x00000001 to 0x000&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SWDWriteAP 0 0x00000001
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That reset the chip for me and held the thing in reset and then I failed to get much done after that, I think I needed to switch back to port 0 but didn&amp;#39;t and upset JLink .. power cycle.&lt;/p&gt;
&lt;p&gt;So to erase everything it seems you should write 0x00000001 to register 0x004 which would be&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SWDWriteAP 1 0x00000001
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and I&amp;#39;m not going to try that myself, but I&amp;#39;d love to hear how you got on :)&lt;/p&gt;
&lt;p&gt;Note all those SWDReadAP and SWDWriteAP commands for 0x000 to 0x00C registers are predicated on your having written the DP port to the correct value with that&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SWDWriteDP 2 0x01000000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;command which I executed before reading the APPPROTECTSTATUS. It&amp;#39;s sticky so you don&amp;#39;t have to keep doing it.&lt;/p&gt;
&lt;p&gt;Usually you don&amp;#39;t have to muck about like that, Segger usually implements this stuff, so did you just try the JLink &lt;code&gt;erase&lt;/code&gt; command to see if it&amp;#39;s CTRL-AP aware? If not, it&amp;#39;s a good question for their forums, and would be a good thing for them to implement.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>