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
  • Please, find the minimal test project attached. The advertising timeout BLE_APP_ADV_FAST_TIMEOUT is set small here (300ms) that makes the issue easy to reproduce. To test the project an another peripheral that accepts connections is needed. It's MAC address is set in ble_app_peer_mac_addr structure. If advertising start chashes in time of central connection, then I additionally try to restart it after disconnect and it also crashes.

    adv_test.zip

    When the crash of advertising happens the Debug Terminal log looks like this:

    <info> app: adv started
    <info> app: adv timeout
    <info> app: central connected
    <info> app: adv start error = 8
    <info> app: adv timeout
    <info> app: on connect
    <info> app: on disconnect
    <info> app: adv restart error = 8

Children
  • Hi 

    Jared is currently out in vacation, and I will help out with this case in the mean time. 

    I have got your code to build, and setup a separate kit to act as a BLE peripheral with the required ble_app_peer_mac_addr. I can see that my second kit connects to your project, and I can also connect to your project from my phone as a central, but I have yet to see the error that you report. 

    All I can see is that if I connect from the phone the advertising stops until I disconnect the phone again. 

    Is there a particular sequence I need to follow to reproduce the issue?

    Best regards
    Torbjørn

Related