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

Multiple FreeRTOS Softdevice Tasks not Working

Hi,

I want to create 2 softdevice tasks, 1 for advertising and 1 for scanning. I have ported the dependencies and some code from the ble_app_freertos_pca10040_s132 into the ble_app_hrs_rscs_relay_pca10040_s132  example. When I call nrf_sdh_freertos_init(adv_scan_start, &erase_bonds) the board works as intended, and does both advertising and scanning correctly, as far as I can tell. When I have two calls to nrf_sdh_freertos_init, however, I get an ERROR 8 (Invalid State) on the advertising side. Why does this occur when I try to run them as 2 separate threads? 

Advertising and Scanning code:

static void scanning_start(void * p_erase_bonds)
{
   scan_start();
    
}
static void advertising_start(void * p_erase_bonds)
{
    bool erase_bonds = *(bool*)p_erase_bonds;

    if (erase_bonds)
    {
        delete_bonds();
        // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
    }
    else
    {
        //scan_start();
        ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
        //adv_scan_start();
        //ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
        //APP_ERROR_CHECK(err_code);
    }
}

Calls to create threads in Main:

    nrf_sdh_freertos_init(scanning_start, &erase_bonds);

    nrf_sdh_freertos_init(advertising_start, &erase_bonds);
    // Start FreeRTOS scheduler.
    vTaskStartScheduler();

Serial Output: 

app: ERROR 8 [NRF_ERROR_INVALID_STATE] at C:\Users\vikra\Downloads\NRFClean\nRF5_SDK_14.2.0_17b948a\examples\ble_central_and_peripheral\experimental\ble_app_hrs_rscs_relay\main.c:1367

Where the error line is line 19 in the advertising_start function.

Related