embassy-rs / nrf-softdevice

Apache License 2.0
269 stars 80 forks source link

There is currently no way to disable the SoftDevice #228

Closed mini-ninja-64 closed 6 months ago

mini-ninja-64 commented 9 months ago

My understanding is disabling the SoftDevice is useful as it allows for runtime configuration changes of the BLE stack, as config cannot be changed while the BLE SoftDevice is enabled.

sd_ble_cfg_set may be called at any time when the SoftDevice is enabled (see sd_softdevice_enable) while the BLE part of the SoftDevice is not enabled (see sd_ble_enable).

source

However this does not seem to currently be exposed safely through the crate.

I am still fairly new to Rust & the nRF5 series in general but can try and raise a PR for this (ノ◕ヮ◕)ノ*:・゚✧, if it would be a useful feature.

I am not sure what the API should look like for this? maybe like pub async fn disable(&self) on SoftDevice with either noop or panic if its not currently enabled :thinking:, but maybe there is a better option.

alexmoon commented 9 months ago

Unfortunately it’s not possible to disable the softdevice without introducing UB because the Softdevice is returned as a static reference. The current recommendation if you need to reconfigure the softdevice is to restart the microcontroller. It is pretty rare in practice for this the be an issue.

mini-ninja-64 commented 6 months ago

that makes sense, thank you, i have learned more from when i raised this issue and now understand :bowing_woman: