add touch 1200 for dfu-flash

This commit is contained in:
hathach 2018-08-21 15:15:44 +07:00
parent 3700bc83b3
commit b7dd33b76e
3 changed files with 32 additions and 5 deletions

@ -1 +1 @@
Subproject commit 6d96b12e27ae60ca500365ee2137105145ada9dd
Subproject commit 7b35cd0203bc409d7c1aefc075672103cb4a913e

View File

@ -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)

View File

@ -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
/**