<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/82409/example-code-to-write-to-uicr</link><description>I am trying to store data to the UICR using SDK16, mesh SDK 4.2.0 and the nRF52840 chip. 
 I want to write to the UICR once on runtime and never again. To avoid messing with the softdevice, I am trying to write to the UICR before calling ble_stack_init</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Wed, 18 May 2022 10:54:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/82409/example-code-to-write-to-uicr" /><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/368289?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 10:54:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d947dffc-ca50-45ad-8cdb-b79685e5eaee</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Thank you Einar.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/368285#368285"](The CPU cannot erase the UICR page, though)[/quote]
&lt;p&gt;Does this mean I can only write to UICR-&amp;gt;CUSTOMER locations which are FFFF... i.e. the UICR locations that have not been written to since the last erase?&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/368221#368221"]You have the same functionality in 1.7.0. There you have&amp;nbsp;nrf52_errata_249() in&amp;nbsp;modules\hal\nordic\nrfx\mdk\nrf52_erratas.h which is used from&amp;nbsp;modules\hal\nordic\nrfx\mdk\system_nrf52_approtect.h. [/quote]
&lt;p&gt;Looking in system_nrf52_approtect.h I can see the code inside the function&amp;nbsp;nrf52_handle_approtect() is disabled because&amp;nbsp;NRF52_ERRATA_249_PRESENT is defined as &lt;span&gt;1&amp;nbsp;in nrf52_erratas.h&lt;/span&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do I need to define ENABLE_APPROTECT?&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://test-devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/nrf52_5F00_handle_5F00_approtect.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;Yet you said this is handled automatically in the MDK. I must be missing something.&lt;/p&gt;
&lt;p&gt;Also, it seems the the function nrf52_errate_249() always returns false unless&amp;nbsp;NRF52_SERIES is defined.&amp;nbsp; &amp;nbsp; How can I add the pre-processor directive &lt;span style="background-color:#ffffff;"&gt;&lt;em&gt;&lt;strong&gt;-D&lt;span&gt;NRF52_SERIES&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt; in Segger Embedded Studio v5.60?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;There are many macros and I am not sure which ones I need to define and which ones are handled automatically by the MDK. Please clarify.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* ========= Errata 249 ========= */
#if    defined (NRF52820_XXAA) || defined (DEVELOP_IN_NRF52820) \
    || defined (NRF52832_XXAA) || defined (DEVELOP_IN_NRF52832) \
    || defined (NRF52832_XXAB) || defined (DEVELOP_IN_NRF52832) \
    || defined (NRF52833_XXAA) || defined (DEVELOP_IN_NRF52833) \
    || defined (NRF52840_XXAA) || defined (DEVELOP_IN_NRF52840)
    #define NRF52_ERRATA_249_PRESENT 1
#else
    #define NRF52_ERRATA_249_PRESENT 0
#endif

#ifndef NRF52_ERRATA_249_ENABLE_WORKAROUND
    #define NRF52_ERRATA_249_ENABLE_WORKAROUND NRF52_ERRATA_249_PRESENT
#endif

