summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <thach@tinyusb.org>2018-08-21 15:15:44 +0700
committerhathach <thach@tinyusb.org>2018-08-21 15:15:44 +0700
commitb7dd33b76edee78e5da8ea856f4fcac3d44e254a (patch)
tree89199caa75c7adfc72a026dcb67b29663cdac651
parent3700bc83b39ebbf54259d0daebbadd422452fd6b (diff)
add touch 1200 for dfu-flash
m---------lib/tinyusb0
-rwxr-xr-xports/nrf/Makefile10
-rw-r--r--ports/nrf/usb/usb.c25
3 files changed, 31 insertions, 4 deletions
diff --git a/lib/tinyusb b/lib/tinyusb
-Subproject 6d96b12e27ae60ca500365ee2137105145ada9d
+Subproject 7b35cd0203bc409d7c1aefc075672103cb4a913
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index b62eff3da..2ab44dbd0 100755
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -314,10 +314,12 @@ endif
#####################
.phony: dfu-gen dfu-flash dfu-bootloader
-ifeq ($(OS),Windows_NT)
- NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
+NRFUTIL = adafruit-nrfutil
+
+ifeq ($(MCU_SUB_VARIANT),nrf52840)
+ DFU_TOUCH = --touch 1200
else
- NRFUTIL = nrfutil
+ DFU_TOUCH =
endif
check_defined = \
@@ -332,7 +334,7 @@ dfu-gen: $(BUILD)/$(OUTPUT_FILENAME).hex
dfu-flash: $(BUILD)/dfu-package.zip
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
- $(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank
+ $(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank $(DFU_TOUCH)
dfu-bootloader:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
diff --git a/ports/nrf/usb/usb.c b/ports/nrf/usb/usb.c
index 953b61e39..7168cf53d 100644
--- a/ports/nrf/usb/usb.c
+++ b/ports/nrf/usb/usb.c
@@ -94,9 +94,12 @@ void usb_init(void) {
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
+
+// Invoked when device is mounted
void tud_mount_cb(void) {
}
+// Invoked when device is unmounted
void tud_umount_cb(void) {
}
@@ -107,6 +110,28 @@ uint32_t tusb_hal_millis(void) {
return (uint32_t) ms;
}
+
+// Invoked when cdc when line state changed e.g connected/disconnected
+// Use to reset to DFU when disconnect with 1200 bps
+void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
+ (void) itf; // interface ID, not used
+
+ // disconnected event
+ if ( !dtr && !rts )
+ {
+ cdc_line_coding_t coding;
+ tud_cdc_get_line_coding(&coding);
+
+ if ( coding.bit_rate == 1200 )
+ {
+ enum { DFU_MAGIC_SERIAL = 0x4e };
+
+ NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL;
+ NVIC_SystemReset();
+ }
+ }
+}
+
#if MICROPY_KBD_EXCEPTION
/**