From d482b7c7388d126a1571820a55925d320cfbafd0 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Mon, 3 Nov 2025 22:00:05 +0800 Subject: [PATCH] update(core/usbh_core): add retry for control transfer, some devices are flakey Signed-off-by: sakumisu <1203593632@qq.com> --- core/usbh_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/usbh_core.c b/core/usbh_core.c index 8860716a..bc4b4dca 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -729,6 +729,7 @@ int usbh_deinitialize(uint8_t busid) int usbh_control_transfer(struct usbh_hubport *hport, struct usb_setup_packet *setup, uint8_t *buffer) { struct usbh_urb *urb; + volatile uint8_t retry = 3; int ret; if (!hport || !setup) { @@ -741,12 +742,21 @@ int usbh_control_transfer(struct usbh_hubport *hport, struct usb_setup_packet *s usbh_print_setup(setup); +resubmit: usbh_control_urb_fill(urb, hport, setup, buffer, setup->wLength, CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT, NULL, NULL); ret = usbh_submit_urb(urb); if (ret == 0) { ret = urb->actual_length; } + if (ret < 0 && (ret != -USB_ERR_TIMEOUT)) { + retry--; + if (retry > 0) { + USB_LOG_WRN("Control transfer failed, errorcode %d, retrying...\r\n", ret); + goto resubmit; + } + } + usb_osal_mutex_give(hport->mutex); return ret; }