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

Softdevice proper re-enable services initialization problems

Hi,

I'm having problems with proper softdevice reinitialization. What I'm trying to do is work out proper reinit solution - what I'm doing is enabling BLE_stack and all the other things in main.c and start advertising for 10 seconds. After 10 secons I'm calling sd_softdevice_disable() and after next 10 seconds I want to enable softdevice again. I'm using timer based at 1 second interval and counting up to 10 and 20 for Softdevice disable/enable. My problem is that I can re-enable softdevice and start advertising - that works fine, but when I try to add service_init() and all the other my BLE stack falls apart and I'm getting errors. 

Please could you provide me proper way to reinitialize softdevice with all the gap/gatt functions? I would really appreciate that. I'm including piece of code that I use for softdevice enable/disable. 

Just to be clear: I use internal rc oscillator with the following config:

 nrf_clock_lf_cfg_t const clock_lf_cfg =
    {
        .source       = NRF_CLOCK_LF_SRC_RC,
        .rc_ctiv      = 16,
        .rc_temp_ctiv = 2,
        .accuracy     = NRF_CLOCK_LF_ACCURACY_20_PPM
    };

uint8_t *ptr;
uint8_t softdevicex=1; //softdevice active at the beggining.

void timer_timeout_handler(void * p_context) //EVENT TRIGGERED EVERY 1 S.
{     
    toggle++; //just for counting up, every 1 second that increments
    if(toggle>10 && softdevicex==1)
    {
      sd_softdevice_disable(); //disabling softdevice
      softdevicex = 0;
      if(sd_softdevice_is_enabled(ptr))
      {
        NRF_LOG_INFO("SoftDevice Enabled.");
      }
      else NRF_LOG_INFO("SoftDevice Disabled.");
    }

    
    if(softdevicex==1) //if softdevice is enabled then update characteristics
    {
      if(toggle%2==0) //FUNCTIONS JUST FOR DATA UPDATING FOR CHARACTERISTIC
      temperature = 70;   
      else temperature = 90;
      our_temperature_characteristic_update(&m_our_service, &temperature);
      NRF_LOG_INFO("Characteristics updated.");
    }


  if(toggle>20 && softdevicex==0)
    {     
          
          uint32_t err_code;
          uint32_t new_ram=0;
         
          err_code = sd_softdevice_enable(NRF_SDH_CLOCK_LF_RC_CTIV, app_error_fault_handler);
          APP_ERROR_CHECK(err_code);
          
          if (err_code != NRF_SUCCESS)
          {
              return err_code;
          }
         
          err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &new_ram);
          APP_ERROR_CHECK(err_code);
          err_code = nrf_sdh_ble_enable(&new_ram);
          APP_ERROR_CHECK(err_code);


          
          gap_params_init();
          gatt_init();
          services_init();
          advertising_init();
          conn_params_init();
          peer_manager_init();
          advertising_start(erase_Bondx); //advertising start
          softdevicex=1; //softdevice started indication
          NRF_LOG_INFO("SoftDevice Re-enabled");
          toggle=0; //erase counter value
    }
}

THANK YOU IN ADVANCE Slight smile

Parents
  • I've noticed that advertising_init() and services_init() generate the problems. If I comment out both softdevice works fine except that services aren't available. So I think that advertising init should be removed permanently, but I don't know what to do about services_init(). There has to be something that has to be done differently in order to enable services correctly. 

  • Before looking into the issue, could you explain why you need to disable and enable the softdevice every 10 sec?

    It's possible to stop the advertising, change the advertisng data, update characteristics data, start advertising again, etc, etc, etc, without disabling/enabling the SoftDevice...

  • Hi, thanks for your response.

    10 secs is just for testing purposes, on my main application I would need to disable softdevice, go to sleep for about 3 hours, wake up, take measurements, enable soft device, start advertising, go into connection with central send data, switch off softdevice and go back to sleep for next 3 hours (with system ON solution for keeping RTC alive).

    The fact is I'm beginner with nrf development and this is the scenario I think would be most energy effective. I may be in a mistake so if you could provide me better and more logical solution I would be very grateful. The device will be battery powered.

    Thanks 

  • this is the scenario I think would be most energy effective.

    The Softdevice is powered optimized, and you will not save any significant amunt of energy by disabling it. You only need to disconnect from the central, and turn off advertising. You start your 3 hour timer, and when the timer expires, you start the advertising again. There is no need to disable the softdevice to save energy.

    Some additional notes:

    Remember to turn off logging to save power, i.e. set NRF_LOG_ENABLED to 0 in sdk_config.h

    Your clock configuration is not correct, when using the internal RC oscillator as LF clock source, you need to set the accuracy to NRF_CLOCK_LF_ACCURACY_500_PPM.

Reply
  • this is the scenario I think would be most energy effective.

    The Softdevice is powered optimized, and you will not save any significant amunt of energy by disabling it. You only need to disconnect from the central, and turn off advertising. You start your 3 hour timer, and when the timer expires, you start the advertising again. There is no need to disable the softdevice to save energy.

    Some additional notes:

    Remember to turn off logging to save power, i.e. set NRF_LOG_ENABLED to 0 in sdk_config.h

    Your clock configuration is not correct, when using the internal RC oscillator as LF clock source, you need to set the accuracy to NRF_CLOCK_LF_ACCURACY_500_PPM.

Children
Related