Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Disable Softdevice from observer crashes; "don't do that" should be documented?

I tried to disable Softdevice from within an observer (kind ble_observer.) It seems to crash. Instead, I just schedule another task to run (and disable the Softdevice) after the observer completes. That seems to work better. Should it be stated in the documentation: you shouldn't disable the SD from within an observer?

I can't say whether the call to nrf_sdh_disable_request() returned an error, since my code is not checking the result.  But a following  assert(!nrf_sdh_is_enabled()) did not assert, so I presume no error was returned.

The example/multiprotocol/ble_gzl... does not exercise this problem, since it disables SD from the main context.

My application is multiprotocol. As soon as a user uses BT to find, connect, and write some characteristic, they are done with BT, which I observe, and then want to disable SD.

Parents
  • Hi,

    Thank you for reporting this.

    What is happening is that we are pulling events from the SoftDevice in nrf_sdh_ble_evts_poll(), and are forwarding them to the observers. We do this until we no longer have any new events from the SoftDevice to process, and sd_ble_evt_get() returns NRF_ERROR_NOT_FOUND. But if we disable the SoftDevice in one of the observers, the next call to sd_ble_evt_get() will return NRF_ERROR_SOFTDEVICE_NOT_ENABLED, and we will enter the error-handler because only NRF_ERROR_NOT_FOUND and NRF_SUCCESS are considered valid return codes.

Reply
  • Hi,

    Thank you for reporting this.

    What is happening is that we are pulling events from the SoftDevice in nrf_sdh_ble_evts_poll(), and are forwarding them to the observers. We do this until we no longer have any new events from the SoftDevice to process, and sd_ble_evt_get() returns NRF_ERROR_NOT_FOUND. But if we disable the SoftDevice in one of the observers, the next call to sd_ble_evt_get() will return NRF_ERROR_SOFTDEVICE_NOT_ENABLED, and we will enter the error-handler because only NRF_ERROR_NOT_FOUND and NRF_SUCCESS are considered valid return codes.

Children
Related