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

dfu with IS_SRVC_CHANGED_CHARACT_PRESENT set to 0

Hi, I am develop a project with dfu and bond features. I found that in dfu project, IS_SRVC_CHANGED_CHARACT_PRESENT is always set to 1. In my understanding, if set this to 1, each time phone connect to my device, it will read the services, then slow down the connection process. Am I right? If above is true, is it possible to set IS_SRVC_CHANGED_CHARACT_PRESENT to 0, that I make bootloader and my application project with the same services?

Parents
  • Hi Loste,

    We set IS_SRVC_CHANGED_CHARACT_PRESENT to 1 is that when we switch from application to bootloader and vice versa, the attributable may change and we need to send service changed indication to tell the central to redo the service discovery.

    You were correct that it may take longer to discover the service if we have service changed characteristic. But I don't think it will increase the discovery time significantly. And note that the central don't do service discovery every time it connects to a bonded device. Only the first time and when receiving service changed indication.

    If your application and the bootloader has the same attribute table, it's true that you can set IS_SRVC_CHANGED_CHARACT_PRESENT to 0.

  • Hi Hung Bui, my application and my bootloader have the same attribute table (same Service, same Chacteristics). But  when i set IS_SRVC_CHANGED_CHARACT_PRESENT to 0, the dfu process can not be done. My question is here  Can not save boot loader setting . 

  • If you test with the unmodified bootloader, do you see the same thing ? I would suggest you to create a new case for your issue. 

  • Thanks for your suggestion. I have test the unmodified bootloader with nRF-Toolbox and see the same result. If you are working with some kind of bootloader project, can you test and confirm my issue?

  • Hi Hoai, 

    I'm sorry, the issue happenned when you change IS_SRVC_CHANGED_CHARACT_PRESENT = 0 , right  ? Then if you test with the unmodified bootloader, there would be an problem because the phone will cache the attribute table and wouldn't see the DFU service. 

    I assume you would need to modify the bootloader to have your application's service as well ? 

    I would suggest you to create a private case that you can share with us your firmware. You can create a dummy version of your application that only do the buttonless DFU (but has all the service of your application). And the bootloader that you modified to have the services of your application as well. 

    Please mention my name in the case so the system knows to assign to me.

  • Thanks

    That the reason my bootloader and my application project have the same attribute table.

    Finally i found where my code go wrong.

    /**@brief Function for the Application's S110 SoftDevice event handler.
     *
     * @param[in] p_ble_evt S110 SoftDevice event.
     */
    static void on_ble_evt(ble_evt_t * p_ble_evt)
    {
        uint32_t                              err_code;
        ble_gatts_rw_authorize_reply_params_t auth_reply;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
    
                m_conn_handle    = p_ble_evt->evt.gap_evt.conn_handle;
                m_is_advertising = false;
                break;
    
            case BLE_GAP_EVT_DISCONNECTED:
                {
                    uint8_t  sys_attr[128];
                    uint16_t sys_attr_len = 128;
    
                    m_direct_adv_cnt = APP_DIRECTED_ADV_TIMEOUT;
    
                    err_code = sd_ble_gatts_sys_attr_get(m_conn_handle,
                                                         sys_attr,
                                                         &sys_attr_len,
                                                         BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
                    APP_ERROR_CHECK(err_code);
    
                }
                if (!m_tear_down_in_progress)
                {
                    // The Disconnected event is because of an external event. (Link loss or
                    // disconnect triggered by the DFU Controller before the firmware update was
                    // complete).
                    // Restart advertising so that the DFU Controller can reconnect if possible.
                    advertising_start();
                }
    
                m_conn_handle = BLE_CONN_HANDLE_INVALID;
    
                break;

    In above function, when we get BLE_GAP_EVT_DISCONNECTED,

    we also call

     

                    err_code = sd_ble_gatts_sys_attr_get(m_conn_handle,
                                                         sys_attr,
                                                         &sys_attr_len,
                                                         BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
                    APP_ERROR_CHECK(err_code);

    I don't know why we call that function, but it will return an NRF_ERROR_NOT_FOUND and make system reboot. I think that removing service change characteristic make my Generic Attribute Service empty and make that error. So my current solution is remove APP_ERROR_CHECK(err_code); line and use the original bootloader_settings_save method.

     

  • I'm glad that you found the issue. NRF_ERROR_NOT_FOUND  will return if you don't have any system characteristic with CCCD (of GAP and GATT services not your application's service) , when you call sd_ble_gatts_sys_attr_get().

    In this case you removed service changed characteristic (which has CCCD).

    So if you check the return code and ignore NRF_ERROR_NOT_FOUND, you should be fine. 

Reply
  • I'm glad that you found the issue. NRF_ERROR_NOT_FOUND  will return if you don't have any system characteristic with CCCD (of GAP and GATT services not your application's service) , when you call sd_ble_gatts_sys_attr_get().

    In this case you removed service changed characteristic (which has CCCD).

    So if you check the return code and ignore NRF_ERROR_NOT_FOUND, you should be fine. 

Children
No Data
Related