From 4b5d5310d192ce0dfdeb5fe0fa5be074770c7687 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 11 Mar 2018 18:38:30 +0100 Subject: [PATCH 1/2] 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; From 08604d409ca0f1fca84555cbe71d59e3f1ff482c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 8 Apr 2018 19:17:56 +0200 Subject: [PATCH 2/2] Fixed compiler warning, as BIG_ENDIAN and LITTLE_ENDIAN are already defined on newer compilers See: https://sourceforge.net/p/predef/wiki/Endianness/ --- middleware/usb_1.0.0/osa/usb_osa.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/middleware/usb_1.0.0/osa/usb_osa.h b/middleware/usb_1.0.0/osa/usb_osa.h index c1f9eaf..e961e80 100644 --- a/middleware/usb_1.0.0/osa/usb_osa.h +++ b/middleware/usb_1.0.0/osa/usb_osa.h @@ -41,12 +41,24 @@ ******************************************************************************/ /*! @brief Define big endian */ +#ifndef BIG_ENDIAN #define BIG_ENDIAN (0U) +#endif /*! @brief Define little endian */ +#ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN (1U) +#endif /*! @brief Define current endian */ +#ifndef _BYTE_ORDER #define ENDIANNESS LITTLE_ENDIAN +#else +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define ENDIANNESS LITTLE_ENDIAN +#else +#define ENDIANNESS BIG_ENDIAN +#endif +#endif /*! @brief Define USB OSA event handle */ typedef void *usb_osa_event_handle;