From 1a274bef20020bbba135a946a2b2bd06556e459d Mon Sep 17 00:00:00 2001 From: Bryan Cain Date: Mon, 6 Jun 2022 19:33:49 -0600 Subject: [PATCH 1/2] sn32: fix USB remote wakeup --- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h index 44a19f2ccf..a977f26057 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h @@ -390,7 +390,9 @@ struct USBDriver { #define usb_lld_wakeup_host(usbp) \ do { \ SN32_USB->SGCTL = (mskBUS_DRVEN|mskBUS_K_STATE); \ - osalThreadSleepMilliseconds(SN32_USB_HOST_WAKEUP_DURATION); \ + uint32_t loops = OSAL_MS2I(SN32_USB_HOST_WAKEUP_DURATION) * \ + (48000000 / CH_CFG_ST_FREQUENCY / 9); \ + for (uint32_t i = 0; i < loops; i++) __NOP(); \ SN32_USB->SGCTL &= ~mskBUS_DRVEN; \ } while (false) From d775328abac8451372f56d8a43e7cb2c2fc91145 Mon Sep 17 00:00:00 2001 From: Bryan Cain Date: Fri, 25 Nov 2022 18:55:11 -0700 Subject: [PATCH 2/2] Use SN32_HCLK instead of hardcoded value Co-authored-by: dexter93 --- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h index a977f26057..8de891831f 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h @@ -391,7 +391,7 @@ struct USBDriver { do { \ SN32_USB->SGCTL = (mskBUS_DRVEN|mskBUS_K_STATE); \ uint32_t loops = OSAL_MS2I(SN32_USB_HOST_WAKEUP_DURATION) * \ - (48000000 / CH_CFG_ST_FREQUENCY / 9); \ + (SN32_HCLK / CH_CFG_ST_FREQUENCY / 9); \ for (uint32_t i = 0; i < loops; i++) __NOP(); \ SN32_USB->SGCTL &= ~mskBUS_DRVEN; \ } while (false)