<?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>Read values of UICR in Application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103981/read-values-of-uicr-in-application</link><description>Hi, 
 I am trying to read the value of the UICR register CUSTOMER[4] during the runtime of the application. Therefore, I am using the following code: 
 nrf_fstorage_read(&amp;amp;m_fs, (0x10001090), &amp;amp;destination, 32); 
 Where m_fs is the storage instance and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Sep 2023 14:23:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103981/read-values-of-uicr-in-application" /><item><title>RE: Read values of UICR in Application</title><link>https://devzone.nordicsemi.com/thread/447116?ContentTypeID=1</link><pubDate>Thu, 21 Sep 2023 14:23:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a99a142-58f1-48d9-ae19-c4beda33f68b</guid><dc:creator>Simon_89</dc:creator><description>&lt;p&gt;Hi Einar&lt;/p&gt;
&lt;p&gt;Thank you very much for the perfect answer, that solved the issue!&lt;/p&gt;
&lt;p&gt;Could that be integrated into the official documentation? This one is only referring to writing, but I could not find anything referring to reading...&lt;/p&gt;
&lt;p&gt;Thanks,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read values of UICR in Application</title><link>https://devzone.nordicsemi.com/thread/447000?ContentTypeID=1</link><pubDate>Thu, 21 Sep 2023 08:48:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10d100e4-3665-4382-b4a3-67b6008a36bb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You cannot use fstorage in this case.&amp;nbsp;To read data from the UICR (or any other fixed address in flash for that matter), just&amp;nbsp;read it directly. Example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t reg_val = *(volatile uint32_t *) 0x10001090;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here, the content of&amp;nbsp;&lt;span&gt;CUSTOMER[4] will be copied to the variable reg_val. You could also make a pointer and use that. For example, like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;volatile uint32_t * p_my_uicr_reg = (volatile uint32_t *) 0x10001090;
NRF_LOG_INFO(&amp;quot;Val: %08X&amp;quot;, *p_my_uicr_reg);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read values of UICR in Application</title><link>https://devzone.nordicsemi.com/thread/446943?ContentTypeID=1</link><pubDate>Wed, 20 Sep 2023 16:13:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e27bd314-1655-4ca4-a7e5-a330151f10dc</guid><dc:creator>JamesDougherty</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;No worries, I&amp;#39;ll leave that there just in case someone asks about it and is using Zephyr / nRF Connect SDK.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read values of UICR in Application</title><link>https://devzone.nordicsemi.com/thread/446942?ContentTypeID=1</link><pubDate>Wed, 20 Sep 2023 16:11:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27f09041-9a4b-4022-9714-13b9103438ae</guid><dc:creator>Simon_89</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry, I&amp;#39;m still using the old framework, nrf5 sdk for thread and zigbee which in our case is used together with FreeRTOS&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read values of UICR in Application</title><link>https://devzone.nordicsemi.com/thread/446940?ContentTypeID=1</link><pubDate>Wed, 20 Sep 2023 16:06:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03cadb67-d21a-4ebf-9657-dcf61afe5b27</guid><dc:creator>JamesDougherty</dc:creator><description>&lt;p&gt;Are you using Zephyr? Here is how I did it in Zephyr. Hopefully it helps some.&lt;/p&gt;
&lt;p&gt;I have an enum to easily select which UICR value I want to interact with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef enum flash_uicr_register {
    fur_01,
    fur_02,
    ...
    fur_30,
    fur_31,
    fur_32,
} flash_uicr_register_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then I wrote a simple helper function to easily compute the offsets:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static off_t compute_uicr_offset(const flash_uicr_register_t uicr_register)
{
    //
    // The UICR base address is 0x10001000
    // The UICR registers start at 0x080
    //
    // This calculation calculates the offset based off of the passed in register ordinal.
    //
    // Examples:
    //     fur_01: 0x10001000 + (0x080 + (0 &amp;lt;&amp;lt; 2)) = 0x10001080 (0x080)
    //     fur_02: 0x10001000 + (0x080 + (1 &amp;lt;&amp;lt; 2)) = 0x10001084 (0x084)
    //     fur_nn: ...
    //     fur_31: 0x10001000 + (0x080 + (30 &amp;lt;&amp;lt; 2)) = 0x100010F8 (0x0F8)
    //     fur_32: 0x10001000 + (0x080 + (31 &amp;lt;&amp;lt; 2)) = 0x100010FC (0x0FC)
    //
    // See: https://infocenter.nordicsemi.com/topic/ps_nrf52840/uicr.html
    //

    return (off_t)NRF_UICR + (0x080 + (uicr_register &amp;lt;&amp;lt; 2));
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then I use the Zephyr&amp;#39;s flash driver to interact with it. Here is a simplified version:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t flash_read_uicr(const flash_uicr_register_t uicr_register)
{
    __ASSERT_NO_MSG(uicr_register &amp;gt;= fur_01 &amp;amp;&amp;amp; uicr_register &amp;lt;= fur_32);

    static uint32_t value = 0;

    int error = flash_read(mDevice, compute_uicr_offset(uicr_register), &amp;amp;value, sizeof(uint32_t));

    if (error != 0)
    {
        LOG_FLASH_E(&amp;quot;Error reading from the UICR (Error: %d - %s)&amp;quot;, error, errno_to_str(error));
        return false;
    }

    return value;
}

bool flash_write_uicr(const flash_uicr_register_t uicr_register, const uint32_t value)
{
    __ASSERT_NO_MSG(uicr_register &amp;gt;= fur_01 &amp;amp;&amp;amp; uicr_register &amp;lt;= fur_32);

    int error = flash_write(mDevice, compute_uicr_offset(uicr_register), &amp;amp;value, sizeof(uint32_t));

    if (error != 0)
    {
        LOG_FLASH_E(&amp;quot;Error writing to the UICR (Error: %d - %s)&amp;quot;, error, errno_to_str(error));
        return false;
    }

    return true;
}

bool flash_write_verify_uicr(const flash_uicr_register_t uicr_register, const uint32_t value)
{
    return flash_write_uicr(uicr_register, value) &amp;amp;&amp;amp;
           flash_read_uicr(uicr_register) == value;
}

bool flash_erase_uicr(void)
{
    int error = flash_erase(mDevice, (off_t)NRF_UICR, sizeof(*NRF_UICR));

    if (error != 0)
    {
        LOG_FLASH_E(&amp;quot;Error erasing the UICR memory (Error: %d - %s)&amp;quot;, error, errno_to_str(error));
        return false;
    }

    return true;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is what mDevice is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const struct device *const mDevice = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>