<?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 to flash default app data while programming?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/97332/how-to-flash-default-app-data-while-programming</link><description>I am working on SDK17.1 with SES. I am developing an BLE application that has bootloader (buttonless dfu), softdevice(s340 7.0.1) and fds. My application requires some data that are stored in flash (fds) to run. I want to flash default values of these</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 05 Mar 2023 10:27:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/97332/how-to-flash-default-app-data-while-programming" /><item><title>RE: how to flash default app data while programming?</title><link>https://devzone.nordicsemi.com/thread/413381?ContentTypeID=1</link><pubDate>Sun, 05 Mar 2023 10:27:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec6ae0c1-cf89-486c-a0fa-c8a30bc0e483</guid><dc:creator>Depraz</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/dincerunsal"&gt;dincerunsal&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;I am not sure if there is a builtin SES way to do that, however, here are some steps you could look at:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Using j-link commander you can do the following&amp;nbsp;&lt;a href="https://wiki.segger.com/J-Link_Commander#LoadFile"&gt;https://wiki.segger.com/J-Link_Commander#LoadFile&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;connect&lt;br /&gt;loadfile &amp;lt;absolute bin file&amp;gt; 0x40000&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This will write the corresponding bytes contained in the file at the specific address 0x40000.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To get the default data, in the application, directly write the necessary files as default.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void default_write(void)
{
    fds_record_t record = {0};
    fds_record_desc_t record_desc;

    fds_init();

    record.file_id           = FDS_DEFAULT_RECORD_ID;
    record.key               = FDS_DEFAULT_RECORD_KEY;
    record.data.p_data       = &amp;amp;default_data;
    record.data.length_words = ARRAY_SIZE(default_data_t);
    fds_record_write(&amp;amp;record_desc, &amp;amp;record);

    // Wait for FDS operation to complete
    while (!fds_check_result(&amp;amp;record_desc));
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then, once you programmed the binary to the target nrf52, read back the flash content at the location of the FDS partition&amp;#39;s address to store it in a .bin file.&lt;br /&gt;You can use nrfjprog --memrd or, by using jlink commander (&lt;a href="https://wiki.segger.com/J-Link_Commander#SaveBin"&gt;https://wiki.segger.com/J-Link_Commander#SaveBin&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;tt&gt;SaveBin &amp;lt;filename&amp;gt; &amp;lt;addr&amp;gt; &amp;lt;NumBytes&amp;gt;&lt;/tt&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now that you have the default partition content data, you can update the linker script to put this data to the proper location in the final binary so that it will have the default values at the proper address.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span class="hljs-type"&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="hljs-type"&gt;uint8_t&lt;/span&gt;&lt;span&gt;&amp;nbsp;FDS_DATA[] __attribute__((section(&lt;/span&gt;&lt;span class="hljs-string"&gt;&amp;quot;dataFds&amp;quot;&lt;/span&gt;&lt;span&gt;))) = {&lt;/span&gt;&lt;span class="hljs-number"&gt;0x12&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="hljs-number"&gt;0x34&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="hljs-number"&gt;0x56&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="hljs-number"&gt;0x78&lt;/span&gt;&lt;span&gt;};&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You can look at&amp;nbsp;&lt;a id="" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/sdk_config.html"&gt;https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/sdk_config.html&lt;/a&gt;&amp;nbsp;to update the config and add where the dataFds array should go:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;{ &lt;/span&gt;&lt;span class="hljs-selector-class"&gt;.&lt;span&gt;dataFds&lt;/span&gt;&lt;/span&gt;&lt;span&gt;: { *(&lt;/span&gt;&lt;span class="hljs-selector-class"&gt;.&lt;span&gt;dataFds&lt;/span&gt;&lt;/span&gt;&lt;span&gt;) } &amp;gt; &lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span&gt;x040000 }&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>