<?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>Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11781/writing-to-uicr-from-application-code</link><description>Hello, 
 I am truing to store data in the UICR register &amp;quot;customer area&amp;quot; from application code. The procedure is invoked only once when the registers are still empty. The code is as follows: 
 void write_to_uicr()
{
 uint32_t data_to_write;

 uint32_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Mar 2016 09:10:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11781/writing-to-uicr-from-application-code" /><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44545?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 09:10:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b042e4b6-a63a-4e9a-b582-869c5f60fc90</guid><dc:creator>GT</dc:creator><description>&lt;p&gt;Thanks for the help RK! You were right my code was righting to the same memory location twice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44544?ContentTypeID=1</link><pubDate>Tue, 09 Feb 2016 11:15:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ea34140-c99e-4f91-951f-8645e44596ab</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Down to guesswork at this point. If the value is correct after the write, then the next logical guess is that you&amp;#39;re writing it again somewhere else, either before the chip power cycles or straight afterwards, and putting in a different value. 0x0000220 is what you would get if you wrote 0x00001234 followed by 0x22222222, sure you&amp;#39;re not doing that?&lt;/p&gt;
&lt;p&gt;Can you set a memory write breakpoint at that address, segger supports those, which should tell you if you or something else writes there again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44543?ContentTypeID=1</link><pubDate>Tue, 09 Feb 2016 11:06:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c92f038-1802-42fd-9d13-22e91885a619</guid><dc:creator>GT</dc:creator><description>&lt;p&gt;I am adding more details related to the problem in this post. In general the code that I am debugging is in two files. The first file contains a variable which is retrieved and stored in the UICR from the second file.&lt;/p&gt;
&lt;p&gt;Data provider (provider.c):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; ...
static uint32_t data;
...

uint32_t get_data(void)
{
    return data;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;UICR write (write.c)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;...
extern uint32_t get_data(void);
...
static void update_uicr_customer_data()
{
    data = get_data();

    if(data != 0){
        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){}
        *(uint32_t *)0x10001080 = data;
        NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos;
        while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}
    }else
    {
        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){}
        *(uint32_t *)0x10001080 = 0x22222222;
        NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos;
        while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the debugger I can verify that the content of the &amp;quot;data&amp;quot; variable is &amp;quot;1234&amp;quot; after the function returns and this is what I expect to get as a result. Then the if statement is executed. The else is there just to prove that data != 0.&lt;/p&gt;
&lt;p&gt;The content of the 0x10001080 at this point is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0x10001080: 00001234 FFFFFFFF FFFFFFFF FFFFFFFF
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, after a power-cycle of the chip the content of the memory location reads back as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0x10001080: 00000220 FFFFFFFF FFFFFFFF FFFFFFFF
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Furthermore, if i replace the call to the external function with a call to function in the same file (write.c) the writing procedure goes as expected and the value is preserved after power-cycle.&lt;/p&gt;
&lt;p&gt;It looks like I am doing something wrong, but I was blaming the UICR write...
Do you have comments on this? Thank you in advance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44542?ContentTypeID=1</link><pubDate>Tue, 09 Feb 2016 09:42:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:327467a5-ac6f-4051-8f9e-b7774029ec34</guid><dc:creator>GT</dc:creator><description>&lt;p&gt;I can verify with the debugger that it returns a legal values as expected. I will post another code snippet shortly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44541?ContentTypeID=1</link><pubDate>Tue, 09 Feb 2016 08:24:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a07f182b-0aba-440b-833c-d41d11472aec</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;code&gt;get_data()&lt;/code&gt; seems to be biggest suspect here. I think it is returning 0 then.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44540?ContentTypeID=1</link><pubDate>Mon, 08 Feb 2016 15:59:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e7d1e22-7bfa-4b32-9836-dbd1cbed46b5</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;ok that makes zero sense then. At this point I&amp;#39;d put a breakpoint in the assembler at the point of the store and look at the registers at that level because I can&amp;#39;t think of a reason it wouldn&amp;#39;t work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44539?ContentTypeID=1</link><pubDate>Mon, 08 Feb 2016 13:38:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c19ad305-61aa-47d7-b78c-488a4b38497e</guid><dc:creator>GT</dc:creator><description>&lt;p&gt;The value of the UICR before I try to write to it is 0xFFFFFFFF. This is just after a full erase. However, if I try to write a hard-coded value instead of the content of the &amp;quot;data_to_write&amp;quot; variable, then it works:&lt;code&gt;*(uint32_t *)0x10001080 = 0xAAAA5555&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing to UICR from application code</title><link>https://devzone.nordicsemi.com/thread/44538?ContentTypeID=1</link><pubDate>Mon, 08 Feb 2016 13:28:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14d39713-bbee-4a1a-93eb-555440a23d70</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;What&amp;#39;s the value in 0x10001080 before you do the write? UICR is like flash, it&amp;#39;s non-volatile memory, which means you can only change bits from 1 to 0 in it. Then you have to erase it which sets it all back to 1s again before you can clear the bits again.&lt;/p&gt;
&lt;p&gt;So if it has 0x00000000 in it before you start, that&amp;#39;s all you&amp;#39;re going to get, you can&amp;#39;t set bits back to &amp;#39;1&amp;#39;, nor, I believe can you erase the UICR from within program code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>