<?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>Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53160/write-initial-values-to-flash-during-production</link><description>During production we need to provision each device with some custom data that must last the life time of the device, ideally using nrfjprog. What is the best way to do this? I see there are Customer registers in UICR , but what about writing more than</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Nov 2019 08:37:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53160/write-initial-values-to-flash-during-production" /><item><title>RE: Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/thread/222011?ContentTypeID=1</link><pubDate>Tue, 26 Nov 2019 08:37:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18a93758-17eb-41a0-be3c-fa5a6a6b0d17</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It looks to be correct.&amp;nbsp;Just remember to adjust the NRF_DFU_APP_DATA_AREA_SIZE define in your bootloader project&amp;nbsp;so it corresponds with the total number of flash pages used by FDS (including the reserved page). This will prevent the bootloader from overwriting the data during DFU.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/thread/221816?ContentTypeID=1</link><pubDate>Mon, 25 Nov 2019 10:49:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2763817a-0320-43e7-84c4-1692d721762d</guid><dc:creator>nrbrook</dc:creator><description>&lt;p&gt;I determined that as a whole page must be erased before flash can be written, the fixed address storage size must be a multiple of the page size (0x1000).&lt;/p&gt;
&lt;p&gt;So far I&amp;#39;ve got, in my linker file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;MEMORY
{
    /* MBR_FLASH (rx)        : ORIGIN = 0x00000000, LENGTH = 0x00001000 */
    /* SOFTDEVICE_FLASH (rx) : ORIGIN = 0x00001000, LENGTH = 0x00025000 */

    FLASH (rx)               : ORIGIN = 0x00026000, LENGTH = 0x00051000
    RAM (rwx)                : ORIGIN = 0x20003320, LENGTH = 0x0000cce0

    provisioning_data (rwx)  : ORIGIN = 0x00077000, LENGTH = 0x00001000

    /* BOOTLOADER_FLASH (rx) : ORIGIN 0x00078000, LENGTH = 0x00006000 */
}

SECTIONS
{
  .provisioning_data_block 0x00077000 :
  {
    KEEP(*(.provisioning_data_sect))
  } &amp;gt; provisioning_data
}

...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here I reduced the size of the application flash by 0x1000 and added a new block of data at the end of the application flash. Then I define the section.&lt;/p&gt;
&lt;p&gt;As I&amp;#39;m using FDS, I needed to reserve the flash from being used by FDS in sdk_config.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define FDS_VIRTUAL_PAGES_RESERVED 1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then, in my code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint8_t __attribute__((section (&amp;quot;.provisioning_data_sect&amp;quot;))) m_provisioning_data[0x1000] __attribute__((used));
const uint32_t provisioningStart = 0xA55A5AA5;

...

if(*(uint32_t *)m_provisioning_data != provisioningStart) {
    nrf_nvmc_page_erase(m_provisioning_data);
    nrf_nvmc_write_word(m_provisioning_data, provisioningStart);
}

nrf_nvmc_write_byte(m_provisioning_data + 4, 0xBA);

NRF_LOG_INFO(&amp;quot;0x%08X&amp;quot;, m_provisioning_data);
NRF_LOG_HEXDUMP_INFO(m_provisioning_data, 5)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is this correct so far?&lt;/p&gt;
&lt;p&gt;Is this sufficient to protect the flash from being overwritten by the bootloader etc? I would assume not, since I have not modified any sizes in the (DFU BLE) bootloader. What would I need to modify?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/thread/214672?ContentTypeID=1</link><pubDate>Sat, 12 Oct 2019 15:01:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6740c0f8-e2ea-49c0-8278-49fc74e7ee10</guid><dc:creator>Jimmy Wong</dc:creator><description>&lt;p&gt;HI,&lt;/p&gt;
&lt;p&gt;You can prepare the batch script to write on the UICR through nrfjprog command.&lt;/p&gt;
&lt;p&gt;such as&lt;/p&gt;
&lt;p&gt;&lt;a href="https://jimmywongbluetooth.wordpress.com/2019/09/16/how-to-store-the-custom-address-device-name-and-device-id-on-nrf52-series/"&gt;https://jimmywongbluetooth.wordpress.com/2019/09/16/how-to-store-the-custom-address-device-name-and-device-id-on-nrf52-series/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://jimmywongbluetooth.wordpress.com/2019/08/19/manufacturer-storage-data-on-uicr-region/"&gt;https://jimmywongbluetooth.wordpress.com/2019/08/19/manufacturer-storage-data-on-uicr-region/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;You can generate the binary file and use the objcopy&amp;nbsp;&lt;/p&gt;
&lt;p&gt;objcopy -v -I binary -O ihex --change-addresses 0x12000000 IMAGE_01.bin IMAGE_01.hex&lt;/p&gt;
&lt;p&gt;and then use the nrfjprog to program the hex file on specify address&lt;/p&gt;
&lt;pre class="wp-block-code"&gt;&lt;code&gt;nrfjprog -f nrf52 --qspicustominit --program ..\result_output\IMAGE_01.hex  --sectorerase&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;similar to the QSPI&amp;nbsp;&lt;a href="https://jimmywongbluetooth.wordpress.com/2019/10/09/how-to-store-the-file-inside-the-qspi-flash/"&gt;https://jimmywongbluetooth.wordpress.com/2019/10/09/how-to-store-the-file-inside-the-qspi-flash/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/thread/214649?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2019 18:39:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57683107-ef44-4b56-b1c7-ab738e928a91</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;You declare a new section in both your firmware global variable and in the linker script map it to an fixed address&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/thread/214648?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2019 18:36:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9aa3184f-7ef7-4b29-bab6-ecce581b6493</guid><dc:creator>nrbrook</dc:creator><description>&lt;p&gt;How would you reserve the flash and avoid FDS and the boot loader (when performing DFU) writing to it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write initial values to flash during production</title><link>https://devzone.nordicsemi.com/thread/214646?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2019 18:03:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4da271a8-9f3c-47ed-bbd5-8a64ad001abe</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;You could reserve a section flash at a fixed location in your firmware and write the custom data directly to that address with an external utility such as the nrfjprog.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>