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.

Parents
  • I appear to have managed to get past that but by calling the following to shutdown the SD:

    void ble_stack_teardown(void)
    {
         ret_code_t err_code;

         if (!nrf_sdh_is_enabled())
              return;

         err_code = nrf_sdh_disable_request();
         APP_ERROR_CHECK(err_code);

        //Wait until soft device reports 'disabled' state. 
        while (nrf_sdh_is_enabled()) {}
    }

    Unfortunately, its now dying elsewhere when I attempt to restart advertising ble_advertising.c line 667


    if (p_advertising->evt_handler != NULL)
    {
         p_advertising->evt_handler(p_advertising->adv_evt);
    }

    I assume that this is because the advertising module has been re-initialised - I don't find a teardown function for this module, but it looks to me that this is what is required.

    Nigel

Reply
  • I appear to have managed to get past that but by calling the following to shutdown the SD:

    void ble_stack_teardown(void)
    {
         ret_code_t err_code;

         if (!nrf_sdh_is_enabled())
              return;

         err_code = nrf_sdh_disable_request();
         APP_ERROR_CHECK(err_code);

        //Wait until soft device reports 'disabled' state. 
        while (nrf_sdh_is_enabled()) {}
    }

    Unfortunately, its now dying elsewhere when I attempt to restart advertising ble_advertising.c line 667


    if (p_advertising->evt_handler != NULL)
    {
         p_advertising->evt_handler(p_advertising->adv_evt);
    }

    I assume that this is because the advertising module has been re-initialised - I don't find a teardown function for this module, but it looks to me that this is what is required.

    Nigel

Children
  • Hi
    You are correct in calling a  nrf_sdh_disable_request() before you disable the softdevice. The correct way of de initializing the softdevice is shown in this chart.
     
    veletron said:
    Unfortunately, its now dying elsewhere when I attempt to restart advertising ble_advertising.c line 667

     How are you restarting the advertising? Are you calling StartAdvertising()? What is the error code that is thrown? 

    Jared 

  • Hi

    I got this working in the end, mostly by tracking the current state of the comms: idle, advertising, advertising-paired, connected etc, and doing whats necessary: