Commit a8c176e
committed
extmod/zephyr_ble: Fix soft reset crash due to net_buf pool state.
After a MicroPython soft reset, Zephyr net_buf pools retain stale runtime
state (free list, uninit_count) from the previous BLE session. When
bt_enable() runs again, it assumes pools are in their initial state with
all buffers uninitialized and the free list empty. This mismatch causes
a HardFault when allocating or freeing buffers.
Add mp_net_buf_pool_state_reset() to restore all net_buf pools to their
initial state before BLE reinitialization. The function iterates over
all statically-defined pools and resets:
- .free lifo (set head/tail to NULL)
- .uninit_count (reset to buf_count)
- .lock spinlock
Tested with 8+ consecutive BLE init/deinit + soft_reset cycles on Pico W.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>1 parent d4240b9 commit a8c176e
File tree
3 files changed
+55
-0
lines changed- extmod/zephyr_ble
3 files changed
+55
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
465 | 466 | | |
466 | 467 | | |
467 | 468 | | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
468 | 475 | | |
469 | 476 | | |
470 | 477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
105 | 148 | | |
106 | 149 | | |
107 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
0 commit comments