From c92a24d57eb71002974aa9d8e207166085b2336c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Fri, 24 May 2019 10:37:40 +0200 Subject: [PATCH] USBHost: Wait for device to implement SET ADDRESS The USB Device must change the address within 2 ms after completing SET ADDRESS status stage. Wait 2 ms before issuing GET DESCRIPTOR under the new address. In my case, this completely resolves the timeout issues. --- features/unsupported/USBHost/USBHost/USBHost.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/features/unsupported/USBHost/USBHost/USBHost.cpp b/features/unsupported/USBHost/USBHost/USBHost.cpp index c86196c3c2..b91f340d1f 100644 --- a/features/unsupported/USBHost/USBHost/USBHost.cpp +++ b/features/unsupported/USBHost/USBHost/USBHost.cpp @@ -163,6 +163,13 @@ void USBHost::usb_process() devices[i].activeAddress(true); USB_DBG("Address of %p: %d", &devices[i], devices[i].getAddress()); + // Wait for the device to actually set the address. The Status stage + // of SET ADDRESS happens before the device implements the request. + // According to Universal Serial Bus Specification Revision 2.0 chapter + // 9.2.6.3 Set Address Processing, the device is allowed SetAddress() + // recovery interval of 2 ms. + ThisThread::sleep_for(2); + // try to read again the device descriptor to check if the device // answers to its new address res = getDeviceDescriptor(&devices[i], buf, 8);