From 4b5d5310d192ce0dfdeb5fe0fa5be074770c7687 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 11 Mar 2018 18:38:30 +0100 Subject: [PATCH] Make the loop depend on the clock frequency when sending out the resume signal, as the delay time is critical See: http://www.usbmadesimple.co.uk/ums_3.htm and https://www.nxp.com/docs/en/application-note/AN5385.pdf --- middleware/usb_1.0.0/device/usb_device_khci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/middleware/usb_1.0.0/device/usb_device_khci.c b/middleware/usb_1.0.0/device/usb_device_khci.c index 8e01f68..5f263d0 100644 --- a/middleware/usb_1.0.0/device/usb_device_khci.c +++ b/middleware/usb_1.0.0/device/usb_device_khci.c @@ -1199,10 +1199,19 @@ usb_status_t USB_DeviceKhciControl(usb_device_controller_handle khciHandle, usb_ #if defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U) USB_OSA_ENTER_CRITICAL(); khciState->registerBase->CTL |= USB_CTL_RESUME_MASK; - for (uint32_t i = 500U; i > 0U; i--) +#if 1 // This is a hack and is not tuned in any way, but it works - note that we can not use a timer, as interrupts are disabled + for (uint64_t i = MSEC_TO_COUNT(8, SystemCoreClock); i > 0U; i--) + { + // The device must apply the wakeup K condition between 1 to 15 ms - see: http://www.usbmadesimple.co.uk/ums_3.htm and https://www.nxp.com/docs/en/application-note/AN5385.pdf + __ASM("nop"); + } +#else + // I increasing this from 500 to 1000, but it is better to use a timer + for (uint32_t i = 1000U; i > 0U; i--) { __ASM("nop"); } +#endif khciState->registerBase->CTL &= ~USB_CTL_RESUME_MASK; USB_OSA_EXIT_CRITICAL(); error = kStatus_USB_Success;