<?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>Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54587/bonding-with-fds-and-dfu-sometimes-fail</link><description>Hi 
 I am using nRF52DK, SDK 15.0, SD 6.0.0, multiperipheral based example with secure bootloader, FDS (7 FDS_VIRTUAL_PAGES). Uploading new software works (not tested thorougly). 
 Project building with SES, then flashing with a script: 
 
 then F5 to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Nov 2019 07:43:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54587/bonding-with-fds-and-dfu-sometimes-fail" /><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222705?ContentTypeID=1</link><pubDate>Fri, 29 Nov 2019 07:43:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5339422a-f05f-4d7a-ad94-810934d89be3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Ok, so that may explain why it&amp;#39;s not failing consistently.&amp;nbsp;See &amp;quot;&lt;a title="SoftDevice timing-activities and priorities" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/multilink_scheduling/priorities_and_events_intro.html?cp=4_5_2_0_14_0"&gt;SoftDevice timing-activities and priorities&lt;/a&gt;&amp;quot; for details&amp;nbsp;on how the scheduler priorities the different events/tasks.&amp;nbsp;&lt;/p&gt;
[quote user="Pawel Niedbala"]High probability of flash operation success means that there is a tiny risk of FDS operation failure we should accept?[/quote]
&lt;p&gt;&amp;nbsp;The app may retry the flash operation later.&amp;nbsp;Writing small chunks of data should not be a problem, but flash erase (garbage collection) is harder to schedule.&lt;/p&gt;
[quote user="Pawel Niedbala"]By return code I meant&amp;nbsp;NRF_ERROR_SOFTDEVICE_NOT_ENABLED when trying to pair.[/quote]
&lt;p&gt;&amp;nbsp;It&amp;#39;s definitely misleading. That is why the FDS errors now use a different number range.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222651?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2019 15:52:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19fbd717-d1cb-4c92-a28e-9a4b7f2baad3</guid><dc:creator>Pawel Niedbala</dc:creator><description>&lt;p&gt;Oh yes of course, it is connectable advertising. And it advertises until given number of masters are connected (multiperipheral).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You suggest postponing starting advertising so flash initialization can be performed completely because it is essential. But what about potential collision between normal periodical advertising packet and occassional flash write?&amp;nbsp;&lt;span&gt;High probability of flash operation success means that there is a tiny risk of FDS operation failure we should accept?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;By return code I meant&amp;nbsp;NRF_ERROR_SOFTDEVICE_NOT_ENABLED when trying to pair.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222643?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2019 15:00:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94b4823e-8326-4722-91ff-b71d23f7a86c</guid><dc:creator>Vidar Berg</dc:creator><description>[quote userid="71756" url="~/f/nordic-q-a/54587/bonding-with-fds-and-dfu-sometimes-fail/222635"]Also&amp;nbsp;&lt;strong&gt;sd_ble_gap_connect(...)&lt;/strong&gt; is not being called at all in my application[/quote]
&lt;p&gt;Yes, but assume you&amp;#39;re starting connectable advertising so a nearby central could chose to send a&amp;nbsp; connect request? I&amp;#39;d recommend to postpone advertising until pending flash operations are complete like the adv. module.&amp;nbsp;&lt;/p&gt;
[quote userid="71756" url="~/f/nordic-q-a/54587/bonding-with-fds-and-dfu-sometimes-fail/222635"]If your guess is correct the return code does not explain the reason properly and the error caught by[/quote]
&lt;p&gt;Return code from which function? A NRF_SUCCESS from the&amp;nbsp; sd_flash APIs only means the task got accepted into the flash queue. The result of the operation will be reported to the fds callback.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222635?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2019 14:44:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b47ea98-2b0e-41ae-9578-e6720161c91e</guid><dc:creator>Pawel Niedbala</dc:creator><description>&lt;p&gt;Indeed, I start advertising directly,&amp;nbsp;&lt;strong&gt;advertising_start()&lt;/strong&gt; which&amp;nbsp;calls&amp;nbsp;&lt;strong&gt;sd_ble_gap_adv_start(...)&lt;/strong&gt;. I do not even use advertising module. Also&amp;nbsp;&lt;strong&gt;sd_ble_gap_connect(...)&lt;/strong&gt; is not being called at all in my application.&lt;/p&gt;
&lt;p&gt;If your guess is correct the return code does not explain the reason properly and the error caught by APP_ERROR_CHECK leads to a&amp;nbsp;misunderstanding.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222617?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2019 12:50:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e561fe4-750f-4217-891c-595a93587b27</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Ok, thanks for confirming. I think&amp;nbsp;it&amp;#39;s likely that&amp;nbsp;the Softdevice fails to schedule the flash operations due to BLE advertising and connections (&lt;a title="Flash memory API" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/flash_mem_api/flash_mem_api.html?cp=4_5_2_0_7"&gt;Flash memory API&lt;/a&gt;). Maybe you have a re-connect immediately&amp;nbsp;on startup that triggers this scenario?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you start advertising directly or do you use ble_advertising_start() which should delay it until there are no pending flash operations?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_advertising_start(ble_advertising_t * const p_advertising,
                               ble_adv_mode_t            advertising_mode)
{
    uint32_t ret;

    if (p_advertising-&amp;gt;initialized == false)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    p_advertising-&amp;gt;adv_mode_current = advertising_mode;

    // Delay starting advertising until the flash operations are complete.
    if (flash_access_in_progress())
    {
        p_advertising-&amp;gt;advertising_start_pending = true;
        return NRF_SUCCESS;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Pawel Niedbala"]I haven&amp;#39;t tried using stack guard, is it really that helpful? Also for SDK15 it is&amp;nbsp;&lt;strong&gt;nrf_mpu_init()&lt;/strong&gt; not&amp;nbsp;&lt;strong&gt;nrf_mpu_lib_init()&lt;/strong&gt;.[/quote]
&lt;p&gt;&amp;nbsp;It can help you detect stack overflows.&amp;nbsp;Probably not necessary if you&amp;#39;ve already profiled the stack usage or know that you have plenty of space left.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222612?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2019 12:33:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5af2b74-4e2c-4012-a655-d4c2b81d702e</guid><dc:creator>Pawel Niedbala</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;After adding busy wait before and after&amp;nbsp;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;pm_init()&lt;/strong&gt;&amp;nbsp;the app seems to work correctly after each bootup, there is no need to reset the board. At least it has not happened yet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    nrf_delay_ms(10); 
    err_code = pm_init();
    APP_ERROR_CHECK(err_code); NRF_LOG_INFO(&amp;quot;pm_init() return status :%d&amp;quot;, err_code);
    nrf_delay_ms(10); &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Can you comment why FDS may not be initializing properly sometimes without that delay?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t tried using stack guard, is it really that helpful? Also for SDK15 it is&amp;nbsp;&lt;strong&gt;nrf_mpu_init()&lt;/strong&gt; not&amp;nbsp;&lt;strong&gt;nrf_mpu_lib_init()&lt;/strong&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222524?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2019 08:06:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3b4ffde-58a7-4093-90f1-ae77bc3ec739</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry, I thought&amp;nbsp;you had actually to perform DFU to reproduce this. That made everything a bit more confusing. Your last three screenshot shows that FDS is only able to tag two pages at a time for the failing case, which explains why the extra resets help.&amp;nbsp;Could you try to add a busy wait (e.g., nrf_delay_ms(10)) right after pm_init() as a test to see if solves the problem even with logging on?&lt;/p&gt;
&lt;p&gt;Also, logging in itself should have any impact on FDS, but it could be related to stack usage, as you said. You can use the&amp;nbsp;&lt;a title="Stack guard" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_stack_guard.html?cp=6_1_3_50"&gt;Stack guard&lt;/a&gt;&amp;nbsp;to catch any stack overflows in your code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static inline void stack_guard_init(void)
{
    APP_ERROR_CHECK(nrf_mpu_lib_init()); //&amp;lt;-- must be initalized for stack guard to trigger fault on stack overflow
    APP_ERROR_CHECK(nrf_stack_guard_init());
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222409?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 14:57:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dc9b57c-3209-4c0e-b456-4b321fe180a8</guid><dc:creator>Pawel Niedbala</dc:creator><description>&lt;p&gt;Hi!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The reset reason 0x4 occurs every time I reflash the device. 0x1 reason after every button reset. I don&amp;#39;t see there is any dependency.&lt;/p&gt;
&lt;p&gt;Now after adding some code to the app (developing and refactoring other functionalities) I noticed something strange. I mean the application behaves differently depending on some logs being turned on or off.&lt;/p&gt;
&lt;p&gt;Logs are on when a predefined symbol is set.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Inside&amp;nbsp;&lt;em&gt;peer_manager.c&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
ret_code_t pm_init(void)
{
    ret_code_t err_code;

    err_code = pds_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: pds_init, code: %d&amp;quot;, err_code);
        /* FIXME DFU err_code=134 */
        #endif
        return NRF_ERROR_INTERNAL;
    }

    err_code = pdb_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: pdb_init&amp;quot;);
        #endif
        return NRF_ERROR_INTERNAL;
    }

    err_code = sm_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: sm_init&amp;quot;);
        #endif
        return NRF_ERROR_INTERNAL;
    }

    err_code = smd_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: smd_init&amp;quot;);
        #endif
        return NRF_ERROR_INTERNAL;
    }

    err_code = gcm_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: gcm_init&amp;quot;);
        #endif
        return NRF_ERROR_INTERNAL;
    }

    err_code = gscm_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: gscm_init&amp;quot;);
        #endif
        return NRF_ERROR_INTERNAL;
    }

    err_code = im_init();
    if (err_code != NRF_SUCCESS)
    {
        #if defined TEST_FDS_DFU_DEBUG_LOG
            NRF_LOG_INFO(&amp;quot;err from: im_init&amp;quot;);
        #endif
        return NRF_ERROR_INTERNAL;
    }

    internal_state_reset();

    m_peer_rank_initialized = false;
    m_module_initialized    = true;

    // If PM_PEER_RANKS_ENABLED is 0, these variables are unused.
    UNUSED_VARIABLE(m_peer_rank_initialized);
    UNUSED_VARIABLE(m_peer_rank_token);
    UNUSED_VARIABLE(m_current_highest_peer_rank);
    UNUSED_VARIABLE(m_highest_ranked_peer);

    return NRF_SUCCESS;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;inside&amp;nbsp;&lt;em&gt;fds.c&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
