Skip to content

Commit 0de8847

Browse files
Crashes after calling btstack_cyw43_deinit (#2446)
You can deinitialise cyw43 and btstack by calling btstack_cyw43_deinit but its pending and timeout workers are not removed which means they can keep running, whcih causes a crash. Add a btstack_run_loop_async_context_deinit method and call this from btstack_cyw43_deinit.
1 parent 31fadf4 commit 0de8847

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/rp2_common/pico_btstack/btstack_run_loop_async_context.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ const btstack_run_loop_t *btstack_run_loop_async_context_get_instance(async_cont
129129
return &btstack_run_loop_async_context;
130130
}
131131

132+
void btstack_run_loop_async_context_deinit(void) {
133+
if (btstack_async_context) {
134+
async_context_remove_at_time_worker(btstack_async_context, &btstack_timeout_worker);
135+
async_context_remove_when_pending_worker(btstack_async_context, &btstack_processing_worker);
136+
btstack_async_context = NULL;
137+
}
138+
}
139+
132140
static void btstack_timeout_reached(__unused async_context_t *context, __unused async_at_time_worker_t *worker) {
133141
// simply wakeup worker
134142
async_context_set_work_pending(btstack_async_context, &btstack_processing_worker);

src/rp2_common/pico_btstack/include/pico/btstack_run_loop_async_context.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ extern "C" {
2323
*/
2424
const btstack_run_loop_t *btstack_run_loop_async_context_get_instance(async_context_t *context);
2525

26+
/**
27+
* \brief Deinitialize the BTstack state to stop it using the async_context API
28+
* \ingroup pico_btstack
29+
*/
30+
void btstack_run_loop_async_context_deinit(void);
31+
2632
#ifdef __cplusplus
2733
}
2834
#endif

src/rp2_common/pico_cyw43_driver/btstack_cyw43.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool btstack_cyw43_init(async_context_t *context) {
6969
void btstack_cyw43_deinit(__unused async_context_t *context) {
7070
hci_power_control(HCI_POWER_OFF);
7171
hci_close();
72+
btstack_run_loop_async_context_deinit();
7273
btstack_run_loop_deinit();
7374
btstack_memory_deinit();
7475
}

0 commit comments

Comments
 (0)