stm32/mboot: Add option to automatically reset when USB is disconnected.

Enable in board config with: #define MBOOT_USB_RESET_ON_DISCONNECT (1)
pull/1/head
Andrew Leech 2019-06-27 11:00:04 +10:00 committed by Damien George
parent fa23033fc4
commit 04fe62d06f
1 changed files with 12 additions and 0 deletions

View File

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