I have an iOS App which is just designed for updating our device firmware OTA. It uses the Nordic DFU library, updated to the latest cocoapod. It connects to our device, and then starts DFU with the library.
In the firmware I'm using S132 v7.0.1 SDK 16.0.0 on nRF52832.
Because the device has not connected before, when the library writes the enter bootloader command the device starts a new bond. This is written to flash on the device, but it seems that sometimes the buttonless DFU library attempts to set the bond info in the bootloader before the peer manager has finished writing to flash.
The log:
<info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0 <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding <info> app: Paired <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update <info> app: New Bond <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update <info> NRF_DFU_BLE_BONDED: Writing peer data to the bootloader... 1 <error> NRF_DFU_BLE_BONDED: Failed to set peer data: 0011 <error> NRF_DFU_BLE_BONDED: Failed to enter bootloader: 0006 <error> app: Request to enter bootloader mode failed asynchroneously. <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Central address resolution, action: Update
I have added some additional logs here that are not in the buttonless DFU by default to print the relevant error codes. Stepping through what is happening:
- Bonding occurs
- The buttonless lib attempts to write peer data to bootloader (1 = svci state = initialized)
- As state is initialized, in nrf_dfu_svci_handler.c line 84 peer data write is attempted
- In nrf_dfu_settings_svci.c line 83 sd_flash_write returns NRF_ERROR_BUSY
- This is returned to buttonless lib (failed to set peer data error 0x11 == 17 == NRF_ERROR_BUSY)
- Peer manager handler indicates peer data write is complete (central address resolution)
Is there any way to prevent this? It seems like it is something that should be handled in the SDK.