<?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>Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24637/flash-handling-after-sdk-14-migration-unclear</link><description>Edit: Rephrased the question to make it easier to answer. 
 I used flash storage to store a couple of variables between resets in a app made from SDK 12.2, now I am attempting to migrate to SDK 14, but I can&amp;#39;t figure out how to make the fstorage migration</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Sep 2017 19:18:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24637/flash-handling-after-sdk-14-migration-unclear" /><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96991?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2017 19:18:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9ca1b5c-7592-4b11-be47-651c7907e076</guid><dc:creator>erltot</dc:creator><description>&lt;p&gt;I used the &amp;quot;will it float or sink&amp;quot; method.. ;) I picked an arbitrary high address and used the nrf tool thingy to male sure norhing was on it after i had flashed the application, and put end address more than one page higher. I seem to recall it used to be picked from the top of the memory and down depending on many pages, but I was not sure and could not find it again. If i remember correctly the soft device aleays gets the first addresses, then you application, and the rest you can use from the top down&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96990?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2017 19:14:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47615805-c551-42ea-8a51-f0bdfa47f6c0</guid><dc:creator>erich</dc:creator><description>&lt;p&gt;Could you explain how you selected the start and end addresses, and how you made sure they don&amp;#39;t conflict with the application or softdevice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96989?ContentTypeID=1</link><pubDate>Wed, 06 Sep 2017 13:43:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7dfe4057-55f4-44c6-b63a-a29afbbb2a87</guid><dc:creator>erltot</dc:creator><description>&lt;p&gt;Added start_addr and end_addr to NRF_FSTORAGE_DEF and made sure the page(s) I want to delete is within the constraints of start and end.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**
 * @brief event handler for flash storage
 * @details this is triggered each time a flash operation is done
 */
static void fs_event_handler(nrf_fstorage_evt_t * evt){
    if (evt-&amp;gt;result != NRF_SUCCESS){
        NRF_LOG_ERROR(&amp;quot;Flash error&amp;quot;);
        while(1);
    } else {
        fs_callback_flag = 0;
        NRF_LOG_INFO(&amp;quot;Flash evt ok&amp;quot;);
    }
}

NRF_FSTORAGE_DEF(nrf_fstorage_t m_fs) =
{
    .evt_handler = fs_event_handler,
    .start_addr = 0x0007F000,
    .end_addr = 0x000FF000,
};


/**@brief Application main function.
 */
