From b33647bbac259764f5dbcf031224d12cd1224882 Mon Sep 17 00:00:00 2001 From: Eugene Lozovoy Date: Sat, 31 Aug 2024 16:23:32 +0300 Subject: [PATCH] usb: fix "USB configure error: 13" for some peripherials I've encountered this error with 8bitdo usb wireless adapter 2. Unfortunatelly this adapter still doesn't work, but for some other reason. See also https://github.com/felis/USB_Host_Shield_2.0/blob/ef5b046d5058b561ddaee69bc41b7e3f672aa9ee/Usb.cpp#L621 --- usb/hub.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/usb/hub.c b/usb/hub.c index c3da5c2..da395de 100644 --- a/usb/hub.c +++ b/usb/hub.c @@ -2,6 +2,7 @@ #include "usb.h" #include "timer.h" +#include "max3421e.h" static uint8_t usb_hub_clear_hub_feature(usb_device_t *dev, uint8_t fid ) { return( usb_ctrl_req( dev, USB_HUB_REQ_CLEAR_HUB_FEATURE, @@ -242,9 +243,21 @@ static uint8_t usb_hub_port_status_change(usb_device_t *dev, uint8_t port, hub_e usb_hub_clear_port_feature(dev, HUB_FEATURE_C_PORT_RESET, port, 0); usb_hub_clear_port_feature(dev, HUB_FEATURE_C_PORT_CONNECTION, port, 0); - rcode = usb_configure(dev->bAddress, port, + for(unsigned retries = 0; retries < 3; retries++) { + rcode = usb_configure(dev->bAddress, port, (evt.bmStatus & USB_HUB_PORT_STATUS_PORT_LOW_SPEED)!=0 ); - if (rcode) iprintf("USB configure error: %d\n", rcode); + if (!rcode) + break; + iprintf("USB configure error: %d\n", rcode); + if (rcode == hrJERR) { + // Some devices returns this when plugged in - trying to initialize the device again usually works + timer_delay_msec(100); + continue; + } + else { + break; + } + } bResetInitiated = false; break;