diff options
| author | Andrew Leech | 2019-06-27 11:00:04 +1000 |
|---|---|---|
| committer | Damien George | 2019-10-08 16:07:32 +1100 |
| commit | 04fe62d06f0e0e56e7dc40bdf9883c7a2f2eac6a (patch) | |
| tree | 386776886b8ade2a4f33323abe07f2386b02dfc8 | |
| parent | fa23033fc4b1b06e92ae5d0f6783257a6774318c (diff) | |
stm32/mboot: Add option to automatically reset when USB is disconnected.
Enable in board config with: #define MBOOT_USB_RESET_ON_DISCONNECT (1)
| -rw-r--r-- | ports/stm32/mboot/main.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index a0f1f1eac..015800ce4 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -1526,6 +1526,9 @@ enter_bootloader: uint32_t ss = systick_ms; int ss2 = -1; #endif + #if MBOOT_USB_RESET_ON_DISCONNECT + bool has_connected = false; + #endif for (;;) { #if USE_USB_POLLING #if MBOOT_USB_AUTODETECT_PORT || MICROPY_HW_USB_MAIN_DEV == USB_PHY_FS_ID @@ -1559,6 +1562,15 @@ enter_bootloader: led_state(LED0, 0); mp_hal_delay_ms(950); #endif + + #if MBOOT_USB_RESET_ON_DISCONNECT + if (pyb_usbdd.hUSBDDevice.dev_state == USBD_STATE_CONFIGURED) { + has_connected = true; + } + if (has_connected && pyb_usbdd.hUSBDDevice.dev_state == USBD_STATE_SUSPENDED) { + do_reset(); + } + #endif } } |
