<?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>How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80830/how-can-i-read-the-uicr-register-of-9160</link><description>The current project needs to save the ID in the programmable register and use the ID in the application image. 
 So I save the ID number in the URCI-&amp;gt;OTP[0] register. When I read the ID in URCI-&amp;gt;OTP[0] in the main function of the application image , a</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 25 Jul 2022 10:59:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80830/how-can-i-read-the-uicr-register-of-9160" /><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/378514?ContentTypeID=1</link><pubDate>Mon, 25 Jul 2022 10:59:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8ea02e8-ced6-4f1e-b26a-af340f7fc0b3</guid><dc:creator>flaik-wayne</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/xinjiang"&gt;xinjiang&lt;/a&gt; - the problem is that OTP memory must be read in 32 bit words. Simply adding the OTP memory to the `ranges` in spm_request_read_nse isn&amp;#39;t enough - I used code like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;__TZ_NONSECURE_ENTRY_FUNC
int spm_request_read_nse(void *destination, uint32_t addr, size_t len)
{
	static const struct read_range ranges[] = {

#ifdef PM_MCUBOOT_ADDRESS
		/* Allow reads of mcuboot metadata */
		{.start = PM_MCUBOOT_PAD_ADDRESS,
		 .size = PM_MCUBOOT_PAD_SIZE},
#endif
		{.start = FICR_INFO_ADDR,
		 .size = FICR_INFO_SIZE},
#if defined(FICR_NFC_TAGHEADER0_MFGID_Msk)
		{.start = FICR_NFC_ADDR,
		 .size = FICR_NFC_SIZE},
#endif
		{.start = FICR_RESTRICTED_ADDR,
		 .size = FICR_RESTRICTED_SIZE},

        // Allow reading UICR
        {.start = NRF_UICR_S_BASE,
         .size = 4096},
	};

	if (destination == NULL || len &amp;lt;= 0) {
		return -EINVAL;
	}

	if (ptr_in_secure_area((intptr_t)destination)) {
		return -EINVAL;
	}

	for (size_t i = 0; i &amp;lt; ARRAY_SIZE(ranges); i++) {
		uint32_t start = ranges[i].start;
		uint32_t size = ranges[i].size;

		if (addr &amp;gt;= start &amp;amp;&amp;amp; addr + len &amp;lt;= start + size)
        {
            if ((addr &amp;amp; 3) == 0 &amp;amp;&amp;amp; (len &amp;amp; 3) == 0)
            {
                // use 32 bit copy
                uint32_t *d = destination;
                uint32_t *s = (uint32_t)addr;
                while (len)
                {
                    *d++ = *s++;
                    len -= 4;
                }
            }
            else
            {
			    memcpy(destination, (const void *)addr, len);
            }
			return 0;
		}
	}

	return -EPERM;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/340860?ContentTypeID=1</link><pubDate>Fri, 26 Nov 2021 09:45:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e00ac9bc-220c-4f81-a2db-d887bb879592</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;There was a read function in the code I linked to as well.&lt;/p&gt;
[quote user=""]The current project needs to save the ID in the programmable register and use the ID in the application image.[/quote]
&lt;p&gt;I&amp;#39;m not sure what kind of use-case this ID has, but a potential alterative would be to use the IMEI number instead. You can read it from the modem using a AT command:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/general/cgsn_set.html"&gt;https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/general/cgsn_set.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/340216?ContentTypeID=1</link><pubDate>Tue, 23 Nov 2021 02:19:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fbda9cc-d6c8-4c8e-926f-20c64354da1e</guid><dc:creator>xinjiang</dc:creator><description>&lt;p&gt;This does not tell me how to read the OTP in the app image.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/340166?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 16:00:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15cff0c6-eaea-426a-9ba0-bf75cff9006d</guid><dc:creator>Sigurd</dc:creator><description>[quote user="xinjiang"] Do you have access to the OTP demo?[/quote]
&lt;p&gt;No.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="xinjiang"]I didn&amp;#39;t find a way to access OTP.[/quote]
&lt;p&gt;But this code shows you how our bootloader writes to OTP:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/subsys/bootloader/bl_storage/bl_storage.c#L205"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.7.1/subsys/bootloader/bl_storage/bl_storage.c#L205&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/339002?ContentTypeID=1</link><pubDate>Mon, 15 Nov 2021 11:53:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0fd9240-c8c7-4402-be22-67b97c2e543f</guid><dc:creator>xinjiang</dc:creator><description>&lt;p&gt;Today I read the link you gave, and I didn&amp;#39;t find a way to access OTP. After writing 0x01 to NRF_KMU_NS-&amp;gt;TASKS_PUSH_KEYSLOT, the operation NRF_KMU_NS-&amp;gt;SELECTKEYSLOT is also invalid. Do you have access to the OTP demo?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/335431?ContentTypeID=1</link><pubDate>Fri, 22 Oct 2021 09:14:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7f456a4-5214-4d1d-8e2f-797ed7c59afc</guid><dc:creator>Sigurd</dc:creator><description>[quote user="xinjiang"]0xDEADDEAD[/quote]
&lt;p&gt;This indicates that you don&amp;#39;t have&amp;nbsp;&lt;span&gt;permission to read it. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;See these links:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/uicr.html#register.KEYSLOT.CONFIG.PERM"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf9160/uicr.html#register.KEYSLOT.CONFIG.PERM&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/kmu.html"&gt;infocenter.nordicsemi.com/.../kmu.html&lt;/a&gt;&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: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/335382?ContentTypeID=1</link><pubDate>Fri, 22 Oct 2021 02:12:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e97970d1-330b-4df7-86bc-5813dc4b2e48</guid><dc:creator>xinjiang</dc:creator><description>&lt;p&gt;Thank you very much for your method, I can already read the UICR register, but getting the value of UICR-&amp;gt;OTP[0] is wrong. I write 0x12345678 to UICR-&amp;gt;OTP[0], but it reads 0xDEADDEAD. The specification says that the register is readable. What is the problem?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1634868669473v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1634868718978v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/335296?ContentTypeID=1</link><pubDate>Thu, 21 Oct 2021 12:05:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b3946d5-d6f3-4c3a-907a-328b0ac24995</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Just modify the file in found in subsys/spm/secure_services.c&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/335169?ContentTypeID=1</link><pubDate>Thu, 21 Oct 2021 02:19:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81a9862d-bf65-41b3-8797-c0c131fcefc8</guid><dc:creator>xinjiang</dc:creator><description>&lt;p&gt;I did not find secure_services.c under the secure_services demo. According to the macro configuration, the file should be imported, but the actual situation is the opposite.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;secure_services demo:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1634782331278v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;nrf/subsys/spm/Kconfig:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1634782424759v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;nrf/subsys/spm/CMakeLists.txt:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1634782461650v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;When I tried to add CONFIG_SPM to spm, a fatal error occurred: CONFIG_SPM and CONFIG_IS_SPM conflict. Do I modify secure_services.c in spm image or modify it in app image?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/335079?ContentTypeID=1</link><pubDate>Wed, 20 Oct 2021 11:53:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:608bf0a1-08e1-417c-9336-68eff34932a0</guid><dc:creator>Sigurd</dc:creator><description>[quote user="xinjiang"]How can I solve this problem?[/quote]
&lt;p&gt;I see now that UICR is not in the allowed read range:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.7.0/subsys/spm/secure_services.c#L73"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.7.0/subsys/spm/secure_services.c#L73&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So you need to append some this like this to the&amp;nbsp;&lt;span&gt;ranges array, so it looks something like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;	static const struct read_range ranges[] = {
#ifdef PM_MCUBOOT_ADDRESS
		/* Allow reads of mcuboot metadata */
		{.start = PM_MCUBOOT_PAD_ADDRESS,
		 .size = PM_MCUBOOT_PAD_SIZE},
