summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2025-11-03 22:00:05 +0800
committersakumisu <[email protected]>2025-11-03 22:01:45 +0800
commit649ad6686ba34be28cbe3b3a2da112787100e68c (patch)
treec25b5b39098b28f5364be0e401ca92655fcf2043
parent868dbee668945f0ac132078333f19a7aa11885d4 (diff)
update(core/usbh_core): add retry for control transfer, some devices are flakey
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--core/usbh_core.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/usbh_core.c b/core/usbh_core.c
index 43ff7961..4d4f47df 100644
--- a/core/usbh_core.c
+++ b/core/usbh_core.c
@@ -705,6 +705,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) {
@@ -717,12 +718,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;
}