diff options
author | Matt Baker <baker.matt.j@gmail.com> | 2019-04-06 15:12:51 -0700 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2019-04-06 20:53:15 -0400 |
commit | e83071c9fef2d1b347fec4aa41650fe0950c60f8 (patch) | |
tree | 1638503857f0ad7b39db9ce35c59e48a1936b567 /src/lpc176x/main.c | |
parent | 04adde9a021d7c25bbf8f3011dc432893c99d4db (diff) | |
download | kutter-e83071c9fef2d1b347fec4aa41650fe0950c60f8.tar.gz kutter-e83071c9fef2d1b347fec4aa41650fe0950c60f8.tar.xz kutter-e83071c9fef2d1b347fec4aa41650fe0950c60f8.zip |
lpc176x: force minimum usb disconnect time
Fixes GitHub Issue #1499. Resolves USB hang by forcing a minimum
USB disconnection time at boot.
Signed-off-by: Matt Baker <baker.matt.j@gmail.com>
Diffstat (limited to 'src/lpc176x/main.c')
-rw-r--r-- | src/lpc176x/main.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lpc176x/main.c b/src/lpc176x/main.c index 1147faec..c417a2c7 100644 --- a/src/lpc176x/main.c +++ b/src/lpc176x/main.c @@ -7,6 +7,7 @@ #include "LPC17xx.h" // NVIC_SystemReset #include "command.h" // DECL_CONSTANT #include "sched.h" // sched_main +#include "board/misc.h" // timer_read_time DECL_CONSTANT_STR("MCU", "lpc176x"); @@ -66,6 +67,20 @@ command_reset(uint32_t *args) } DECL_COMMAND_FLAGS(command_reset, HF_IN_SHUTDOWN, "reset"); +// Implement simple early-boot delay mechanism +void +udelay(uint32_t usecs) +{ + if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + } + + uint32_t end = timer_read_time() + timer_from_us(usecs); + while (timer_is_before(timer_read_time(), end)) + ; +} + // Main entry point int main(void) |