#endif
		{.start = FICR_PUBLIC_ADDR,
		 .size = FICR_PUBLIC_SIZE},
		{.start = FICR_RESTRICTED_ADDR,
		 .size = FICR_RESTRICTED_SIZE},
		{.start = NRF_UICR_S_BASE+0x108, //OTP[0] address
		 .size = 0x4},
	};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/334963?ContentTypeID=1</link><pubDate>Wed, 20 Oct 2021 02:19:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4619b627-d0f1-48d2-991d-d9de933a2890</guid><dc:creator>xinjiang</dc:creator><description>&lt;p&gt;I imitated the method of reading the FICR register in secure services to read the UICR register. The spm_request_read() function returns error code -1. How can I solve this problem?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static int read_uicr_word(uint32_t *result, const volatile uint32_t *addr)
{
	printk(&amp;quot;Read UICR (address 0x%08x):\n&amp;quot;, (uint32_t)addr);
	int ret = spm_request_read(result, (uint32_t)addr, sizeof(uint32_t));

	if (ret != 0) {
		printk(&amp;quot;Could not read UICR (err: %d)\n&amp;quot;, ret);
	}
	return ret;
}
void main(void)
{
    uint32_t uicr_info;
    if(read_uicr_word(&amp;amp;ficr_info, &amp;amp;NRF_UICR_S-&amp;gt;OTP[0]) == 0) {
	    printk(&amp;quot;UICR = 0x%08X\n\n&amp;quot;, uicr_info);        
    }
    
	printk(&amp;quot;Reboot in %d seconds.\n&amp;quot;, sleep_time_s);
	k_sleep(K_SECONDS(5));

	sys_reboot(0); /* Argument is ignored. */    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Log:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Read UICR (address 0x00ff8108):
Could not read UICR (err: -1)
Reboot in 5 seconds.&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I read the UICR register of 9160?</title><link>https://devzone.nordicsemi.com/thread/334945?ContentTypeID=1</link><pubDate>Tue, 19 Oct 2021 17:21:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68dae852-79f8-41f7-acde-fdf78cd7e300</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]How can I pass the ID to the application image(not via flash)?[/quote]
&lt;p&gt;If you want to read the UICR (or FICR) from the application, you need to use secure services.&lt;/p&gt;
&lt;p&gt;See this sample:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/samples/nrf9160/secure_services/src/main.c"&gt;https://github.com/nrfconnect/sdk-nrf/blob/master/samples/nrf9160/secure_services/src/main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.0/nrf/samples/nrf9160/secure_services/README.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.0/nrf/samples/nrf9160/secure_services/README.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>