From f7617168e2ce2e7ea2e49cba5962b69aed04900e Mon Sep 17 00:00:00 2001 From: renjie Date: Sun, 21 Jun 2026 14:06:23 +0800 Subject: fix(host): release spinlock in tuh_deinit to fix multi-rebuild panic tuh_rhport_init() calls osal_spin_init(&_usbh_spin), which under OPT_OS_PICO claims a hardware spinlock via critical_section_init(). There was no osal_spin_deinit(), so tuh_deinit() never released it: every host init/deinit cycle leaked one spinlock. RP2350 has a small spinlock pool, so a few usb_host rebuilds exhaust it and hw_claim_unused_from_range() panics (the long-standing "crashes on the 4th rebuild" bug). Add osal_spin_deinit() to all OSAL backends (critical_section_deinit for pico; no-op for none/freertos) and call it in tuh_deinit(). Verified 20/20 deinit+rebuild cycles on RP2350-Zero and Waveshare RP2350-USB-A (previously panicked on the 4th). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/host/usbh.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/host') diff --git a/src/host/usbh.c b/src/host/usbh.c index 6bafde368..d60feebb4 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -557,6 +557,11 @@ bool tuh_deinit(uint8_t rhport) { osal_mutex_delete(_usbh_mutex); _usbh_mutex = NULL; #endif + + // Release the spinlock claimed by osal_spin_init() in tuh_rhport_init(). + // Pairs with that init; without it each init/deinit cycle leaks a hardware + // spinlock and a few host rebuilds exhaust the pool (panic in claim). + osal_spin_deinit(&_usbh_spin); } return true; -- cgit v1.3.1 From f94e1f575e86a5f926e96f0b35f77fdb26228e60 Mon Sep 17 00:00:00 2001 From: HiFiPhile Date: Mon, 22 Jun 2026 21:25:06 +0200 Subject: usbh: remove Pico specific comment Signed-off-by: HiFiPhile --- src/host/usbh.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/host') diff --git a/src/host/usbh.c b/src/host/usbh.c index d60feebb4..9a7511fc8 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -558,9 +558,6 @@ bool tuh_deinit(uint8_t rhport) { _usbh_mutex = NULL; #endif - // Release the spinlock claimed by osal_spin_init() in tuh_rhport_init(). - // Pairs with that init; without it each init/deinit cycle leaks a hardware - // spinlock and a few host rebuilds exhaust the pool (panic in claim). osal_spin_deinit(&_usbh_spin); } -- cgit v1.3.1