There is bug in SDK 15.3 in the way the DB discovery procedure handles SoftDevice busy state. In the discovery_start() function the code checks return code from sd_ble_gattc_primary_services_discover(). If it is NRF_ERROR_BUSY then it sets p_db_discovery->discovery_pending to true. This field is then checked in ble_db_discovery_on_ble_evt(). If it is true then discovery process is restared by calling discovery_start(). So far so good.
But what happens if a service is finally discovered? The function on_primary_srv_discovery_rsp() doesn't set p_db_discovery->discovery_pending to false. The result is that discovery process loops and after some time ends with HardFault. As a temporary fix I have added
p_db_discovery->discovery_pending = false;
after
if (p_ble_gattc_evt->gatt_status == BLE_GATT_STATUS_SUCCESS)
in ble_db_discovery.c
Please fix it in next SDK release.
Logs showing the problem in case of ANCS discovery are as follows:
<debug> app: Could not find the remote database in flash. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> nrf_ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0. <debug> nrf_ble_gatt: sd_ble_gattc_exchange_mtu_request() on connection 0x0 returned busy, will retry. <debug> nrf_ble_gatt: Updating data length to 251 on connection 0x0. <info> app: Processing event 7 <info> app: Con<debug> nrf_ble_gatt: Data length updated to 27 on connection 0x0. <debug> nrf_ble_gatt: max_rx_octets: 27 <debug> nrf_ble_gatt: max_tx_octets: 27 <debug> nrf_ble_gatt: max_rx_time: 328 <debug> nrf_ble_gatt: max_tx_time: 328 <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> nrf_ble_gatt: Peer on connection 0x0 requested an ATT MTU of 185 bytes. <debug> nrf_ble_gatt: Updating ATT MTU to 185 bytes (desired: 247) on connection 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <info> app: Updated file 49152 record key 49160 record id 304 result 0 <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Discovery of service with UUID 0x1801 completed with success on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0xF431 on connection handle 0x0. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0. <debug> ble_db_disc: Found service UUID 0x1801. <debug> ble_db_disc: Starting discovery of service with UUID 0x1801 on connection handle 0x0.