Proper Way to Temporarily Disable Softdevice

What is the proper way to temporarily disable the softdevice? Currently I have the following

  sd_ble_gap_adv_stop();

  bool disabled_softdevice = false;
  if (nrf_sdh_is_enabled())
  {
    nrf_sdh_disable_request();
    while (nrf_sdh_is_enabled()) {}
    disabled_softdevice = true;
  }

  nrf_nvmc_write_bytes((uint32_t)&NRF_UICR->CUSTOMER[0], ...);
  ...

  if (disabled_softdevice)
  {
    nrf_sdh_enable_request();
    while (!nrf_sdh_is_enabled()) {}
    disabled_softdevice = false;
  }

But soon after reenabling the softdevice asserts with the following callstack

SWI2_EGU2_IRQHandler
nrf_sdh_evts_poll
nrf_sdh_ble_evts_poll

where sd_ble_evt_get returns error code 0x4001.

  • HI Andreas, 

    which SDK and SoftDevice versions are you using?

    According to the S132 API doc sd_ble_evt_get should not return 0x4001. In fact 0x4001 is NRF_FAULT_ID_SDK_ERROR , i.e. an error stemming from a call to APP_ERROR_CHECK or APP_ERROR_CHECK_BOOL.

    Could you debug the project and set a breakpoint in app_error_handler and app_error_handler_bare and see if you end up there? If so post the call stack and the debug log output here.

    Best regards

    Bjørn