// Initialize the filesystem.
static ret_code_t init_execute(uint32_t prev_ret, fds_op_t * const p_op)
{
    ret_code_t ret = FDS_ERR_INTERNAL;
    #if defined TEST_FDS_DFU_DEBUG_LOG
        NRF_LOG_RAW_INFO(&amp;quot;init_execute: prev_ret %d, p_op %d\n&amp;quot;, prev_ret, p_op-&amp;gt;init.step);
    #endif
    if (prev_ret != NRF_SUCCESS)
    {
        // A previous operation has timed out.
        m_flags.initializing = false;
        return FDS_ERR_OPERATION_TIMEOUT;
    }

    switch (p_op-&amp;gt;init.step)
    {
        case FDS_OP_INIT_TAG_SWAP:
        {
            // The page write offset was determined previously by pages_init().
            p_op-&amp;gt;init.step = FDS_OP_INIT_TAG_DATA;
            ret             = page_tag_write_swap();
        } break;

        case FDS_OP_INIT_TAG_DATA:
        {
            // Tag remaining erased pages as data.
            bool write_reqd = false;
            for (uint16_t i = 0; i &amp;lt; FDS_DATA_PAGES; i++)
            {
                if (m_pages[i].page_type == FDS_PAGE_ERASED)
                {
                    m_pages[i].page_type = FDS_PAGE_DATA;
                    write_reqd           = true;
                    ret = page_tag_write_data(m_pages[i].p_addr);
                    break;
                }
            }
            if (!write_reqd)
            {
                m_flags.initialized  = true;
                m_flags.initializing = false;
                return FDS_OP_COMPLETED;
            }
        } break;

        case FDS_OP_INIT_ERASE_SWAP:
        {
            // If the swap is going to be discarded then reset its write_offset.
            p_op-&amp;gt;init.step          = FDS_OP_INIT_TAG_SWAP;
            m_swap_page.write_offset = FDS_PAGE_TAG_SIZE;

            ret = nrf_fstorage_erase(&amp;amp;m_fs, (uint32_t)m_swap_page.p_addr, FDS_PHY_PAGES_IN_VPAGE, NULL);
        } break;

        case FDS_OP_INIT_PROMOTE_SWAP:
        {
            p_op-&amp;gt;init.step       = FDS_OP_INIT_TAG_SWAP;

            // When promoting the swap, keep the write_offset set by pages_init().
            ret = page_tag_write_data(m_swap_page.p_addr);

            uint16_t const         gc         = m_gc.cur_page;
            uint32_t const * const p_old_swap = m_swap_page.p_addr;

            // Execute the swap.
            m_swap_page.p_addr = m_pages[gc].p_addr;
            m_pages[gc].p_addr = p_old_swap;

            // Copy the offset from the swap to the new page.
            m_pages[gc].write_offset = m_swap_page.write_offset;
            m_swap_page.write_offset = FDS_PAGE_TAG_SIZE;

            m_pages[gc].page_type = FDS_PAGE_DATA;
        } break;

        default:
            // Should not happen.
            break;
    }
    #if defined TEST_FDS_DFU_DEBUG_LOG
        NRF_LOG_RAW_INFO(&amp;quot;init_execute: ret %d\n&amp;quot;, ret);
    #endif
    if (ret != FDS_SUCCESS)
    {
        // fstorage queue was full.
        m_flags.initializing = false;
        return FDS_ERR_BUSY;
    }

    return FDS_OP_EXECUTING;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And here it is - when the logs are turned on the fds module initializes correctly on the first run. When they are turned off the device need 3 consecutive button resets until it starts working properly.&lt;/p&gt;
&lt;p&gt;I made hexdump before and after each reset in the failing case and below is the diff:&lt;/p&gt;
&lt;p&gt;just flashed against 1 reset:&amp;nbsp;:&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1574866565644v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;just flashed against 2 resets:&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1574866581120v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;just flashed against 3 resets:&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1574866596430v5.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is it some RAM issue? I am nearing to 94% RAM usage based on SES build output. Or some NRF_LOG delay?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222318?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 11:22:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb4ecb6d-4d31-4668-9e50-bf296ab9a8c3</guid><dc:creator>Vidar Berg</dc:creator><description>[quote user="Pawel Niedbala"]I understand that CCCDs are stored in flash memory so it may change, but only when I change them, right? In my scenario I did not enabled nor disabled any indications/notifications. Just click bond and click DFU.[/quote]
&lt;p&gt;Yes, the phone shouldn&amp;#39;t change the configuration automatically.&amp;nbsp; It could be related to&amp;nbsp;gscm_local_database_has_changed() or pm_peer_rank_*() if they&amp;#39;re being&amp;nbsp;used in your code.&lt;/p&gt;
&lt;p&gt;I notice that reset reason is 0x4 when it fails, and 0x1 when it works in the logs you&amp;#39;ve posted. Is it like that every time?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222124?ContentTypeID=1</link><pubDate>Tue, 26 Nov 2019 13:58:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ceb717ac-41f8-4348-89d4-6edda35c8997</guid><dc:creator>Pawel Niedbala</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I understand that CCCDs are stored in flash memory so it may change, but only when I change them, right? In my scenario I did not enabled nor disabled any indications/notifications. Just click bond and click DFU.&lt;/p&gt;
&lt;p&gt;As for return value from pm_init() - yes, its return value is passed to error checking. Moreover I print it over debug terminal:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void peer_manager_init(bool erase_bonds)
{
    switch(PEER_MANAGER_SETTING)
    {
        case NO_PAIRING_NO_BONDING:
            BOND = false;        MITM = false;        LESC = 0;        KEYPRESS = 0;
            IO_CAPS = BLE_GAP_IO_CAPS_NONE;        OOB = false;        MIN_KEY_SIZE = 0;        MAX_KEY_SIZE = 0;
            K_OWN_ENC = 0;        K_OWN_ID = 0;        K_PEER_ENC = 0;        K_PEER_INC = 0;        
        break;
        case PAIRING_NO_BONDING:
            BOND = false;        MITM = false;        LESC = 0;        KEYPRESS = 0;
            IO_CAPS = BLE_GAP_IO_CAPS_NONE;        OOB = false;        MIN_KEY_SIZE = 7;        MAX_KEY_SIZE = 16;
            K_OWN_ENC = 0;        K_OWN_ID = 0;        K_PEER_ENC = 0;        K_PEER_INC = 0;
        break;
        case JUST_WORKS_BONDING:
            BOND = true;        MITM = false;        LESC = 0;        KEYPRESS = 0;
            IO_CAPS = BLE_GAP_IO_CAPS_NONE;        OOB = false;        MIN_KEY_SIZE = 7;        MAX_KEY_SIZE = 16;
            K_OWN_ENC = 1;        K_OWN_ID = 1;        K_PEER_ENC = 1;        K_PEER_INC = 1;
        break;
        case PASSKEY_BONDING_DISPLAY:
            BOND = true;        MITM = true;        LESC = 0;        KEYPRESS = 0;
            IO_CAPS = BLE_GAP_IO_CAPS_DISPLAY_ONLY;        OOB = false;        MIN_KEY_SIZE = 7;        MAX_KEY_SIZE = 16;
            K_OWN_ENC = 1;        K_OWN_ID = 1;        K_PEER_ENC = 1;        K_PEER_INC = 1;
        break;       
    }

    ble_gap_sec_params_t sec_param;
    ret_code_t err_code;
    err_code = pm_init();
    APP_ERROR_CHECK(err_code); NRF_LOG_INFO(&amp;quot;pm_init() return status :%d&amp;quot;, err_code);

    if (erase_bonds)
    {
        pm_peers_delete();
        NRF_LOG_INFO(&amp;quot;bonds deleted&amp;quot;);
    }
    memset(&amp;amp;sec_param, 0, sizeof(ble_gap_sec_params_t));
    
    ...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is the output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: __________________start
&amp;lt;info&amp;gt; app: ~~ ZMIANA NAZWY (na v1) W: gap_params_init
&amp;lt;info&amp;gt; app: pm_init() return status :0
&amp;lt;info&amp;gt; app: Setting vector table to bootloader: 0x00078000
&amp;lt;info&amp;gt; app: Setting vector table to main app: 0x00026000
&amp;lt;info&amp;gt; app: zostaje domyslny adv_name
&amp;lt;error&amp;gt; app: bzdurne wartosci ts:0, cnt:0
&amp;lt;info&amp;gt; app: nie ma w ogole pomiarow offline, bo secret_word to: 26DB1 wobec 0xAAAAAAAA
&amp;lt;info&amp;gt; app: epoch 0
&amp;lt;info&amp;gt; app: battery_meas handler rusza
&amp;lt;info&amp;gt; app: reset_reason: 0x00000004.

&amp;lt;info&amp;gt; app: adc handler rusza
SPRAWDZENIE
&amp;lt;info&amp;gt; app: pages_available 0 open_records 0 valid_records 0
&amp;lt;info&amp;gt; app: dirty_records 0 words_reserved 0 words_used 0
&amp;lt;info&amp;gt; app: largest_contig 0 freeable_words 0 corruption 0
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So the return value is 0, despite the FDS is not initialized properly (0 pages instead of 8).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/222024?ContentTypeID=1</link><pubDate>Tue, 26 Nov 2019 09:32:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b839fc7-0c68-481b-a115-39e8e06c5821</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, I meant&amp;nbsp;&lt;span&gt;DFU_APP_DATA_RESERVED&amp;nbsp;and&amp;nbsp;it should be either be equal or larger than the FDS_VIRTUAL_PAGES number defined by the main app. However, the fact that you can recover through a reset indicates that the problem is something else. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It looks like none of the FDS events are coming through in the failing case.&amp;nbsp;&lt;span&gt;Is the return value from pm_init() passed to the APP_ERROR_CHECK() macro in your code?&lt;/span&gt;&lt;/p&gt;
[quote user="Pawel Niedbala"]Is it desired behaviour that number of words_used is bigger after the update? So do valid_records number?[/quote]
&lt;p&gt;CCCD (notifications/indications&amp;nbsp;configuration) are stored to flash by the peer manager&amp;nbsp;so the client configuration can be&amp;nbsp;retained across connections.&amp;nbsp; That may explain why the FDS stat is not always the same. E.g., if the phone disables indications on the buttonless characteristic, then enables it when it starts the DFU.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/221483?ContentTypeID=1</link><pubDate>Fri, 22 Nov 2019 08:34:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed35fd1d-e2b2-43f0-833d-fc3ac2ddde9e</guid><dc:creator>Pawel Niedbala</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Thank you for response.&lt;/p&gt;
&lt;p&gt;If you are talking about&amp;nbsp;DFU_APP_DATA_RESERVED then yes, I have reserved it.&lt;/p&gt;
&lt;p&gt;I shouldn&amp;#39;t have any negative effect but I changed if from 7 to 8 -both on app side and bootloader side. Now there is&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; #define FDS_VIRTUAL_PAGES 8&lt;/p&gt;
&lt;p&gt;in application project&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; #define DFU_APP_DATA_RESERVED&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(CODE_PAGE_SIZE * 8)&lt;/p&gt;
&lt;p&gt;in bootloader project.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The situation with not-initializing the FDS still happens occassionally, but resetting the board with RESET button does the job and with the next boot-up the FDS works.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I thought there may be some kind of misconfiguration with the FDS or DFU. Right after (successfull) flashing and booting the &lt;strong&gt;fds_stat()&lt;/strong&gt; shows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: pages_available 8 open_records 0 valid_records 0
 0&amp;gt; &amp;lt;info&amp;gt; app: dirty_records 0 words_reserved 0 words_used 14
 0&amp;gt; &amp;lt;info&amp;gt; app: largest_contig 1022 freeable_words 0 corruption 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;after bonding with one device it shows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: pages_available 8 open_records 0 valid_records 3
 0&amp;gt; &amp;lt;info&amp;gt; app: dirty_records 0 words_reserved 0 words_used 52
 0&amp;gt; &amp;lt;info&amp;gt; app: largest_contig 1022 freeable_words 0 corruption 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;then I prepared .zip package. New app differs with TWO bytes, &amp;quot;v2&amp;quot; instead of &amp;quot;v1&amp;quot; in log content and &amp;quot;board-v2&amp;quot; instead of &amp;quot;board-v1&amp;quot; in&amp;nbsp;#define DEVICE_NAME - just so I know the new software is up and running.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="batchfile"&gt;SET family= NRF52
SET application= C:\repo\pikflometr\multiperipheral\pca10040\s132\ses\Output\Release\Exe\ble_app_multiperipheral_pca10040_s132.hex
SET application-version=2
SET hardware-version= 52
SET sd-req= 0xA8
SET private_key= C:\repo\pikflometr\lib\\private_key.pem
SET nrfutil_location= C:\repo\pikflometr\lib\
SET zipfile_name= p6-2.zip
cd %nrfutil_location%
nrfutil pkg generate --application %application% --application-version %application-version% --hw-version %hardware-version% --sd-req %sd-req% --key-file %private_key% %zipfile_name%&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;after bluetooth DFU OTA sometimes I see:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: pages_available 8 open_records 0 valid_records 4
&amp;lt;info&amp;gt; app: dirty_records 3 words_reserved 0 words_used 82
&amp;lt;info&amp;gt; app: largest_contig 1022 freeable_words 26 corruption 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;or sometimes&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: pages_available 8 open_records 0 valid_records 4
&amp;lt;info&amp;gt; app: dirty_records 2 words_reserved 0 words_used 78
&amp;lt;info&amp;gt; app: largest_contig 1022 freeable_words 22 corruption 0&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is it desired behaviour that number of words_used is bigger after the update? So do valid_records number?&lt;/p&gt;
&lt;p&gt;I made no writes to the flash memory. Just the:&lt;/p&gt;
&lt;p&gt;programming -&amp;gt; &lt;strong&gt;fds_stat() &lt;/strong&gt;-&amp;gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;bonding -&amp;gt;&amp;nbsp;&lt;strong&gt;fds_stat()&lt;/strong&gt; -&amp;gt;&amp;nbsp; update -&amp;gt;&amp;nbsp;&lt;strong&gt;fds_stat()&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding with FDS and DFU sometimes fail</title><link>https://devzone.nordicsemi.com/thread/221282?ContentTypeID=1</link><pubDate>Thu, 21 Nov 2019 10:37:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e695d769-a406-46b3-970d-9df37f46b823</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I agree that it looks to be a problem with the FDS initialization. Have you tried to reserve the 7 flash&amp;nbsp;pages&amp;nbsp;in the bootloader so the can&amp;#39;t get overwritten during DFU(&lt;a title="Memory layout" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_bootloader.html?cp=6_1_3_5_0_7#lib_bootloader_memory"&gt;Memory layout&lt;/a&gt;)?&amp;nbsp;FDS may fail to free the pages aftewards if not.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>