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

Advertising crash when central and peripheral run simultaneously on the same device

Hi everyone,

we are using nRF52832 with SDK 15.0.0.

Our device uses one central and one peripheral simultaneously that are running independently. Recently, I've faced a stack crash in the next scenario:

1) The central is scanning and the peripheral is advertising.
2) BLE_GAP_EVT_ADV_REPORT event happens (scan has succeeded).
3) The central calls sd_ble_gap_connect() to connect to peer and the function returns NRF_SUCCESS.
4) Peripheral advertisement set is terminated (BLE_GAP_EVT_ADV_SET_TERMINATED).
5) The peripheral gets into adv_event_handler() with the event set to BLE_ADV_EVT_IDLE.
6) From BLE_ADV_EVT_IDLE the peripheral calls ble_advertising_start() to restart advertising after timeout.
7) ble_advertising_start() fails with the error NRF_ERROR_INVALID_STATE.
8) Just after that the central connects successfully and BLE_GAP_EVT_CONNECTED event happens.
9) All the following calls of ble_advertising_start() fail with the same error NRF_ERROR_INVALID_STATE, so it's not possible to restart advertising anymore without microcontroller restart.

The advertising module seems to crash if advertising is restarted between sd_ble_gap_connect() call and BLE_GAP_EVT_CONNECTED event. It happens not always, but it's easy to catch this crash if the adverting timeout is short enough. Sometimes when ble_advertising_start() crashes, also BLE_GAP_EVT_CONNECTED gets lost even though the central connects successfully to its peer.

Currently, we've found workaround to disable advertising with sd_ble_gap_adv_stop() right before the central tries to connect and than re-enable peripheral advertising from BLE_GAP_EVT_CONNECTED event handler. But it makes me thinking that the central and the peripheral may share some resources of the BLE stack and it may cause collisions if they run at the same time.

So, my question is if there are any procedures from the central and the peripheral that are mutually exclusive and can lead to the BLE stack crash when they run in the same time? Is it possible to make the central and the peripheral co-existing in the same device independently without any interference?

Parents Reply Children
Related