<?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 - Zephyr OS - Flash Protection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/78322/nrf52840---zephyr-os---flash-protection</link><description>I&amp;#39;m looking to enable the flash protection for an nRF52 application running on Zephyr RTOS: 
 
 Basically looking to disable flash reads from the JTAG/SWD interface: Only erase or reprogram should be possible. 
 
 My understanding is that this can be</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Aug 2021 13:50:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/78322/nrf52840---zephyr-os---flash-protection" /><item><title>RE: nRF52840 - Zephyr OS - Flash Protection</title><link>https://devzone.nordicsemi.com/thread/325337?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 13:50:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f886912-328b-49e0-9514-7273f441fa8f</guid><dc:creator>SirBranch</dc:creator><description>&lt;p&gt;Thanks for all the help and the following up!&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Zephyr OS - Flash Protection</title><link>https://devzone.nordicsemi.com/thread/325255?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 09:52:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13577045-ed97-4184-9132-74721a4c72f4</guid><dc:creator>Sigurd</dc:creator><description>[quote user="SirBranch"]looking forward for when this gets added as a Kconfig![/quote]
&lt;p&gt;&amp;nbsp;A PR have been created for this now.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/pull/37732"&gt;https://github.com/zephyrproject-rtos/zephyr/pull/37732&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Zephyr OS - Flash Protection</title><link>https://devzone.nordicsemi.com/thread/324522?ContentTypeID=1</link><pubDate>Wed, 11 Aug 2021 14:19:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bb0fe33-c098-4dcb-a0c9-26726f4ef825</guid><dc:creator>SirBranch</dc:creator><description>&lt;p&gt;Thanks for the insight, much appreciated!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll look into getting that to run on Zephyr using the HAL, looking forward for when this gets added as a Kconfig!&lt;/p&gt;
&lt;p&gt;Thanks for the help&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Zephyr OS - Flash Protection</title><link>https://devzone.nordicsemi.com/thread/324298?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 15:10:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09564032-db7c-45ad-b0cd-87d414c30aa8</guid><dc:creator>Sigurd</dc:creator><description>[quote user=""]Any insight into how to achieve this on Zephyr RTOS would be greatly appreciated.[/quote]
&lt;p&gt;&amp;nbsp;There are no Kconfig or similar in Zephyr for this, but we are looking into adding this.&lt;/p&gt;
&lt;p&gt;Here are some code on how to enable it:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void nrf_bootloader_debug_port_disable(void)
{
    if (NRF_UICR-&amp;gt;APPROTECT != 0x0)
    {
        nrf_nvmc_write_word((uint32_t)&amp;amp;NRF_UICR-&amp;gt;APPROTECT, 0x0);
        NVIC_SystemReset();
    }
#if (!defined (NRF52810_XXAA) &amp;amp;&amp;amp; !defined (NRF52811_XXAA) &amp;amp;&amp;amp; !defined (NRF52832_XXAA) &amp;amp;&amp;amp; !defined (NRF52832_XXAB))
    if (NRF_UICR-&amp;gt;DEBUGCTRL != 0x0)
    {
        nrf_nvmc_write_word((uint32_t)&amp;amp;NRF_UICR-&amp;gt;DEBUGCTRL, 0x0);
        NVIC_SystemReset();
    }
#endif
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - Zephyr OS - Flash Protection</title><link>https://devzone.nordicsemi.com/thread/324052?ContentTypeID=1</link><pubDate>Mon, 09 Aug 2021 14:19:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a0106b4-b372-4432-97a9-9f2e8fed433d</guid><dc:creator>SirBranch</dc:creator><description>&lt;p&gt;To provide an update on the state of this ticket:&lt;/p&gt;
&lt;p&gt;I&amp;#39;m currently able to protect with the known nrfjprog command:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="batchfile"&gt;nrfjprog --rbp ALL -f NRF52&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But I&amp;#39;m looking for a way to do this from the application code. I&amp;#39;ve set CONFIG_SOC_FLASH_NRF_UICR=y from the bootloader configuration as well as application and I&amp;#39;m currently able to read in run time using:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_UICR-&amp;gt;APPROTECT&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But this reference doesn&amp;#39;t seem to allow for writing or clearing. I&amp;#39;ve tried using the flash API&amp;nbsp;in the following manner to read/write&amp;nbsp;but no success in even being able to read:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define PER_UICR 0x10001000UL
#define UICR_REG_APPROTECT 0x208UL

void uicr_reg_approtect_read(void){

	const struct device* flash_dev = device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL);
    uint32_t reg_approtect = 0UL;

    if (flash_dev == NULL) {
        LOG_ERR(&amp;quot;Nordic nRF52 flash driver was not found!\n&amp;quot;);
        return;
    }  // Check status

    LOG_WRN(&amp;quot;Found flash controller %s&amp;quot;, log_strdup(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL));

    err = flash_read(flash_dev, PER_UICR + UICR_REG_APPROTECT, &amp;amp;reg_approtect, sizeof(uint32_t));

    if (err != 0) {
        LOG_WRN(&amp;quot;Flash read of REG_APPROTECT failed! %d\n&amp;quot;, err);
    } else {
        LOG_WRN(&amp;quot;UICR - REG_APPROTECT 0x%X&amp;quot;, reg_approtect);
    }

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>