I'm debugging the function of switching between ESB and BLE. My general approach is as follows:
-
Initially, the BLE protocol stack is initialized, advertising starts running, and ESB broadcasting is operated within Timeslot.
-
If the ESB broadcast establishes a connection with the peer ESB device, I call
nrf_sdh_disable_request()to disable BLE and run ESB exclusively. -
When I need to perform BLE pairing, I trigger it via a button press—disconnect ESB, then reinitialize the BLE protocol stack and advertising. However, at this stage, the reinitialization reports errors, such as
services_init(). I suspect this is due to parts of the code that cannot be reinitialized.
Is there a method to fully reinitialize the protocol stack along with the corresponding services and advertising?
Here is a rough outline of my code:
//init ble softdevices
void hid_devices_init(void)
{
//static bool is_init = false;
NRF_LOG_INFO("HID devices init start.");
power_management_init();
ble_stack_init();
ble_address_init();
gap_params_init();
gatt_init();
services_init();
sensor_simulator_init();
conn_params_init();
buffer_init();
peer_manager_init();
}
//disable ble softdevice
void ble_switch_to_esb()
{
app_timer_pause();
nrf_sdh_disable_request();
esb_stop();
esb_start();
app_timer_resume();
}
//reinit ble softdevice
void hid_devices_init(void)
{
//static bool is_init = false;
NRF_LOG_INFO("HID devices init start.");
power_management_init();
ble_stack_init();
ble_address_init();
gap_params_init();
gatt_init();
services_init();
sensor_simulator_init();
conn_params_init();
buffer_init();
peer_manager_init();
}I have tried the following re-enabling method: when reinitializing the protocol stack, only the SoftDevice is reinitialized, while GAP, GATT, services, connection parameters, etc., are not reinitialized. However, the advertising name obtained is incorrect, and other functionalities are likely abnormal as well.
void hid_devices_reinit(void)
{
static bool is_init = false;
NRF_LOG_INFO("HID devices init start.");
power_management_init();
ble_stack_init();
if(!is_init)
{
ble_address_init();
gap_params_init();
gatt_init();
services_init();
sensor_simulator_init();
conn_params_init();
buffer_init();
peer_manager_init();
}
is_init = true;
}Is this approach of repeatedly switching between BLE and a proprietary protocol feasible? Is it recommended? If possible, could you recommend a workflow for repeatedly reinitializing the softdevice stack and other related services (GAP, GATT, services, advertising)?