int main(void)
{
    uint32_t err_code;
    bool     erase_bonds;
    
    uint32_t data;
    uint32_t flash_data[4];
    do_flash_operation = true;

    // Initialize.
    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

    uart_init();
    log_init();
    
    err_code = nrf_fstorage_init(&amp;amp;m_fs, &amp;amp;nrf_fstorage_sd, NULL);
    APP_ERROR_CHECK(err_code);
    
    buttons_leds_init(&amp;amp;erase_bonds);
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    NRF_LOG_INFO(&amp;quot;BLE NUS with UART and FSTORAGE Start!&amp;quot;);
    err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_FLUSH();
    // Enter main loop.
    for (;;)
    {
        if(do_flash_operation)
        {   
            do_flash_operation = false;
            // Erase one page
            NRF_LOG_INFO(&amp;quot;Erasing a flash page at address 0x%X\n&amp;quot;, (uint32_t)m_fs.start_addr);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_erase(&amp;amp;m_fs, m_fs.start_addr, 1, NULL);
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;erase error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
            data = 0xAAAAAAAA;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\n&amp;quot;, data, (uint32_t)m_fs.start_addr);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
            data = 0xBBBBBBBB;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 4);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 4, &amp;amp;data, 4, NULL);
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
                        
            data = 0xCCCCCCCC;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 8);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 8, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
                        
            data = 0xDDDDDDDD;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 12);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 12, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
            //Read the first 4 words of the page
            NRF_LOG_INFO(&amp;quot;Data read from flash address 0x%X: \n&amp;quot;, (uint32_t)m_fs.start_addr);
            err_code = nrf_fstorage_read(&amp;amp;m_fs, m_fs.start_addr, flash_data, 32);
            APP_ERROR_CHECK(err_code);
            for(int i=0; i&amp;lt;4; i++)
            {                  
                NRF_LOG_INFO(&amp;quot;%X &amp;quot;, flash_data[i]);
            }
            NRF_LOG_INFO(&amp;quot;Read Done\n&amp;quot;);
                        
            data = 0xEEEEEEEE;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 16);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 16, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
                        
            data = 0x00000000;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\r\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 20);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 20, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
                        
            data = 0x11111111;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\r\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 24);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 24, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
                        
            data = 0x22222222;
            NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\r\n&amp;quot;, data, (uint32_t)m_fs.start_addr + 28);
            fs_callback_flag = 1;
            err_code = nrf_fstorage_write(&amp;amp;m_fs, m_fs.start_addr + 28, &amp;amp;data, 4, NULL);      //Write data to memory address. Check it with command: nrfjprog --memrd addr --n 32
            APP_ERROR_CHECK(err_code);
            if (err_code != NRF_SUCCESS)
            {
                bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
                NRF_LOG_ERROR(&amp;quot;write error&amp;quot;);
            }
            NRF_LOG_FLUSH();
            while(fs_callback_flag == 1)  { power_manage(); }
            
            //Read the first 4 words of the page
            NRF_LOG_INFO(&amp;quot;Data read from flash address 0x%X: \r\n&amp;quot;, (uint32_t)m_fs.start_addr + 16);
            err_code = nrf_fstorage_read(&amp;amp;m_fs, m_fs.start_addr + 16, flash_data, 32);
            APP_ERROR_CHECK(err_code);
            for(int i=0; i&amp;lt;4; i++)
            {
                NRF_LOG_INFO(&amp;quot;%X &amp;quot;, flash_data[i]);
            }
            NRF_LOG_INFO(&amp;quot;Read Done\n&amp;quot;);
        }
        
        if (NRF_LOG_PROCESS() == false)
        {
            NRF_LOG_FLUSH();
            power_manage();
        }
        NRF_LOG_FLUSH();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://ufile.io/5r9x8"&gt;Link to project (Only valid for 30 days)&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96985?ContentTypeID=1</link><pubDate>Wed, 06 Sep 2017 11:07:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a11e356-24bd-45bb-8b55-e22287a3514e</guid><dc:creator>erltot</dc:creator><description>&lt;p&gt;Yes. In the previous sdk this address was calculated automaticly when initializing the module I think? Do I have to set it manually now? How do i pick the right address?
@petter An example with &amp;quot;best practise&amp;quot; of handling persistent storing of variables with either fds or fstorage I think would be useful to add to your examples in the SDK..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96987?ContentTypeID=1</link><pubDate>Wed, 06 Sep 2017 10:20:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a809e8b-cef9-4f92-88b2-09fe2564e096</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Seems you are trying to erase 4 flash pages starting from address 0x00000000? This is a part of flash where the SoftDevice resides, so that is probably why you get NRF_ERROR_INVALID_ADDR.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96986?ContentTypeID=1</link><pubDate>Mon, 04 Sep 2017 10:21:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a4f6152-20f6-4064-83be-9889cfa814bb</guid><dc:creator>erltot</dc:creator><description>&lt;p&gt;@petter Please see updated question, and yes I am using softdevice&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96984?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 11:13:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91ec51a4-fe89-47dc-849f-8cd91d85fef5</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Are you using a SoftDevice? Could you send me your complete project so I can test it here? Error 167? is that hex or what?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96983?ContentTypeID=1</link><pubDate>Mon, 28 Aug 2017 09:00:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ca08846-e4b5-45da-8af0-d7667c83fced</guid><dc:creator>erltot</dc:creator><description>&lt;p&gt;Hi, see updated question&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash handling after sdk 14 migration unclear</title><link>https://devzone.nordicsemi.com/thread/96988?ContentTypeID=1</link><pubDate>Fri, 25 Aug 2017 10:41:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9dd6e7b-1576-4c6f-afbf-729388bade09</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Exactly what is unclear? Have you had a look at the migration guides?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>