From 30c850db3f5f8c78c0c95a28ee9c5aa8788fbcd8 Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sun, 18 Oct 2026 14:07:40 +0800 Subject: [PATCH] fix: release chestnut USB handle while modeld loads --- openpilot/system/hardware/chestnut/monitoring.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/openpilot/system/hardware/chestnut/monitoring.py b/openpilot/system/hardware/chestnut/monitoring.py index 3a8b21f61..dae2b99ba 100644 --- a/openpilot/system/hardware/chestnut/monitoring.py +++ b/openpilot/system/hardware/chestnut/monitoring.py @@ -5,6 +5,7 @@ import usb1 import openpilot.cereal.messaging as messaging from openpilot.cereal.services import SERVICE_LIST from openpilot.common.hardware.usb import CHESTNUT_USB_PRODUCT, get_usb_state, is_chestnut_usb_id +from openpilot.common.params import Params def read_chestnut_state(handle, gpu_state=None): @@ -26,11 +27,18 @@ def read_chestnut_state(handle, gpu_state=None): def chestnut_state_thread(end_event): pm = messaging.PubMaster(['chestnutState']) sm = messaging.SubMaster(['chestnutGpuState']) + params = Params() with usb1.USBContext() as context: handle = None try: while not end_event.is_set(): - if handle is None: + # modeld owns the chestnut USB interface while loading/running the big model. + # Do not hold a second libusb handle: libusb_set_configuration returns EBUSY. + modeld_owns_usb = params.get_bool("ChestnutLoading") or params.get_bool("ChestnutActive") + if handle is not None and modeld_owns_usb: + handle.close() + handle = None + if handle is None and not modeld_owns_usb: devices = [d for d in get_usb_state() if is_chestnut_usb_id(d['vendorId'], d['productId']) and d['product'] == CHESTNUT_USB_PRODUCT] if len(devices) == 1: