Skip to content

Commit b7dd33b

Browse files
committed
add touch 1200 for dfu-flash
1 parent 3700bc8 commit b7dd33b

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

ports/nrf/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,12 @@ endif
314314
#####################
315315
.phony: dfu-gen dfu-flash dfu-bootloader
316316

317-
ifeq ($(OS),Windows_NT)
318-
NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
317+
NRFUTIL = adafruit-nrfutil
318+
319+
ifeq ($(MCU_SUB_VARIANT),nrf52840)
320+
DFU_TOUCH = --touch 1200
319321
else
320-
NRFUTIL = nrfutil
322+
DFU_TOUCH =
321323
endif
322324

323325
check_defined = \
@@ -332,7 +334,7 @@ dfu-gen: $(BUILD)/$(OUTPUT_FILENAME).hex
332334

333335
dfu-flash: $(BUILD)/dfu-package.zip
334336
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
335-
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank
337+
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank $(DFU_TOUCH)
336338

337339
dfu-bootloader:
338340
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)

ports/nrf/usb/usb.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ void usb_init(void) {
9494
//--------------------------------------------------------------------+
9595
// tinyusb callbacks
9696
//--------------------------------------------------------------------+
97+
98+
// Invoked when device is mounted
9799
void tud_mount_cb(void) {
98100
}
99101

102+
// Invoked when device is unmounted
100103
void tud_umount_cb(void) {
101104
}
102105

@@ -107,6 +110,28 @@ uint32_t tusb_hal_millis(void) {
107110
return (uint32_t) ms;
108111
}
109112

113+
114+
// Invoked when cdc when line state changed e.g connected/disconnected
115+
// Use to reset to DFU when disconnect with 1200 bps
116+
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
117+
(void) itf; // interface ID, not used
118+
119+
// disconnected event
120+
if ( !dtr && !rts )
121+
{
122+
cdc_line_coding_t coding;
123+
tud_cdc_get_line_coding(&coding);
124+
125+
if ( coding.bit_rate == 1200 )
126+
{
127+
enum { DFU_MAGIC_SERIAL = 0x4e };
128+
129+
NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL;
130+
NVIC_SystemReset();
131+
}
132+
}
133+
}
134+
110135
#if MICROPY_KBD_EXCEPTION
111136

112137
/**

0 commit comments

Comments
 (0)