static bool nrf52_errata_249(void)
{
    #ifndef NRF52_SERIES
        return false;
    #else
        #if defined (NRF52820_XXAA) || defined (DEVELOP_IN_NRF52820)\
         || defined (NRF52832_XXAA) || defined (DEVELOP_IN_NRF52832)\
         || defined (NRF52832_XXAB) || defined (DEVELOP_IN_NRF52832)\
         || defined (NRF52833_XXAA) || defined (DEVELOP_IN_NRF52833)\
         || defined (NRF52840_XXAA) || defined (DEVELOP_IN_NRF52840)
            uint32_t var1 = *(uint32_t *)0x10000130ul;
            uint32_t var2 = *(uint32_t *)0x10000134ul;
        #endif
...
...
        #if defined (NRF52833_XXAA) || defined (DEVELOP_IN_NRF52833)
            if (var1 == 0x0D)
            {
                switch(var2)
                {
                    case 0x00ul:
                        return false;
                    case 0x01ul:
                        return false;
                    case 0x02ul:
                        return true;
                    default:
                        return true;
                }
            }
        #endif
...
...
        return false;
    #endif
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/368285?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 10:52:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d005101-2c51-4b26-8ae2-e962f0cdae48</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="92434" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/368284#368284"]&lt;p&gt;&lt;span&gt;If&amp;nbsp;NRF_UICR-&amp;gt;APPROTECT is set to UICR_APPROTECT_PALL_Enabled&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Will I still be able to write to&amp;nbsp;NRF_UICR-&amp;gt;CUSTOMER flash area in the firmware at runtime?&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Yes. The APPROTECT mechanism only prevents debugger access. The CPU still has ability to write to the UICR. (The CPU cannot erase the UICR page, though).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/368284?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 10:47:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6ea904b-2e72-4722-a853-9b671184e18b</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;The reason I am looking at using&amp;nbsp;&lt;span&gt;nrf52_errata_249() is, as you suggested, to distinguish between chips with the older APPROTECT mechanism and those with the new one in system_SetDebugPortAccess(). &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;There is one thing I am not sure about though.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If&amp;nbsp;NRF_UICR-&amp;gt;APPROTECT is set to UICR_APPROTECT_PALL_Enabled&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Will I still be able to write to&amp;nbsp;NRF_UICR-&amp;gt;CUSTOMER flash area in the firmware at runtime?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Mohamed&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/368221?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 08:08:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dbb2294-da3b-4aa5-9aa6-72206b861a87</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi Mohamed,&lt;/p&gt;
&lt;p&gt;You have the same functionality in 1.7.0. There you have&amp;nbsp;nrf52_errata_249() in&amp;nbsp;modules\hal\nordic\nrfx\mdk\nrf52_erratas.h which is used from&amp;nbsp;modules\hal\nordic\nrfx\mdk\system_nrf52_approtect.h. So also there, this is handled automatically by the MDK and you don&amp;#39;t really need to do anything. But if you for some reason want to have your own code for handing this (like it seems you do in your system_SetDebugPortAccess(), though I don&amp;#39;t really see the need thins the MDK&amp;nbsp; handles it for you), you can use this function to distinguish between old revisions with old APPROTECT (HW only based) mechanism and new APPROTECT mechanism (HW + SW based).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/368010?ContentTypeID=1</link><pubDate>Mon, 16 May 2022 09:53:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:358a208c-2725-4595-86cd-65c429006218</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hello Einar,&lt;/p&gt;
&lt;p&gt;Thank you for the clarifications and the link.&lt;/p&gt;
&lt;p&gt;I will have a read.&amp;nbsp;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/367925#367925"]Referring to nRF Connect SDK 1.9.1 you have&amp;nbsp;modules/hal/nordic/nrfx/mdk/system_nrf52_approtect.h which handles APPROTECT. There you can see that the&amp;nbsp;nrf52_configuration_249() is checked and this returns true for devices with the new APPROTECT mechanism and false for the older.[/quote]
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I would like to avoid moving to v1.9.1 at this moment in time if I can help it.&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;In SDK 1.7.0 I can only find in stystem_nrf52_approtect.h the function&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;strong&gt;static inline void nrf52_handle_approtect(void)&lt;/strong&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Is there something similar in v1.7.0 that will allow me to read the chip revision ?&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367925?ContentTypeID=1</link><pubDate>Sun, 15 May 2022 07:36:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7110197-457c-4b37-a67b-a25c6910f90e</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Mohamed,&lt;/p&gt;
&lt;p&gt;The code in this snippet will&amp;nbsp;not work for older revisions., which has a different APPROTECT mechanism. You need to handle the revisions separately, as is done in the MDK. Referring to nRF Connect SDK 1.9.1 you have&amp;nbsp;modules/hal/nordic/nrfx/mdk/system_nrf52_approtect.h which handles APPROTECT. There you can see that the&amp;nbsp;nrf52_configuration_249() is checked and this returns true for devices with the new APPROTECT mechanism and false for the older.&lt;/p&gt;
&lt;p&gt;As you want to disable APPROTECT, and older devices has APPROTECT disabled by default (, you can simply check which revision you have and avoid running any APPROTECT&amp;nbsp;related code on the older devices.&lt;/p&gt;
&lt;p&gt;PS: To understand the&amp;nbsp;difference between the old (Access port protection controlled by hardware) and new (Access port protection controlled by hardware and software) scheme, I suggest you refer to the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/dif.html?cp=4_1_0_3_7"&gt;Debug and trace chapter in the product specification&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367904?ContentTypeID=1</link><pubDate>Fri, 13 May 2022 20:59:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:476c37ee-5bf7-433d-91c4-0dfbf85963b2</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/366848#366848"]&lt;blockquote class="quote"&gt;&lt;div class="quote-user"&gt;Learner said:&lt;/div&gt;&lt;div class="quote-content"&gt;Can I use the same code snippet with other Soc version e.g. QDAAA0?&lt;/div&gt;&lt;/blockquote&gt;&lt;div class="quote-footer"&gt;&lt;/div&gt;
&lt;p&gt;If you refer to the code snippet to write to flash, then yes. Writing to flash (including the UICR) is the same for all revisions. (As mentioned&amp;nbsp;&lt;em&gt;deleting&lt;/em&gt; the UICR page is special though, as it can only be done with a full chip erase).&lt;/p&gt;[/quote]
&lt;p&gt;I am finding that I cannot debug&amp;nbsp;code on an older version &lt;strong&gt;QDAAA0&lt;/strong&gt;. The code boots up and stops at the point where NRF_UICR-&amp;gt;APPROTECT is checked, see code below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void system_SetDebugPortAccess(void)
{
#if (CONFIG_DEBUG_PORT_ACCESS)

    /* Prevent chip from locking itself in hardware (if not already set) */
    if (NRF_UICR-&amp;gt;APPROTECT != UICR_APPROTECT_PALL_HwDisabled)
    {
        LOG_ERR(&amp;quot;Device debug prevented on next POR (0x%08X), resetting to disable this.&amp;quot;, NRF_UICR-&amp;gt;APPROTECT);
        system_WriteDebugPortAccess(UICR_APPROTECT_PALL_HwDisabled);
    }

    /* Prevent chip from locking itself in software */
    NRF_APPROTECT-&amp;gt;DISABLE = APPROTECT_DISABLE_DISABLE_SwDisable;

#else
    /* Enforce HW protection (if not already set) */
    if (NRF_UICR-&amp;gt;APPROTECT != UICR_APPROTECT_PALL_Enabled)
    {
        LOG_ERR(&amp;quot;Device debug allowed on next POR (0x%08X), resetting to disable this.&amp;quot;, NRF_UICR-&amp;gt;APPROTECT);
        system_WriteDebugPortAccess(UICR_APPROTECT_PALL_Enabled);
    }

    /* Belts and braces, enforce SW protection */
    NRF_APPROTECT-&amp;gt;FORCEPROTECT = APPROTECT_FORCEPROTECT_FORCEPROTECT_Force;

#endif //CONFIG_DEBUG_PORT_ACCESS
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is what I see in Segger Embedded Studio (SES-Nordic Edition) Debug Terminal:&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v2.6.99-ncs1 ***&lt;br /&gt;&lt;span style="font-size:inherit;"&gt;&lt;span style="font-size:75%;"&gt;[00:00:00.025,848] &lt;span style="color:#ff0000;"&gt;&amp;lt;err&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt; system: Device debug prevented on next POR (0xFFFFFFFF), resetting to disable this.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;font-size:inherit;"&gt;So, basically&amp;nbsp;NRF_UICR-&amp;gt;APPROTECT &lt;span style="background-color:#ffff00;"&gt;!=&lt;/span&gt; UICR_APPROTECT_PALL_HwDisabled&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;font-size:inherit;"&gt;I&amp;nbsp;can debug the same code on a newer version of the chip QDAAB0.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;font-size:inherit;"&gt;&lt;/span&gt;&lt;span style="color:#000000;font-size:inherit;"&gt;QDAAA0: content of APPROTECT:&amp;nbsp;10120000FFFFFFFFFFFFFFFF&lt;span style="background-color:#ffff00;"&gt;FFFFFFFF&lt;/span&gt;FFFFFFFFEE&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;font-size:inherit;"&gt;&lt;span&gt;QDAAB0: content of APPROTECT:&amp;nbsp;101200001200000012000000&lt;span style="background-color:#ffff00;"&gt;5A000000&lt;/span&gt;FEFFFFFF65&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;font-size:inherit;"&gt;&lt;span&gt;So, I wrote to APPROTECT of the &lt;strong&gt;QDAAA0&lt;/strong&gt; chip 0x0000005A&amp;nbsp; to disable the protection mechanism.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="color:#000000;"&gt;C:\WINDOWS\system32&amp;gt;&lt;strong&gt;nrfjprog --recover&lt;/strong&gt;&lt;br /&gt;Recovering device. This operation might take 30s.&lt;br /&gt;Erasing user code and UICR flash areas.&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="color:#000000;"&gt;C:\WINDOWS\system32&amp;gt;&lt;strong&gt;nrfjprog --memwr 0x10001208 --val 0x0000005A --verify&lt;/strong&gt;&lt;br /&gt;Parsing parameters.&lt;br /&gt;Writing.&lt;br /&gt;Verified OK.&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I then read UICR back to check the value of&amp;nbsp;APPROTECT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;C:\WINDOWS\system32&amp;gt;&lt;strong&gt;nrfjprog --readuicr hb-700078-3.ihex&lt;/strong&gt;&lt;br /&gt;Storing data in &amp;#39;hb-700078-3.ihex&amp;#39;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;QDAAA0: new content of APPROTECT:&amp;nbsp;10120000FFFFFFFFFFFFFFFF&lt;span style="background-color:#ffff00;"&gt;5A000000&lt;/span&gt;FFFFFFFFEE&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But when I flash the firmware in SES and start a debug session I still cannot debug it. I get the same error,&amp;nbsp;&lt;span style="font-size:75%;"&gt;&lt;span style="color:#ff0000;"&gt;&amp;lt;err&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&amp;nbsp;system: Device debug prevented on next POR (0xFFFFFFFF), resetting to disable this.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I then tried to read back&amp;nbsp;UICR to check if APPROTECT is still disabled but the read command failed&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;C:\WINDOWS\system32&amp;gt;&lt;strong&gt;nrfjprog --readuicr hb-700078-4.ihex&lt;/strong&gt;&lt;br /&gt;ERROR: The operation attempted is unavailable due to readback protection in&lt;br /&gt;ERROR: your device. Please use --recover to unlock the device.&lt;br /&gt;NOTE: For additional output, try running again with logging enabled (--log).&lt;br /&gt;NOTE: Any generated log error messages will be displayed.&lt;/em&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;Why?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;It looks as if the APPROTECT enable/disable does not work for older chip version such as QDFAAA0.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Kind regards&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Mohamed&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367333?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 08:31:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74e29f01-3b25-459b-9e22-5e828c602b68</guid><dc:creator>user92434</dc:creator><description>&lt;div&gt;Good Morning Einar,&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;We managed to solve the problem by just installing &lt;strong&gt;nRF Connect for Desktop&lt;/strong&gt; on the new machine.&lt;/div&gt;
&lt;div&gt;Thank you for your support.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367287?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 06:10:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eea3d5c5-84a5-4ad3-8c2c-ef7207f54e63</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am not immediately able to explain that. Please open a new question/thread for this&amp;nbsp;as it is not&amp;nbsp;directly related to the original topic in this thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367233?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 14:55:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6251ccac-19e5-470b-9fb9-81b98a3734a0</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hi Thorsrud,&lt;/p&gt;
&lt;p&gt;I have&amp;nbsp;installed nrfjprog v10:15 on another machine running Windows 10 64-bits and&amp;nbsp;I am running into this problem,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C:\&amp;gt;nrfjprog -v&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;ERROR: JLinkARM DLL is invalid. Please reinstall latest JLinkARM DLL.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;NOTE: For additional output, try running again with logging enabled (--log).&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;NOTE: Any generated log error messages will be displayed.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C:\&amp;gt;nrfjprog -v --log&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;WARNING: Logging is unavailable. nrfjprog.exe does not have write&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;WARNING: permission for the log file&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;ERROR: JLinkARM DLL is invalid. Please reinstall latest JLinkARM DLL.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;NOTE: For additional output, try running again with logging enabled (--log).&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;NOTE: Any generated log error messages will be displayed.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;He has installed it twice but he is still facing the same problem.&lt;/p&gt;
&lt;p&gt;Thank you for your help.&lt;/p&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367126?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 09:47:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:939ae8dc-4792-491a-b8a9-b24aad606ec4</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Thank you for sharing the link.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/367120#367120"]note that if you want to debug/program after step 3, it is a&amp;nbsp;requirement that the firmware continues to enable debugger access. That is the default&amp;nbsp;behavior with the SDK though, so it&amp;nbsp;should be good).[/quote]
&lt;p&gt;Understood. The three steps mentioned above are for a production environment. We do all development and debugging in Segger Embedded Studio.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367120?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 09:29:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0718e617-f4fd-4101-8400-1c76ec42fbf7</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Yes, that looks correct (note that if you want to debug/program after step 3, it is a&amp;nbsp;requirement that the firmware continues to enable debugger access. That is the default&amp;nbsp;behavior with the SDK though, so it&amp;nbsp;should be good).&lt;/p&gt;
&lt;p&gt;I forgot about this post before, but you can read a bit more in &lt;a href="https://test-devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/working-with-the-nrf52-series-improved-approtect"&gt;Working with the nRF52 Series&amp;#39; improved APPROTECT&lt;/a&gt; if you want more details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367116?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 09:21:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c78b16b-28bf-4c39-ae0c-7e3aa94e33a3</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Thank you Thorsrud.&lt;/p&gt;
&lt;p&gt;It is all clear now.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/367066#367066"]If you are using the newest revision ICs, you need to recover first with for instance nrfjprog: nrfjprog --recover. This will disable APPROTECT in the UICR and add a small[/quote]
&lt;p&gt;So, for the newest revision ICs, I must perform the firmware flash operation and setting the device id in three&amp;nbsp; the steps. Step 1 will erase&amp;nbsp;all user flash memory and disables the&amp;nbsp;readback protection mechanism if enabled. Step 2 will write the device id in the UICR customer[0] location. Finally, step 3 will flash the firmware &lt;span style="text-decoration:underline;"&gt;without erasing&lt;/span&gt; the UICR. The firmware will then re-enable the&amp;nbsp;&lt;span&gt;readback protection mechanism at boot-up.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Step 1: Disable APPROTECT:&amp;nbsp;&amp;nbsp;&lt;strong&gt;nrfjprog --recover&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Step 2: Flash device id:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;strong&gt;nrfjprog --memwr 0x10001080 --val&lt;/strong&gt; &amp;lt;device id&amp;gt;&lt;/p&gt;
&lt;p&gt;Step 3: Flash firmware:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;strong&gt;nrfjprog --program merged.hex &amp;ndash;-sectorerase --reset&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Am I right?&lt;/p&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367096?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 08:42:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81307931-5241-428c-ae36-ebd313d13005</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;nRF Connect SDK 1.7.0 OK (that is the oldest nRF Connect SDK with support for the latest&amp;nbsp;revision the nRF52833). nRF Connect SDK 1.7.0 use nrfx 2.5.0 which include MDK 8.40.2. Finding it is a bit tedious, but the easiest is to check the README for nrfx which you find under&amp;nbsp;modules/hal/nordic/nrfx/README, and which tells you which version you are using. Then check the CHANGELOG.md in the same folder, which states which&amp;nbsp;MDK version is used.&lt;/p&gt;
&lt;p&gt;There are separate documents for each device, but the content is&amp;nbsp;virtually&amp;nbsp;the same. For nRF52833 it is &lt;a href="https://infocenter.nordicsemi.com/pdf/in_149_v1.1.pdf?cp=18_9"&gt;IN-149&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367090?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 08:31:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b5d3f60-4549-4f1a-99fc-df07e5e72661</guid><dc:creator>user92434</dc:creator><description>&lt;div&gt;Good Morning Thorsrud,&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Thank you for the tips.&lt;/div&gt;
&lt;div&gt;I must admit I get confused with all these different tools versions.&lt;/div&gt;
&lt;div&gt;I know I am using,&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Zephyr&amp;nbsp;&amp;nbsp;OS build v2.6.99-ncs1&lt;/div&gt;
&lt;div&gt;nRF Connect SDK v1.7.0&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;But I am not sure which MDK version I am using. How do I find out?&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/367066#367066"]See &lt;a href="https://infocenter.nordicsemi.com/pdf/in_142_v1.1.pdf?cp=18_16"&gt;IN-142&lt;/a&gt; for more details[/quote]This document refers to nRF52832 but I am using nrf52833.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;Does it also apply to nRF52833?&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/367066?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 06:56:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfec3b0b-59af-4f79-963d-9a842b3cda51</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Mohamed,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is a special case. Reading the output from nrfjprog you see that readback protection is enabled (APPROTECT). And the only way to disable it is to perform a full chip erase (nrfjprog --recover). Clearly you want to avoid this issue in the future, as you want to be able to program/debug&amp;nbsp;several times after the initial programming:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;If you are using older revisions, simply do not enable APPROTECT. As long as it is never enabled, you will not have this problem.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;If you are using the newest revision ICs, you need to recover first with for instance nrfjprog: nrfjprog --recover. This will disable APPROTECT in the UICR and add a small code snippet that unlocks the debug port so that it can be used in the future. However, when you flash your firmware this temporary firmware is deleted, and you must ensure that your firmware does this. For that you must use a MDK version &amp;gt;= 8.40.2, which for&amp;nbsp;instance is included in nRF5 SDK 17.1.0. See &lt;a href="https://infocenter.nordicsemi.com/pdf/in_142_v1.1.pdf?cp=18_16"&gt;IN-142&lt;/a&gt; for more details.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366991?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 14:13:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3eec7c8-569c-4121-b3d3-113db2742e25</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hi Thorsrud,&lt;/p&gt;
&lt;p&gt;I see, I thought I needed to explicitly specify the pages I wanted to erase because &amp;#39;sectorerase expects arguments. so I don&amp;#39;t need to specify the pages number after --sectorerase at the end of the command line.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried the command&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;nrfjprog -f NRF52 --program merged.hex &amp;ndash;-sectorerase&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;First I got this error,&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:75%;"&gt;&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;C:\Sandbox\HomeBeacon_dev_sb\build_nrf52833dk_nrf52833_v133_rel\zephyr&amp;gt;nrfjprog -f NRF52 --program merged.hex --sectorerase&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;ERROR: The operation attempted is unavailable due to readback protection in&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;ERROR: your device. Please use --recover to unlock the device.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;NOTE: For additional output, try running again with logging enabled (--log).&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;NOTE: Any generated log error messages will be displayed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then I tried&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:75%;"&gt;&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;C:\Sandbox\HomeBeacon_dev_sb\build_nrf52833dk_nrf52833_v133_rel\zephyr&amp;gt;nrfjprog -f NRF52 --recover --program merged.hex --sectorerase&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;ERROR: Two arguments were provided that cannot be combined. Use --help to read&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;ERROR: about the valid argument combinations.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;NOTE: For additional output, try running again with logging enabled (--log).&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;NOTE: Any generated log error messages will be displayed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Finally, I tried&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:75%;"&gt;&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;C:\Sandbox\HomeBeacon_dev_sb\build_nrf52833dk_nrf52833_v133_rel\zephyr&amp;gt;nrfjprog -f NRF52 --recover --program merged.hex&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;Recovering device. This operation might take 30s.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;Parsing image file.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;WARNING: A programming operation has been performed without --verify.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#0000ff;font-size:75%;"&gt;WARNING: Programming can fail without error.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;But I ended up erasing the content of the UICR which I wanted to avoid.&lt;/p&gt;
&lt;p&gt;What am I doing wrong?&lt;/p&gt;
&lt;p&gt;Actually, I think the reason the command&amp;nbsp;&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;nrfjprog -f NRF52 --program merged.hex --sectorerase &lt;/span&gt;&lt;/strong&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="color:#000000;"&gt;did not work it is because the device had the &lt;span style="text-decoration:underline;"&gt;&lt;strong&gt;release&lt;/strong&gt; &lt;/span&gt;version of the code which has&lt;/span&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;&amp;nbsp;CONFIG_DEBUG_PORT_ACCESS=n.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;So, I flashed the &lt;span style="text-decoration:underline;"&gt;&lt;strong&gt;debug&lt;/strong&gt;&lt;/span&gt; version (&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;CONFIG_DEBUG_PORT_ACCESS=y&lt;/span&gt;&lt;/strong&gt;) into the device then I tried the same command &lt;strong&gt;&lt;span style="color:#0000ff;"&gt;nrfjprog -f NRF52 --program merged.hex --sectorerase&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;again and this time the&amp;nbsp;UICR register was not erased. So, we can flash the device without erasing the whole flash including the UICR only if&amp;nbsp;&amp;nbsp;&lt;strong&gt;&lt;span style="color:#0000ff;"&gt;CONFIG_DEBUG_PORT_ACCESS=y.&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366987?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 14:06:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a761611a-8d18-4faa-a991-4932296de9b8</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Mohamed,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What you have found is correct (specifying family is optional). Specifically,&amp;nbsp;&lt;/span&gt;&lt;span&gt;nrfjprog never does an erase without &amp;quot;being told so&amp;quot;, so that is no problem. To just flash your firmware if there was nothing there before, you can simply use &amp;quot;nrfjprog --program &amp;lt;hexfile&amp;gt;&amp;quot;. If you want to overwrite an existing application (the pages you are writing to are not all FFFF), then add --sectorerase like this: &amp;quot;nrfjprog --program &amp;lt;hex&amp;gt; --sectorerase&amp;quot;. With this, all pages that will be written to are erased first, but non of the others, and then the hex file is written.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366983?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 13:54:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c7c5c72-8ca0-4562-91c0-1b249cbf6801</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hi Thorsrud,&lt;/p&gt;
&lt;p&gt;Thank you for your support.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/366848#366848"]The nRF Connect Programmer version &amp;gt;= 2.0.0 unfortunately&amp;nbsp;always does an erase on write, and this is a full chip erase and not a sector erase (erasing only sectors to be writtne to). [/quote]
&lt;p&gt;Unfortunately, this is what we were planning to use. It looks like we will have to go to plan B.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/366848#366848"]A simple tool for this is &lt;a href="https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools/download"&gt;nrfjprog&lt;/a&gt;.[/quote]
&lt;p&gt;nrfjprog is plan B. I have never used it before. I have now downloaded v10.15.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;nrfjprog version: 10.15.4 external&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;JLinkARM.dll version: 7.58b&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I have read the documentation but I am still not sure how to use &amp;#39;&lt;strong&gt;sectorerase&lt;/strong&gt;&amp;#39;. I would like to use the following command line to flash our firmware using nrfjprog and avoiding to erase UICR,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;nrfjprog -f NRF52 --program merged.hex &amp;ndash;-sectorerase&lt;/strong&gt;&amp;nbsp;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;strong&gt;????&amp;gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;Thank you for your help.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;Kind regards&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;Mohamed&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366848?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 07:56:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:158b88a8-b55c-47df-801f-d69f3770e801</guid><dc:creator>user7377</dc:creator><description>[quote user="Learner"]Can I use the same code snippet with other Soc version e.g. QDAAA0?[/quote]
&lt;p&gt;If you refer to the code snippet to write to flash, then yes. Writing to flash (including the UICR) is the same for all revisions. (As mentioned&amp;nbsp;&lt;em&gt;deleting&lt;/em&gt; the UICR page is special though, as it can only be done with a full chip erase).&lt;/p&gt;
[quote user="Learner"]Also, when I use nRF Programmer v2.3.3 to flash the same debug version of the firmware merged.hex the UICR content&amp;nbsp;gets erased. However, when I use &lt;span&gt;SES Nordic Edition v5.60 to flash the same&amp;nbsp;debug version&amp;nbsp;merged.hex the content of the UICR is preserved.&lt;/span&gt;[/quote]
&lt;p&gt;The nRF Connect Programmer version &amp;gt;= 2.0.0 unfortunately&amp;nbsp;always does an erase on write, and this is a full chip erase and not a sector erase (erasing only sectors to be writtne to). This has been reported, but is unfortunately the case at the moment. So you must use another tool in order to program without erasing the whole chip (including the UICR). A simple tool for this is &lt;a href="https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools/download"&gt;nrfjprog&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366846?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 07:46:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4b3bf46-cc76-4830-b625-4879ebba7f0f</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Yes, that is correct. Writing to flash can only flip bits from &amp;#39;1&amp;#39; to &amp;#39;0&amp;#39;. This is an inherent property of flash technology and applies to all flash memory (not just on Nordic products).&lt;/p&gt;
&lt;p&gt;To change bits from &amp;#39;0&amp;#39; to &amp;#39;1&amp;#39; you need to erase the page.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366811?ContentTypeID=1</link><pubDate>Sun, 08 May 2022 12:18:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3befd5ad-1f42-410c-acb8-a1bc3710f81e</guid><dc:creator>user54487</dc:creator><description>&lt;p&gt;Regarding my statement:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;write to flash can only reset bits.&lt;br /&gt; It is necessary to erase flash to set it to FFFFFFF&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The second part is NOT correct!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Unfortunately&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;NRFJPROG incorrectly&amp;nbsp;requires it see:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/70043/nrfjprog---memwr-0x10001080---val-0x01010101-shouldn-t-fail-second-time" rel="noopener noreferrer" target="_blank"&gt;nrfjprog---memwr-0x10001080---val-0x01010101-shouldn-t-fail-second-time&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/70043/nrfjprog---memwr-0x10001080---val-0x01010101-shouldn-t-fail-second-timehttps://devzone.nordicsemi.com/f/nordic-q-a/70043/nrfjprog---memwr-0x10001080---val-0x01010101-shouldn-t-fail-second-time"&gt;&lt;/a&gt;In fact you could use a &amp;quot;counter&amp;quot; (up to 31) by repeatedly clearing bits.&lt;br /&gt;counter =1: 7FFFFFF, &amp;nbsp;counter=2:3FFFFFFF, counter=3 :1FFFFFFF, =4:0FFFFFFF ... =30:00000003, 31:00000001 with no intervening erasures.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;++++++++++++++&lt;/p&gt;
&lt;p&gt;You can use nrfjprog&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;--sectorerase &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;to only erase the area that is being programmed which can preserve UCIR.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366770?ContentTypeID=1</link><pubDate>Fri, 06 May 2022 16:01:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4e1ab00-812e-4e89-bedc-ae5b459b3915</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi Thorsrud,&lt;/span&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/366694#366694"]The code snippet you have seems to match QDAAB0, which has the improved access port mechanism (&lt;a href="https://infocenter.nordicsemi.com/pdf/in_149_v1.1.pdf?cp=18_9"&gt;IN-149&lt;/a&gt;).[/quote]
&lt;p&gt;Can I use the same code snippet with other Soc version e.g. QDAAA0?&lt;/p&gt;
&lt;p&gt;Also, when I use nRF Programmer v2.3.3 to flash the same debug version of the firmware merged.hex the UICR content&amp;nbsp;gets erased. However, when I use &lt;span&gt;SES Nordic Edition v5.60 to flash the same&amp;nbsp;debug version&amp;nbsp;merged.hex the content of the UICR is preserved.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Note, when using nRF Programmer only the &amp;#39;&lt;strong&gt;Erase &amp;amp; write&lt;/strong&gt;&amp;#39; option is available. The &lt;strong&gt;&amp;#39;Write&lt;/strong&gt;&amp;#39; only option is disabled, see attached&amp;nbsp;screen shot below.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://test-devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/nRFProgrammer_5F00_Erase_2600_Write.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366764?ContentTypeID=1</link><pubDate>Fri, 06 May 2022 14:50:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7031ce57-abc3-4add-b46f-a7bd1331b715</guid><dc:creator>user92434</dc:creator><description>&lt;p&gt;Hi Thorsrud,&lt;/p&gt;
&lt;p&gt;Before I try what you suggested I would like you to clarify the statement below.&lt;/p&gt;
[quote userid="54487" url="~/f/nordic-q-a/82409/example-code-to-write-to-uicr/341951#341951"]write to flash can only reset bits. It is necessary to erase flash to set it to FFFFFFF[/quote]
&lt;p&gt;Is the above statement from dgerman correct?&lt;/p&gt;
&lt;p&gt;I see you are not erasing flash in the example code you shared earlier with rmarques.&lt;/p&gt;
&lt;p&gt;Please clarify.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div&gt;Kind regards&lt;/div&gt;
&lt;div&gt;Mohamed&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Example code to write to UICR</title><link>https://test-devzone.nordicsemi.com/thread/366694?ContentTypeID=1</link><pubDate>Fri, 06 May 2022 11:14:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa30a6c5-8e04-4091-a51b-ea6e80024b8e</guid><dc:creator>user7377</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Mohamed,&lt;/p&gt;
[quote user="Learner"]So, in debug mode I should NOT be experiencing this problem, right?[/quote]
&lt;p&gt;I do not know everything you do, but yes: as long as debug port access is enabled, then you can erase and write&amp;nbsp;specific sectors and do not need to do a full chip erase.&lt;/p&gt;
[quote user="Learner"]Also, isn&amp;#39;t the whole purpose of&amp;nbsp;the access port protection is to make sure it is enabled before product deployment?[/quote]
&lt;p&gt;Yes it is. But that also means that debug access is blocked, and to enable it you must do an ERASE ALL (recover), which also erases UICR.&lt;/p&gt;
[quote user="Learner"]We are currently using a mixture of N52833 QDAAB0 and QDAAA0 but ultimately we will be using only revision QDAAB0.[/quote]
&lt;p&gt;I see. The code snippet you have seems to match QDAAB0, which has the improved access port mechanism (&lt;a href="https://infocenter.nordicsemi.com/pdf/in_149_v1.1.pdf?cp=18_9"&gt;IN-149&lt;/a&gt;). With this debugging is disabled by default and you need to disable it by writing to UICR and also writing to&amp;nbsp; NRF_APPROTECT-&amp;gt;DISABLE on every boot. If not, a full erase is needed to be able to debug again.&lt;/p&gt;
&lt;p&gt;Note that it is also so that the only way to erase UICR is to erase the whole flash, so if the UICR is &amp;quot;suddenly&amp;quot; erased it is because the tools you use for some reason do an erase all. The question is why. Can you start by reading data from UICR to see if debug access is enabled and the data is still there? then what exactly do you do when the UICR is erased by the debugger?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>