<?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>NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55530/nrf52840-cryptocell-register-setting-reading-problem</link><description>I am trying to set the Lifecycle state of the cryptocell, but it seems like I am having an issue. 
 
 I do 
 /** Enable crypto cell to configure it **/ NRF_CRYPTOCELL-&amp;gt;ENABLE = CRYPTOCELL_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; CRYPTOCELL_ENABLE_ENABLE_Pos; /** Config</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Dec 2019 09:58:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55530/nrf52840-cryptocell-register-setting-reading-problem" /><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225566?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 09:58:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b591edaa-5a77-4e08-9c37-cd5653e7c719</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, the documentation for CrytoCell is a bit lacking. This has been reported, so hopefully, it will improve in the future.&lt;/p&gt;
&lt;p&gt;I have a few more details to share.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;CryptoCell must alway be enabled before writing to any of the other registers. This is not explicitly stated in the PS.&lt;/li&gt;
&lt;li&gt;The simple delay approach I used to show that there is a timing dependency is not the best (it might give you a race condition of timing changed due to temperature or something else). Instead, you could try to read back the registers until it has the expected value. (E.g. use &amp;quot;while (NRF_CC_HOST_RGF-&amp;gt;HOST_IOT_LCS != 0x102) {}&amp;quot; after writing to&amp;nbsp;HOST_IOT_LCS).&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225409?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 14:33:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcba9846-ca86-4bc1-816e-4eefeb953dfe</guid><dc:creator>Barry</dc:creator><description>&lt;p&gt;Thanks. This did work. I appreciate the help. Although obviously you guys need more documentation around the cryptocell.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225397?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 14:09:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e824e682-f28a-443d-b70f-af3f1ab3f876</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am not sure about the debugger issues here, nor am I able to find a link between ACL and this. But, there seems to be a requirement here which may be related to what you see.&lt;/p&gt;
&lt;p&gt;Testing your code from the original question the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/cryptocell.html?cp=4_0_0_5_5_7_0_0_6#register.HOST_IOT_LCS"&gt;HOST_IOT_LCS&lt;/a&gt;&amp;nbsp;register will not be set, even if waiting a long time to read it out (it will be 0x00000002). But, adding a delay between writing to&amp;nbsp;ENABLE and&amp;nbsp;HOST_IOT_LCS and before reading it back this works as expected, and&amp;nbsp;HOST_IOT_LCS is read back as&amp;nbsp;0x00000102.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    /** Enable crypto cell to configure it **/
    NRF_CRYPTOCELL-&amp;gt;ENABLE = CRYPTOCELL_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; CRYPTOCELL_ENABLE_ENABLE_Pos;

    nrf_delay_us(1);

    /** Config cryptocell resgister so Device root key can only be set once per reset*/
    NRF_CC_HOST_RGF-&amp;gt;HOST_IOT_LCS = CC_HOST_RGF_HOST_IOT_LCS_LCS_Secure &amp;lt;&amp;lt; CC_HOST_RGF_HOST_IOT_LCS_LCS_Pos;

    nrf_delay_us(1);

    NRF_LOG_INFO(&amp;quot;HOST_IOT_LCS: 0x%08x&amp;quot;, NRF_CC_HOST_RGF-&amp;gt;HOST_IOT_LCS);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225231?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 17:17:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60efd813-bcf0-423e-9f54-de7391f1f74a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, you are right. The documentation is unclear on this.&lt;/p&gt;
