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

Runtime restart advertising with new MAC and services

Hi

I have a requirement to be able to re-start advertising with new parameters when told to do so over a Slave SPI interface. From other posts, it appears that there is no way to 'de-init' the soft-device - eg to remove and re-add services. Rather, the SD must be disabled and then re-initialised.

SDK 15.2, Soft device 132 V6.1

My new parameters consist of a new MAC address and a new service UUID (this is generated randomly, and used to uniquely identify an advertising device. The mobile learns the device MAC and GUID via NFC. Also in my advertising data is a mask detailing which of my three apps may connect at any time. The device is a medical product with both patient and clinician apps. I need to prevent the use of the clinician app in certain runtime modes.

My StartAdvertising(), and ble_stack_init() is as follows. The crash happens in  err_code = nrf_sdh_enable_request(); which returns NRF_ERROR_INVALID_STATE 0x08

Hoping someone has an idea of how to resolve the crash, my backup plan is to have the Nordic MCU reset (via SPI command from its master) and then await new config from the master, but that's a right pain. Restarting the SD without rebooting the MCU should work somehow.

NB - the ability to stop advertising, remove services, change manuf specific data and then restart advertising WITHOUT killing off and re-initialising the soft device would be a nice addition for a future SDK.

void StartAdvertising(void)
{
		ret_code_t err_code = sd_softdevice_disable();
		APP_ERROR_CHECK(err_code);
		
		nrf_delay_ms(500);  //tried a delay here - did not work
		
		ble_stack_init();  //  <-- crash is within this method, see below
		gap_params_init();
		gatt_init();  				
		services_init();
		advertising_init();
	    conn_params_init();
        peer_manager_init();  
		ConfigureTagForPatientAppNfcPairing();
		
		start_advertising(true);
}

void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();     //<-- The Crash Happens here
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}



void advertising_start(bool erase_bonds)
{
    if (erase_bonds == true)
    {
        delete_bonds();
        // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED event
    }
    else
    {
		whitelist_init();
        APP_ERROR_CHECK(ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST));
    }
}


		

Parents Reply Children
No Data
Related