<?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>Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46400/is-it-possibl-that-re-write-uicr-when-application-is-running-if-yes-how-to-do-this</link><description>SDK 15.3.0 
 I want to save some user data in UICR , this data will change when application runing. How to re-write the data into UICR. 
 I assume that the UICR will not be erased by DFU, am I right ?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 22 Apr 2019 05:52:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46400/is-it-possibl-that-re-write-uicr-when-application-is-running-if-yes-how-to-do-this" /><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182919?ContentTypeID=1</link><pubDate>Mon, 22 Apr 2019 05:52:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ada8d2f-332e-491f-8810-5f14e50624c3</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;The bootloader will just not erase the last two pages (by default). This is defined in sdk_config.h, you would have to take a look at the code to understand how this happens, as I don&amp;#39;t know the mechanisms by heart.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182915?ContentTypeID=1</link><pubDate>Mon, 22 Apr 2019 02:41:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00eb1e79-c5f9-401d-ae2a-f3b045b6946f</guid><dc:creator>BRN</dc:creator><description>&lt;p&gt;I took a look at the FDS, seems it is beyond my understanding, but I found a example to write flash.&lt;/p&gt;
&lt;p&gt;my concern is &amp;quot; how to make sure the data won&amp;#39;t be erased by DFU?&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182860?ContentTypeID=1</link><pubDate>Sat, 20 Apr 2019 09:07:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db55c507-8005-45db-96ff-6db440a885a0</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;As I said, take a look at the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_fds.html"&gt;FDS library&lt;/a&gt;. It implements a very simple file system that already takes care of load balancing, identification and&amp;nbsp;deletion for you. The fstorage library is a simple API to access RAW data in flash, it doesn&amp;#39;t cut it to constantly update a single uint32 in flash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182859?ContentTypeID=1</link><pubDate>Sat, 20 Apr 2019 09:00:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c6825d9-ed86-4c80-9608-e0cb0ee236a3</guid><dc:creator>BRN</dc:creator><description>&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;I found there is DEFINE named &amp;quot;DFU_APP_DATA_RESERED&amp;quot; in bootloader example code, according to the comments, seems this flash area is for saving application&amp;#39;s data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;all I have to do is write my user data to this flash area. this area is 8k size, the bootloader rom is from 0x28000, therefor this DFU_APP_DATA area is from 0x26000 to 0x27FFF.&lt;/p&gt;
&lt;p&gt;I used nrf_storage function to write data to 0x26000, but when I called&amp;nbsp; the flash write, the system got stucked.&lt;/p&gt;
&lt;p&gt;I added a Button Event to run below code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;;-----------------------------------------------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;NRF_LOG_INFO(&amp;quot;FLASH WRITE START&amp;quot;);&lt;br /&gt; pairKey = (rcvData[1] &amp;lt;&amp;lt; 24) | (rcvData[2] &amp;lt;&amp;lt; 16) | (rcvData[3] &amp;lt;&amp;lt; 8) | (rcvData[1]);&lt;br /&gt; nrf_fstorage_api_t * p_fs_api; &lt;br /&gt; p_fs_api = &amp;amp;nrf_fstorage_sd; &lt;br /&gt; err_code = nrf_fstorage_init(&amp;amp;fstorage, p_fs_api, NULL);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; (void) nrf5_flash_end_addr_get();&lt;br /&gt; err_code = nrf_fstorage_write(&amp;amp;fstorage, 0x26000, &amp;amp;pairKey, sizeof(pairKey), NULL);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; wait_for_flash_ready(&amp;amp;fstorage);&lt;br /&gt; NRF_LOG_INFO(&amp;quot;FLASH WRITE DONE&amp;quot;);&lt;/p&gt;
&lt;p&gt;;------------------------------------------------------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;Related define for above code:&lt;/p&gt;
&lt;p&gt;static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =&lt;br /&gt;{&lt;br /&gt; /* Set a handler for fstorage events. */&lt;br /&gt; .evt_handler = fstorage_evt_handler,&lt;/p&gt;
&lt;p&gt;/* These below are the boundaries of the flash space assigned to this instance of fstorage.&lt;br /&gt; * You must set these manually, even at runtime, before nrf_fstorage_init() is called.&lt;br /&gt; * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the&lt;br /&gt; * last page of flash available to write data. */&lt;br /&gt; .start_addr = 0x26000,&lt;br /&gt; .end_addr = 0x27FFF,&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;/* Dummy data to write to flash. */&lt;br /&gt;static uint32_t pairKey;&lt;/p&gt;
&lt;p&gt;static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt)&lt;br /&gt;{&lt;br /&gt; if (p_evt-&amp;gt;result != NRF_SUCCESS)&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: ERROR while executing an fstorage operation.&amp;quot;);&lt;br /&gt; return;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;switch (p_evt-&amp;gt;id)&lt;br /&gt; {&lt;br /&gt; case NRF_FSTORAGE_EVT_WRITE_RESULT:&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: wrote %d bytes at address 0x%x.&amp;quot;,&lt;br /&gt; p_evt-&amp;gt;len, p_evt-&amp;gt;addr);&lt;br /&gt; } break;&lt;/p&gt;
&lt;p&gt;case NRF_FSTORAGE_EVT_ERASE_RESULT:&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: erased %d page from address 0x%x.&amp;quot;,&lt;br /&gt; p_evt-&amp;gt;len, p_evt-&amp;gt;addr);&lt;br /&gt; } break;&lt;/p&gt;
&lt;p&gt;default:&lt;br /&gt; break;&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;static uint32_t nrf5_flash_end_addr_get()&lt;br /&gt;{&lt;br /&gt; uint32_t const bootloader_addr = NRF_UICR-&amp;gt;NRFFW[0];&lt;br /&gt; uint32_t const page_sz = NRF_FICR-&amp;gt;CODEPAGESIZE;&lt;br /&gt; uint32_t const code_sz = NRF_FICR-&amp;gt;CODESIZE;&lt;/p&gt;
&lt;p&gt;return (bootloader_addr != 0xFFFFFFFF ?&lt;br /&gt; bootloader_addr : (code_sz * page_sz));&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void wait_for_flash_ready(nrf_fstorage_t const * p_fstorage)&lt;br /&gt;{&lt;br /&gt; /* While fstorage is busy, sleep and wait for an event. */&lt;br /&gt; while (nrf_fstorage_is_busy(p_fstorage))&lt;br /&gt; {&lt;br /&gt; sd_app_evt_wait();&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182858?ContentTypeID=1</link><pubDate>Sat, 20 Apr 2019 08:56:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0aff1030-60fd-40bc-bb44-e2949d18f665</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;How to properly post source code:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/8308._5F00_Insert-Code-_2D00_-Nordic.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182856?ContentTypeID=1</link><pubDate>Sat, 20 Apr 2019 08:50:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:debfbbc3-4ac2-4c05-8d2a-475135265dd0</guid><dc:creator>BRN</dc:creator><description>&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;I found a DEFINE named &amp;quot;DFU_APP_DATA_RESERVED&amp;quot; in bootloader code, according to the code comments, seems this flash area is for saving application data.&lt;/p&gt;
&lt;p&gt;this area is 8k byes, the bootloader is start from 0x28000, therefor, this DFU_APP_DATA is from 0x26000 to 0x27FFF.&lt;/p&gt;
&lt;p&gt;I assumed that all I have to is just use nrf_fstorage.c &amp;#39;s function to write my user data to 0x26000.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I added a button event to run below code, but it seems the system is stucked when run it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Please help !&lt;/p&gt;
&lt;p&gt;;----------------------------------------------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;NRF_LOG_INFO(&amp;quot;FLASH WRITE START&amp;quot;);&lt;br /&gt; pairKey = (rcvData[1] &amp;lt;&amp;lt; 24) | (rcvData[2] &amp;lt;&amp;lt; 16) | (rcvData[3] &amp;lt;&amp;lt; 8) | (rcvData[1]);&lt;br /&gt; nrf_fstorage_api_t * p_fs_api; &lt;br /&gt; p_fs_api = &amp;amp;nrf_fstorage_sd; &lt;br /&gt; err_code = nrf_fstorage_init(&amp;amp;fstorage, p_fs_api, NULL);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; (void) nrf5_flash_end_addr_get();&lt;br /&gt; err_code = nrf_fstorage_write(&amp;amp;fstorage, 0x26000, &amp;amp;pairKey, sizeof(pairKey), NULL);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; wait_for_flash_ready(&amp;amp;fstorage);&lt;br /&gt; NRF_LOG_INFO(&amp;quot;FLASH WRITE DONE&amp;quot;);&lt;/p&gt;
&lt;p&gt;;---------------------------------------------------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;BELOW LINES ARE related define.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =&lt;br /&gt;{&lt;br /&gt; /* Set a handler for fstorage events. */&lt;br /&gt; .evt_handler = fstorage_evt_handler,&lt;/p&gt;
&lt;p&gt;/* These below are the boundaries of the flash space assigned to this instance of fstorage.&lt;br /&gt; * You must set these manually, even at runtime, before nrf_fstorage_init() is called.&lt;br /&gt; * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the&lt;br /&gt; * last page of flash available to write data. */&lt;br /&gt; .start_addr = 0x26000,&lt;br /&gt; .end_addr = 0x27FFF,&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;/* Dummy data to write to flash. */&lt;br /&gt;static uint32_t pairKey;&lt;/p&gt;
&lt;p&gt;static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt)&lt;br /&gt;{&lt;br /&gt; if (p_evt-&amp;gt;result != NRF_SUCCESS)&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: ERROR while executing an fstorage operation.&amp;quot;);&lt;br /&gt; return;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;switch (p_evt-&amp;gt;id)&lt;br /&gt; {&lt;br /&gt; case NRF_FSTORAGE_EVT_WRITE_RESULT:&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: wrote %d bytes at address 0x%x.&amp;quot;,&lt;br /&gt; p_evt-&amp;gt;len, p_evt-&amp;gt;addr);&lt;br /&gt; } break;&lt;/p&gt;
&lt;p&gt;case NRF_FSTORAGE_EVT_ERASE_RESULT:&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: erased %d page from address 0x%x.&amp;quot;,&lt;br /&gt; p_evt-&amp;gt;len, p_evt-&amp;gt;addr);&lt;br /&gt; } break;&lt;/p&gt;
&lt;p&gt;default:&lt;br /&gt; break;&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;static uint32_t nrf5_flash_end_addr_get()&lt;br /&gt;{&lt;br /&gt; uint32_t const bootloader_addr = NRF_UICR-&amp;gt;NRFFW[0];&lt;br /&gt; uint32_t const page_sz = NRF_FICR-&amp;gt;CODEPAGESIZE;&lt;br /&gt; uint32_t const code_sz = NRF_FICR-&amp;gt;CODESIZE;&lt;/p&gt;
&lt;p&gt;return (bootloader_addr != 0xFFFFFFFF ?&lt;br /&gt; bootloader_addr : (code_sz * page_sz));&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void wait_for_flash_ready(nrf_fstorage_t const * p_fstorage)&lt;br /&gt;{&lt;br /&gt; /* While fstorage is busy, sleep and wait for an event. */&lt;br /&gt; while (nrf_fstorage_is_busy(p_fstorage))&lt;br /&gt; {&lt;br /&gt; sd_app_evt_wait();&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possibl that re-write UICR when application is running? if yes, how to do this.</title><link>https://devzone.nordicsemi.com/thread/182814?ContentTypeID=1</link><pubDate>Fri, 19 Apr 2019 12:37:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31451165-c169-447d-80ac-1b8d9c254f7e</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;If you need to store and update variables in flash I&amp;rsquo;d advise you to use the FDS module. UICR is not the way to go for the functionality you need, unless you need to update the UICR only once (during production flashing for example).&lt;/p&gt;
&lt;p&gt;And UICR is not erased by DFU. You need to do a full chip erase for that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>