&lt;p&gt;And about the original question, it seems you are right on that point tas well.&amp;nbsp; The LCS_IS_VALID is a read-only field, but if you write to it, this will make it 1 regardless of what you write. It is intended to show if LCS is set, which is the only field in HOST_IOT_LCS that should be written to.&lt;/p&gt;
&lt;p&gt;So in short, any writing to any part of the HOST_IOT_LCS register sets the LCS_IS_VALID field to 1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225229?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 17:12:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7e24a4c-ded6-4836-bdaf-eaf36ee006cc</guid><dc:creator>Barry</dc:creator><description>&lt;p&gt;Sorry about so many posts, but I think I have another thing that is contributing to the issue. This code is executing in a bootloader whose partition is from 0 to 0x22000. Another protection I implement in the bootloader is to use ACL[0] to protect the bootloader from writes. I&amp;nbsp;use this code&lt;/p&gt;
&lt;p&gt;NRF_ACL-&amp;gt;ACL[0].ADDR = 0;&lt;br /&gt; NRF_ACL-&amp;gt;ACL[0].PERM = ACL_ACL_PERM_WRITE_Disable &amp;lt;&amp;lt; ACL_ACL_PERM_WRITE_Pos; // 0x2&lt;br /&gt; NRF_ACL-&amp;gt;ACL[0].SIZE = DT_FLASH_AREA_MCUBOOT_SIZE;&amp;nbsp; // this is 0x22000&lt;/p&gt;
&lt;p&gt;When I do this before I write the LCS register, I get the behavior I described in my original post. If I don&amp;#39;t write to this ACL i get he behavior from my second post.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see how this ACL code affects the writing to the&amp;nbsp;NRF_CRYPTOCELL, or&amp;nbsp;NRF_CC_HOST_RGF&lt;/p&gt;
&lt;p&gt;I also notice that if I do the ACL setup before I write the LCS resgister, and I have more than 5 break points set anywhere in the code. Then I try to step past a line in the&amp;nbsp;disassembly that stores a value to either the RF_CRYPTOCELL-&amp;gt;ENABLE register or the NRF_CC_HOST_RGF-&amp;gt;HOST_IOT_LCS register,&amp;nbsp; SES&amp;nbsp;takes a long time and then SES spits out a message saying something like&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;quot;Timeout while erasing sectors, RAMCode did not respond in time. (PC = 0x00000000, CPSR = 0x00000000, LR = 0x01000005)!&lt;br /&gt;Failed to erase sectors.&lt;br /&gt;Programming failed @ address 0x00001A50 (block verification error)&amp;quot;&lt;/p&gt;
&lt;p&gt;Sometimes execution stays at the line&amp;nbsp; and does not execute it, sometimes&amp;nbsp;execution goes past it&lt;/p&gt;
&lt;p&gt;If I have no debug points the code runs fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;These are software breakpoints.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If I remove the ACL protection I can use as many breakpoints as I want and there is no timeout problems.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225202?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 15:03:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f22b983e-8544-4c2e-8051-d8a466b70f82</guid><dc:creator>Barry</dc:creator><description>&lt;p&gt;Also the documentation doesn&amp;#39;t really mention this (I don&amp;#39;t think) but to be clear, if I want to write to or read from&amp;nbsp;CC_HOST_RGF the cryptocell must be enabled correct. It seems that way but I only figured that out by trial and error.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225198?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 14:58:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a94e726-c359-46ea-8955-684c4873dd0e</guid><dc:creator>Barry</dc:creator><description>&lt;p&gt;I think maybe the issue is fixed. But I&amp;#39;m not sure. The behavior seems to depend how I debug.&lt;/p&gt;
&lt;p&gt;First I changed one thing. I was doing this register setting before the flash device was initialized. So I changed it to happen after (not really related to this register setting but for something else I am doing in the same function).&lt;/p&gt;
&lt;p&gt;Now when I set the register, it still goes fine&amp;nbsp;&lt;span&gt;LCS_IS_VALID is 1 and LCS is 2 (I see that after I set the register but before I disable). Then when I enable the cryptocell again if I step my debugger through the lines (shown in my original post) where I set the register I&lt;/span&gt;&amp;nbsp;see&amp;nbsp;&lt;span&gt;LCS_IS_VALID is 1 and LCS is 2 in the register. But if I don&amp;#39;t step my debugger though those lines and later I enable the cryptocell and look at the value of the register&amp;nbsp; in the debuger&amp;nbsp;LCS_IS_VALID is 1 and LCS is 0. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So this is probably just a debugger issue at this point ( I am using nordic connect SES with a J-trace pro). But I&amp;#39;m not sure. I guess the only way to tell for sure will be to encrypt something with the root key then try to change the root key, and encrypt again, and see if the result is the same.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Cryptocell register setting reading problem</title><link>https://devzone.nordicsemi.com/thread/225195?ContentTypeID=1</link><pubDate>Thu, 12 Dec 2019 14:56:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d8f047b-8c6d-4277-a48d-e1fc643d0afc</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;There may be a problem with the LCS_IS_VALID register and/or always-on power domain. We need to look a bit more into this,&amp;nbsp;but I will update you as soon as possible (hopefully tomorrow).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>