<?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>Setting up App Data preservation with DFU</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40927/setting-up-app-data-preservation-with-dfu</link><description>I have the BMD350 from Rigado. I am using Segger embedded studio with SDK v 15.2.0 I have the buttonless DFU working with my custom application that has the buttonless DFU and the nordic uart service (NUS). I would like to use the app data section of</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Nov 2018 09:36:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40927/setting-up-app-data-preservation-with-dfu" /><item><title>RE: Setting up App Data preservation with DFU</title><link>https://devzone.nordicsemi.com/thread/159509?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 09:36:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b1f8741-1253-46f5-84ac-a168c45d48dc</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, FDS will automatically&amp;nbsp;use the app data region&amp;nbsp;which gets placed below the bootloader as shown&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_bootloader.html?cp=4_0_0_3_5_0_7#lib_bootloader_memory"&gt;here&lt;/a&gt;. The region end add address (where bootloader starts) is found by reading out the BL start address stored in&amp;nbsp;NRF_UICR-&amp;gt;NRFFW[0], see fds.c -&amp;gt;flash_end_addr() .&lt;/p&gt;
&lt;p&gt;You&amp;nbsp;may chose how many flash pages you want allocated to FDS by changing&amp;nbsp;FDS_VIRTUAL_PAGES define in sdk_config.h. But note&amp;nbsp;that&amp;nbsp;APP_DATA_RESERVED define in the bootloader code must correspond with&amp;nbsp;&lt;span&gt;FDS_VIRTUAL_PAGES value used by the app to ensure that user data is not erased by a DFU.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
[quote user="erosembedded"]&lt;br /&gt;For Volatile, I meant define it so the compiler will not optimize out any usage I have of the data. But using the FDS may get rid of the need for that.&amp;nbsp;[/quote]
&lt;p&gt;FDS will simply copy the data from a given&amp;nbsp;source address so you should&amp;nbsp;assess your code to determine&amp;nbsp;the&amp;nbsp;structure should be declared volatile.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up App Data preservation with DFU</title><link>https://devzone.nordicsemi.com/thread/159459?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 02:24:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69e2abdc-ac69-48f2-9639-3e88de8e02aa</guid><dc:creator>erosembedded</dc:creator><description>&lt;p&gt;FDS sounds like the way to go.&lt;/p&gt;
&lt;p&gt;I had a question, does the FDS automatically use the persistent &amp;quot;app data&amp;quot; region in flash that the bootloader does not write to? I don&amp;#39;t see any set up for where the file system is located. Is it set up so that whatever I write to the file system will not be overwritten by the bootloader?&lt;br /&gt;&lt;br /&gt;For Volatile, I meant define it so the compiler will not optimize out any usage I have of the data. But using the FDS may get rid of the need for that.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I don&amp;#39;t plan on writing to my configuration file very often. It will only be written to once in a while with long periods (days, weeks) in between.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up App Data preservation with DFU</title><link>https://devzone.nordicsemi.com/thread/159379?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 09:44:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d50ec9b4-b8fe-44b4-8ca4-3639e5cd4fef</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;You may know this but there are a few things to keep in mind when dealing with flash storage. 1. flash must be erased before you can write to it.&amp;nbsp;I.e.,, to update existing data in flash you need to ensure that the flash page you are writing to is erased. 2. Flash can only be erased in units of flash pages (4kB on nRF52 series). 3.&amp;nbsp;Page erase is&amp;nbsp;a relatively time consuming task (&amp;lt;85 ms)&amp;nbsp; and the softdevice may fail do schedule it if there&amp;#39;s too much BLE activity (short connection interval, etc), see &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.sds/dita/softdevices/s130/flash_mem_api/flash_mem_api.html?cp=2_3_1_0_7"&gt;Flash API&lt;/a&gt;&amp;nbsp;for more information on how the scheduling works.&lt;/p&gt;
&lt;p&gt;Generally I think FDS is the best option, especially if you need to update data regularly. Instead of erasing a flash page every time existing data is updated&amp;nbsp;FDS will invalidate the old record by writing one bit then write a new one. When there is no more flash pages you can run garbage collection to remove invalidated data.&lt;/p&gt;
[quote user="erosembedded"]I do not need to use a file system. I just need to define a simple C structure with maybe 1kBytes of data max. I need to be able to update this app data in the application code as well. If the configuration changes or the data structure changes I need to write new data.[/quote]
&lt;p&gt;FDS/Fstorage does not care about data types&amp;nbsp;but the data source must be from one contiguous&amp;nbsp;block in memory and the length must be a multiple of 4 bytes (word). It&amp;nbsp;might&amp;nbsp;make sense to split up the structure in smaller data records if you parts of the structure is being updated more frequently.&amp;nbsp;&lt;/p&gt;
[quote user="erosembedded"]It is also important that I be able to&amp;nbsp;define the structure I put in the app data as &amp;quot;packed&amp;quot; (packed attribute) and sub structures within it as packed as well. It also needs to be volatile as well[/quote]
&lt;p&gt;FDS/Fstorage does not care whether the structure is packed or not. I&amp;#39;m not sure what you mean by &amp;#39;volatile&amp;#39; in this context but the source data must be kept in static memory until the flash operation is completed.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;following examples demonstrate usage of&amp;nbsp; fstorage and FDS in the SDK:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/fds_example.html"&gt;Flash Data Storage Example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/fstorage_example.html"&gt;Flash Storage Example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note: if you end up using FDS, it is not necessary to initialize it as it being done by the PM. Just register a new user.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void flash_callback(fds_evt_t const * p_evt)
{
    switch (p_evt-&amp;gt;id)
    {
        case FDS_EVT_INIT:
            if(p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                NRF_LOG_INFO(&amp;quot;FDS initialized&amp;quot;);
            }
            break;
            
        //TODO: add fds event handling
}

void flash_init(void)
{
    uint32_t err_code;

    err_code = fds_register(flash_callback);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&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: Setting up App Data preservation with DFU</title><link>https://devzone.nordicsemi.com/thread/159320?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 00:37:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84a9f9fc-c7c8-4632-993e-4f6cac27e1ec</guid><dc:creator>erosembedded</dc:creator><description>&lt;p&gt;The &amp;nbsp;buttonless BLE DFU PCA100040 example uses the peer manager so it is also in my code as well.&lt;br /&gt;&lt;br /&gt;It has this function:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for the Peer Manager initialization.
 */
static void peer_manager_init()
{
    ble_gap_sec_params_t sec_param;
    ret_code_t           err_code;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);

    memset(&amp;amp;sec_param, 0, sizeof(ble_gap_sec_params_t));

    // Security parameters to be used for all security procedures.
    sec_param.bond           = SEC_PARAM_BOND;
    sec_param.mitm           = SEC_PARAM_MITM;
    sec_param.lesc           = SEC_PARAM_LESC;
    sec_param.keypress       = SEC_PARAM_KEYPRESS;
    sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
    sec_param.oob            = SEC_PARAM_OOB;
    sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
    sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
    sec_param.kdist_own.enc  = 1;
    sec_param.kdist_own.id   = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id  = 1;

    err_code = pm_sec_params_set(&amp;amp;sec_param);
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I do not need to use a file system. I just need to define a simple C structure with maybe 1kBytes of data max. I need to be able to update this app data in the application code as well. If the configuration changes or the data structure changes I need to write new data.&lt;br /&gt;&lt;br /&gt;It is also important that I be able to&amp;nbsp;define the structure I put in the app data as &amp;quot;packed&amp;quot; (packed attribute) and sub structures within it as packed as well. It also needs to be volatile as well&lt;br /&gt;&lt;br /&gt;So I&amp;#39;m guess using fstorage directly with peer manager as you mentioned would be best?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up App Data preservation with DFU</title><link>https://devzone.nordicsemi.com/thread/159294?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 16:11:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9965e77a-bea4-4d48-a8b2-603b554afbac</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Device manager and pstorage have been replaced with the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_peer_manager.html?cp=4_0_0_3_2_7"&gt;peer manager&lt;/a&gt; and &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_fds.html?cp=4_0_0_3_55"&gt;FDS&lt;/a&gt;/&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_fstorage.html?cp=4_0_0_3_56"&gt;fstorage&lt;/a&gt;.&amp;nbsp;Instructions on how you can implement persistent storage depends on whether you&amp;nbsp;intend to use&amp;nbsp;the peer manager (support BLE pairing) or not and&amp;nbsp;if&amp;nbsp;you want to use fstorage or directly or use FDS on top (file system). Please let me know if you are using the peer manager and if you prefer fds or fstorage.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s not necessary to define the app data section in your linker script but you need to make sure that the application does not grow into this section.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>