<?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>nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72536/nrf52832-uicr-serial-number-programming</link><description>In firmware I can read the programmed UICR serial number as follows: - 
 uint32_t serial; 
 memcpy(&amp;amp;serial, (uint32_t*)0x10001080, 4); 
 Is it possible to program the UICR from within the firmware during runtime? 
 Using the reverse - memcpy( (uint32_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Mar 2021 12:03:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72536/nrf52832-uicr-serial-number-programming" /><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/299762?ContentTypeID=1</link><pubDate>Mon, 15 Mar 2021 12:03:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64f12965-787f-4577-a9ee-f01d7481c3c1</guid><dc:creator>ranger3</dc:creator><description>&lt;p&gt;Thanks for your help Einar. It&amp;#39;s working now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/299485?ContentTypeID=1</link><pubDate>Fri, 12 Mar 2021 13:22:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fe6824f-98d7-458c-990b-9cc2f21bc1be</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You need to adjust the code like this (how you enable and disable flash writing):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Enable write mode.
NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Wen;
while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}

// write value to the register
NRF_UICR-&amp;gt;CUSTOMER[0] = serial;

// Disable flash writing
NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren;
while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This works for me when modifying the beacon example in SDK 17.0.2 to test, as shown by this diff:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4747.main.c.diff"&gt;devzone.nordicsemi.com/.../4747.main.c.diff&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/299216?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 11:04:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd8b4d84-4c6e-4838-aa57-a9a9754f20a6</guid><dc:creator>ranger3</dc:creator><description>&lt;p&gt;Thanks for your answer. I&amp;#39;m getting closer now. With the following code: -&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;err_code = sd_softdevice_disable(); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;if( err_code == NRF_SUCCESS )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;// Enable write mode.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Een&amp;lt;&amp;lt;NVMC_CONFIG_WEN_Pos;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;while(NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;// write value to the register&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;NRF_UICR-&amp;gt;CUSTOMER[0] = serial;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;// Disable flash writing&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren&amp;lt;&amp;lt;NVMC_CONFIG_WEN_Pos;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;while(NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;// now reboot the nRF52 - there is no return from this command!&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new, courier;"&gt;&amp;nbsp;NVIC_SystemReset();&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:courier new, courier;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;All steps work, and the device reboots successfully, but the register value has not changed. I have read in other threads that after writing to the UICR and before restarting the softDevice needs to be re-enabled using &lt;span style="font-family:courier new, courier;"&gt;sd_softdevice_enable()&lt;/span&gt;. Is this the case?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/299170?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 08:33:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8323a09-7c84-42dd-9867-4ce546976773</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I thought I would put together an example that demonstrated this, but unfortunately it turns out that writing to the UICR with the SoftDevice enabled is not allowed, which I had forgotten. This has been requested before but it does not look like it will be implemented. So then your only option is to write to UICR with the SoftDevice disabled, or to store your serial number elsewhere in flash. I am sorry for the confusion.&lt;/p&gt;
&lt;p&gt;You use&amp;nbsp;sd_softdevice_disable() to do that, but then you need to include nrf_sdm.h where it is declared. Note that wile disabling the SoftDEvice itself is no problem, most SDK libraries that interface the SoftDevice are not designed to handle the SoftDevice being disabled, so it is not as straight forward as you would think.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/299165?ContentTypeID=1</link><pubDate>Thu, 11 Mar 2021 07:51:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c34c686f-43d3-42a9-96b1-c104138937f1</guid><dc:creator>ranger3</dc:creator><description>&lt;p&gt;Am I also correct in thinking that the soft device needs to be disabled first using sd_softdevice_disable()?&lt;/p&gt;
&lt;p&gt;If so, is that the correct function? I keep getting an &amp;#39;undefined reference to sd_softdevice_disable()&amp;#39; error.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/298841?ContentTypeID=1</link><pubDate>Tue, 09 Mar 2021 19:13:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b625f667-ad8a-4c11-931d-43a9a82c771e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Yes, that is correct. You need to use sd_flash_write() in this case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/298807?ContentTypeID=1</link><pubDate>Tue, 09 Mar 2021 16:25:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fff9cf97-bc65-4b58-bd6f-1ec5aedc30d5</guid><dc:creator>ranger3</dc:creator><description>&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;Just to clarify, during initialisation the firmware retrieves the serial number from address 0x10001080. Then during normal runtime, the new serial is sent over BLE and I need to write that to the same location, so after a reboot the serial is updated. If I understand correctly, then the softdevice is already running so I need to use the sd_flash_write() method?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 UICR serial number programming</title><link>https://devzone.nordicsemi.com/thread/298708?ContentTypeID=1</link><pubDate>Tue, 09 Mar 2021 13:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee3eb623-8062-4ad5-b8bd-26d89c3193d4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, you can program the UICR from firmware. However, this is flash and not RAM, so you need to do it in a different way. If you do it without/before the SoftDevice is enabled, you can do it in the same way as shown in this code snippet from boards.c (just replace the destination address with another part of the UICR):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Wen;
        while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}

        NRF_UICR-&amp;gt;REGOUT0 = (NRF_UICR-&amp;gt;REGOUT0 &amp;amp; ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) |
                            (UICR_REGOUT0_VOUT_3V0 &amp;lt;&amp;lt; UICR_REGOUT0_VOUT_Pos);

        NRF_NVMC-&amp;gt;CONFIG = NVMC_CONFIG_WEN_Ren;
        while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy){}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you need to do this while the SoftDevice is enabled you should use &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v6.1.1/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html?cp=4_7_3_3_2_7_2_9#gae5361e65cbb5e7f6e258947a394c9b55"&gt;sd_flash_write()&lt;/a&gt;&amp;nbsp;instead.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>