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

DFU master from central

Hello, i'm trying to updade my firmaware using the DFU. I manage to do it with nRF Connect and nrfutil but i'm trying to a custom central to flash the software without any human interactions.

I already checked on the DEV zone and it looks like there is no exemples (even close) for what i'm trying to do.

I started to develop my own software and i'm facing issues regarding the discovery of the DFU when the module is in bootloader mode.

I started from the ble_app_uart_c as a template to discover the 128 bit caracteristics. I manage to discover the service but everytime the caracteristic's array is always empty.

Do you have any idea about where it could come from ? 

Parents
  • Hello,

    Do you do any filtering of the discovered database before you check the characteristic count? I'm wondering if there could be UUID/ UUID type mismatch that makes your callback ignore the discovered characteristics. Could you place a breakpoint at the beginning of your "ble_nus_c_on_db_disc_evt" callback and check if p_evt->params.discovered_db.char_count is 0 after the DFU service have been discovered?

     

Reply
  • Hello,

    Do you do any filtering of the discovered database before you check the characteristic count? I'm wondering if there could be UUID/ UUID type mismatch that makes your callback ignore the discovered characteristics. Could you place a breakpoint at the beginning of your "ble_nus_c_on_db_disc_evt" callback and check if p_evt->params.discovered_db.char_count is 0 after the DFU service have been discovered?

     

Children
  • I did several checks and the error actually comes from the discovering part i'm checking if the type is BLE_DB_DISCOVERY_COMPLETE and the type found is BLE_DB_DISCOVERY_SRV_NOT_FOUND.

    This error happened even though the uuid has been found correcly.

    I tried to add the UUID to the softdevice but i still get the same error.

    uint32_t ble_dfu_c_init(ble_dfu_c_t * p_ble_dfu_c)
    {
    uint32_t err_code;

    ble_uuid_t dfu_uuid;
    ble_uuid128_t dfu_base_uuid = DFU_UUID_BASE;

    uint8_t nordic_base_uuid_type;

    VERIFY_PARAM_NOT_NULL(p_ble_dfu_c);

    err_code = sd_ble_uuid_vs_add(&dfu_base_uuid, &nordic_base_uuid_type);
    VERIFY_SUCCESS(err_code);

    dfu_uuid.type = nordic_base_uuid_type;
    dfu_uuid.uuid = BLE_DFU_SERVICE_UUID;

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
    &dfu_uuid,
    &(p_ble_dfu_c->conn_handle));


    return ble_db_discovery_evt_register(&dfu_uuid);

    }

  • UPDATE : i found a other way to discover the service and it's working fine. I'm back to my first issue where i can't discover all the characteristics i do the discovery like this : 

    void ble_dfu_c_on_db_disc_evt(ble_dfu_c_t * p_ble_dfu_c, const ble_db_discovery_evt_t * p_evt)
    {
    	
    	ble_dfu_c_evt_t evt;
    	 memset(&evt,0,sizeof(evt));
    	
    	const ble_gatt_db_char_t * p_char = p_evt->params.discovered_db.charateristics;
    	
    		
    		//check if Thingy environement service was discovered
    		if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
            p_evt->params.discovered_db.srv_uuid.uuid == BLE_DFU_SERVICE_UUID &&
            p_evt->params.discovered_db.srv_uuid.type == BLE_UUID_TYPE_BLE)
        {
    				
    
    			NRF_LOG_INFO("nb char dfu %d\r\n",p_evt->params.discovered_db.char_count);
    			 for (uint32_t i = 0; i < p_evt->params.discovered_db.char_count; i++)
           {										
    					
    				 
    					switch (p_char[i].characteristic.uuid.uuid)
                {
    								case BLE_DFU_CONTROL_POINT_CHAR_UUID:
                        evt.params.peer_db.control_point_handle      = p_char->characteristic.handle_value;
                        evt.params.peer_db.control_point_cccd_handle = p_char->cccd_handle;
    										NRF_LOG_INFO("control point handle %d \r\n", p_char->characteristic.handle_value);
                        break;
    								case BLE_DFU_PACKET_CHAR_UUID:
    										evt.params.peer_db.packet_handle      = p_char->characteristic.handle_value;
    										NRF_LOG_INFO("config handle %d \r\n", p_char->characteristic.handle_value);
    									  break;
    								default:
    									NRF_LOG_INFO("Not found %d \r\n", p_char[i].characteristic.uuid.uuid);
                        break;
    						}
    				}
    			 
    
    				
    				
    				 //If the instance has been assigned prior to db_discovery, assign the db_handles
            if (p_ble_dfu_c->conn_handle != BLE_CONN_HANDLE_INVALID)
            {
    					if((p_ble_dfu_c->peer_dfu_db.control_point_handle				== BLE_GATT_HANDLE_INVALID)&&
    						 (p_ble_dfu_c->peer_dfu_db.control_point_cccd_handle  == BLE_GATT_HANDLE_INVALID)&&
    						 (p_ble_dfu_c->peer_dfu_db.packet_handle							== BLE_GATT_HANDLE_INVALID))
    					{
    							p_ble_dfu_c->peer_dfu_db = evt.params.peer_db;
    						  NRF_LOG_DEBUG("ERROR CONN HANDLE DFU.\r\n");
    					}
    					
    				}
    				
    				if (p_ble_dfu_c->evt_handler != NULL)
            {
    						evt.evt_type    = BLE_DFU_C_EVT_DISCOVERY_COMPLETE;
    						evt.conn_handle = p_evt->conn_handle;
    						p_ble_dfu_c->evt_handler(p_ble_dfu_c, &evt);
    				}
    				
    		}
    
    
    }

    unfortunately no characteristics are discovered the switch is going strait to default insted of discovering 

    the DFU without bound characteristics (0x0003). I still get the right number of characteristics but the wrong UUID.

  • Are you sure you've set the correct base uuid? Note that it is not the same as the one used with the NUS. 

        uint8_t uuid_type = BLE_UUID_TYPE_VENDOR_BEGIN;
    
        ble_uuid128_t const base_uuid128 =
        {
            {
                0x50, 0xEA, 0xDA, 0x30, 0x88, 0x83, 0xB8, 0x9F,
                0x60, 0x4F, 0x15, 0xF3,  0x00, 0x00, 0xC9, 0x8E
            }
        };
    
        err_code = sd_ble_uuid_vs_add(&base_uuid128, &uuid_type);
        APP_ERROR_CHECK(err_code);

    Here is the result from my test (used NUS client example from sdk 15 as starting point): 

  • That actually was it, wow i can't belive i made a such stupid mistake...

    Thanks a lot for your help ;) .

Related