aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-31 13:34:23 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-03-31 13:37:01 -0400
commitfbbe2cf9d6ced1e1d417464302200414c8ca713a (patch)
treed8d48ef8f6919e28fe4fad9b4eb317b45c6679e1
parent60ff2e9dc1eb2c0133bca8ecd9e200a3502e1f92 (diff)
downloadkutter-fbbe2cf9d6ced1e1d417464302200414c8ca713a.tar.gz
kutter-fbbe2cf9d6ced1e1d417464302200414c8ca713a.tar.xz
kutter-fbbe2cf9d6ced1e1d417464302200414c8ca713a.zip
lpc176x: Explicitly disconnect USB on a bootloader request
It appears some host machines may not recognize that the USB device has disconnected upon start of bootloader mode. Explicitly disable USB and add a 5ms delay to help signal the host of the upcoming change. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/lpc176x/usbserial.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lpc176x/usbserial.c b/src/lpc176x/usbserial.c
index d6db8565..847746d8 100644
--- a/src/lpc176x/usbserial.c
+++ b/src/lpc176x/usbserial.c
@@ -8,6 +8,7 @@
#include "LPC17xx.h" // LPC_SC
#include "autoconf.h" // CONFIG_SMOOTHIEWARE_BOOTLOADER
#include "board/irq.h" // irq_disable
+#include "board/misc.h" // timer_read_time
#include "byteorder.h" // cpu_to_le32
#include "command.h" // output
#include "generic/usb_cdc.h" // usb_notify_ep0
@@ -248,9 +249,14 @@ usb_request_bootloader(void)
{
if (!CONFIG_SMOOTHIEWARE_BOOTLOADER)
return;
+ // Disable USB and pause for 5ms so host recognizes a disconnect
+ irq_disable();
+ sie_cmd_write(SIE_CMD_SET_DEVICE_STATUS, 0);
+ uint32_t end = timer_read_time() + timer_from_us(5000);
+ while (timer_is_before(timer_read_time(), end))
+ ;
// The "LPC17xx-DFU-Bootloader" will enter the bootloader if the
// watchdog timeout flag is set.
- irq_disable();
LPC_WDT->WDMOD = 0x07;
NVIC_SystemReset();
}