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
  • Hi Jared,

    here is my configuration for the link count:

    // <o> NRF_SDH_BLE_PERIPHERAL_LINK_COUNT - Maximum number of peripheral links. 
    #ifndef NRF_SDH_BLE_PERIPHERAL_LINK_COUNT
    #define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1
    #endif
    
    // <o> NRF_SDH_BLE_CENTRAL_LINK_COUNT - Maximum number of central links. 
    #ifndef NRF_SDH_BLE_CENTRAL_LINK_COUNT
    #define NRF_SDH_BLE_CENTRAL_LINK_COUNT 1
    #endif
    
    // <o> NRF_SDH_BLE_TOTAL_LINK_COUNT - Total link count. 
    // <i> Maximum number of total concurrent connections using the default configuration.
    
    #ifndef NRF_SDH_BLE_TOTAL_LINK_COUNT
    #define NRF_SDH_BLE_TOTAL_LINK_COUNT 2
    #endif

    The entire configuration file:

    3858.sdk_config.h

  • Hi,

    Could you upload a minimal project that will reproduce the issue on a development kit?  I can make the case private first if you prefer it,

    Is it possible to make the central and the peripheral co-existing in the same device independently without any interference?

     Yes, this is done in the multirole example in the SDK.

    regards

    Jared 

  • Jared,

    thank you very much for support. I have lots of pressure at work these days, so will be able to create the minimal project reproducing the issue only in about two weeks. Please, let's postpone this thread until then.

  • Understandable. Just update the thread when you have time, I'll be happy to help you then! :) 

  • 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

Related