This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU buttonless with Bond not working.

Hello there,

First of all, I had searched similar issue internally but didn't find any solution.

My problem is for my application with DFU buttonless without bond everything is okay. So I just followed the instruction (https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/getting-started-with-nordics-secure-dfu-bootloader#h61sjziauupw1j397q9s9ldr01q4j6d5) to add bond. It seemed pretty straightforward. The program stuck at   

err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);

Here is the debug info

"<00> info> app: Setting vector table to bootloader: 0x00078000


<00> debug> app: nrf_dfu_svci_vector_table_set() -> success


<00> debug> app: nrf_dfu_set_peer_data_init() -> success


<00> info> app: Setting vector table to main app: 0x00026000


<00> debug> app: nrf_dfu_svci_vector_table_unset() -> success


<00> error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at ..\..\..\main.c:777
00> PC at: 0x00031A4B


<00> error> app: End of error report

"

here is where ble_dfu_buttonless_init located in my code

static void services_init(void)
{
    ret_code_t         err_code;
    ble_lbs_init_t     init;
    ble_nus_init_t nus_init;
    nrf_ble_qwr_init_t qwr_init = {0};
        ble_dfu_buttonless_init_t dfus_init = {0};

    // Initialize Queued Write Module instances.
    qwr_init.error_handler = nrf_qwr_error_handler;

    for (uint32_t i = 0; i < LINK_TOTAL; i++)
    {
        err_code = nrf_ble_qwr_init(&m_qwr[i], &qwr_init);
        APP_ERROR_CHECK(err_code);
    }
        //Initialize DFU
        
            // Initialize the async SVCI interface to bootloader.
    err_code = ble_dfu_buttonless_async_svci_init();
    APP_ERROR_CHECK(err_code);

    dfus_init.evt_handler = ble_dfu_evt_handler;

    err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);
        
    // Initialize LBS.
    init.led_write_handler = led_write_handler;

    err_code = ble_lbs_init(&m_lbs, &init);
    APP_ERROR_CHECK(err_code);
        


    // Initialize NUS.
    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = nus_data_handler;

    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);

    ble_conn_state_init();
}

Here is main function

int main(void)
{
    
        bool erase_bonds;
     ret_code_t err_code;
    // Initialize.
    
        err_code = clock_config();
    APP_ERROR_CHECK(err_code);
  
    
    uart_init();
    log_init();
    timers_init();
    leds_init();
    buttons_init();
    power_management_init();

    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
        peer_manager_init(erase_bonds);

        start_app_timer();

    advertising_start(erase_bonds);

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Then I used ble_app_buttonless_dfu example and changed sdk_config.h to bond. It also worked fine.

So it must be something wrong with my services_init(). But I just cannot figure it out.

Thank you.

Parents
  • Hello,

    Please make sure you have enabled the NRF_DFU_BLE_REQUIRES_BONDS config option for the bootloader as well. This is required to support the bond sharing mechanism between app and bootloader (Buttonless Secure DFU Service with bonds).

    Best regards,

    Vidar

  • Hi Vidar,

    Thanks for looking into my case. I did

    • Change NRF_DFU_BLE_REQUIRES_BONDS to 1
    • Change NRF_SDH_BLE_SERVICE_CHANGED to 1.

    I am successfully done the DFU_buttonless example with bond. So the bootloader for bond should be okay.

    I am also successfully integrating DFU_buttonless into my application without bond. I just got problem when I modify the sdk_config.h to set bond to 1 also following the instruction in previous link.

    In addition to these setting,

    In sdk_config.h in the bootloader:

    • Change NRF_DFU_BLE_REQUIRES_BONDS to 1
    • Change NRF_SDH_BLE_SERVICE_CHANGED to 1

    - In sdk_config.h in ble_app_buttonless_dfu

    • Change NRF_DFU_BLE_BUTTONLESS_SUPPORTS_BONDS to 1
    • Check if NRF_SDH_BLE_SERVICE_CHANGED is not 1 then set it to 1

    do I need to change anything else for DFU with bond?

    Thanks,

    -Lei

  • Hi Vidar,

    Yes, all you mentioned are set. That's why I feel weird.

    I set the ble_dfu_buttonless_async_svci_init right after log_init(). From my original post, the debug info showed ble_dfu_buttonless_async_svci_init() called and success.

    As I mentioned, everything is fine for DFU without bond. I also tried other application withDFU and Bond. It worked fine too. But just for this application after change the bond setting, the program stuck at    

    err_code = ble_dfu_buttonless_init(&dfus_init);
        APP_ERROR_CHECK(err_code);

    I suspect it may be some conflict between different services. Can you please take a look at my services_init() and main() in original post?

    Or I can send you my source file with everything there.

    Thanks a lot!

    -Lei

  • Hi Lei,

    I didn't notice that you had ble_dfu_buttonless_async_svci_init() in your service initialization. I took a closer look at the code now, and I think the error may be coming from ble_dfu_buttonless_init::ble_dfu_buttonless_backend_init(). It will return this error if the Peer manager is not initialized. Could this be it?

    Best regards,

    Vidar

  • Hi Vidar,

    The ble_dfu_buttonless_async_svci_init is in service Initialization. I tried to move it right after log_init() in main() but got the same error.

    The current init sequence in Main() is okay for DFU without bond. It's like bond changes something.

    I just tried to move the peer_manager_init before service_init. It seems the program passed the service_init but stuck at advertising_init(), more specifically at    

    err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
        APP_ERROR_CHECK(err_code);

    with "ERROR 7, INVALID_PARAM".

    Can I send you my source code?

    Here is my advertising_init() code

    static void advertising_init(void)
    {
        ret_code_t           err_code;
        ble_advdata_t        advdata;
        ble_advdata_t        srdata;
        ble_gap_adv_params_t adv_params;
    //        ble_advertising_init_t init;


        ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};

        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));

        advdata.name_type          = BLE_ADVDATA_FULL_NAME;
        advdata.include_appearance = true;
        advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;


        memset(&srdata, 0, sizeof(srdata));
        srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
        srdata.uuids_complete.p_uuids  = adv_uuids;

        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);

        err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
        APP_ERROR_CHECK(err_code);

        // Start advertising.
        memset(&adv_params, 0, sizeof(adv_params));
        adv_params.p_peer_addr   = NULL;
        adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
        adv_params.interval      = APP_ADV_INTERVAL;

        adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
        adv_params.duration        = APP_ADV_DURATION;
        adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;

        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
        APP_ERROR_CHECK(err_code);
    }

  • Hi Vidar,

    Can I create a private case ticket? So I can upload everything for your reference.

    Thanks a lot!

    -Lei

  • Hi Lei,

    Yes, please do. It's probably easier if I can debug it here. Just create a new private ticket. I'll assign it to myself tomorrow.

Reply Children
No Data
Related