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

Need to run DFU procedure twice

Hi

NRF51822 with SD7, S110.

I have some troubles with DFU procedure. I uploaded standard OTA-DFU bootloader and S110 to my NRF. Everything works well with my code except DFU. I have to start DFU procedure twice.

When I'm trying to start DFU from Android nRF Master, my nRF uc enters bootloader and waiting in bootloader_dfu_start() procedure. But in nRF Master after a 3-4 seconds of 'starting DFU' message i see 'GATT ERROR'. Then Android finds "DfuTarg" peripheral and i can connect and proceed with success update.

I'm using Device Manager to remember devices bonding.

My 'reset_prepare' function

  static void reset_prepare(void)
{
	uint8_t err_code;
	goingToUpdate = 1;
	if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
	{
		err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
		APP_ERROR_CHECK(err_code);
	}

	if(WORK_MODE == SCHEDULE)
	{
		NRF_TIMER2->TASKS_STOP = 1;
		NRF_TIMER2->TASKS_CLEAR = 1;
		NRF_TIMER2->EVENTS_COMPARE[0] = 0;
		LED_PWM[0] = 0;
		LED_PWM[1] = 0;
		LED_PWM[2] = 0;
	}
	
	 //err_code = ble_conn_params_stop();
   //APP_ERROR_CHECK(err_code);
}

I tried both with or without ble_conn_params_stop();

DFU_init:

static void dfu_srv_init()
{
		uint32_t err_code;
		ble_dfu_init_t   dfus_init;
    // Initialize the Device Firmware Update Service.
    memset(&dfus_init, 0, sizeof(dfus_init));
    dfus_init.evt_handler    = dfu_app_on_dfu_evt;
    dfus_init.error_handler  = NULL; //service_error_handler - Not used as only the switch from app to DFU mode is required and not full dfu service.   
    err_code = ble_dfu_init(&m_dfu, &dfus_init);
    APP_ERROR_CHECK(err_code);
    
    dfu_app_reset_prepare_set(reset_prepare);
		//dfu_app_set_dm_handle(&m_application);
}

And second question: there is no dfu_app_set_dm_handle function in dfu api, but docs says there is that function.

Edit. After updating to newest nRF Master on Android, after trying to do DFU, nRF gets back to services list (on DFUTarg device, only one service is active)

  • Hi

    The thing that you describe with needing to start DFU twice, has something to do with that the central DFU app (on android and IOS) conserves the GATT table for a device that it was connected with before. When then trying to upload new firmware with the bootloader, the Android phone still has GATT table from HRS service (or whatever profile you were connected with before), but it really needs the GATT table for the bootloader. The upload fails and the phone disconnects and erases the GATT table. On the second attempt, there is no GATT table present on the phone so the app will perform a service discovery on the bootloader profile and then the upload works afterwards. The app developers are aware of this behavior and hopefully they will make improvements in future release

Related