diff options
-rw-r--r-- | stmhal/modpyb.c | 1 | ||||
-rw-r--r-- | stmhal/usb.c | 7 | ||||
-rw-r--r-- | stmhal/usb.h | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index 43a017751d..7ec25038bf 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -65,6 +65,7 @@ /// \function bootloader() /// Activate the bootloader without BOOT* pins. STATIC NORETURN mp_obj_t pyb_bootloader(void) { + pyb_usb_dev_stop(); storage_flush(); HAL_RCC_DeInit(); diff --git a/stmhal/usb.c b/stmhal/usb.c index fd8cbb95a1..ef7e8a62eb 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -75,6 +75,13 @@ void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium) { #endif } +void pyb_usb_dev_stop(void) { + if (dev_is_enabled) { + USBD_Stop(&hUSBDDevice); + dev_is_enabled = 0; + } +} + bool usb_vcp_is_enabled(void) { return dev_is_enabled; } diff --git a/stmhal/usb.h b/stmhal/usb.h index 8b8562ce6d..3bd30ba92c 100644 --- a/stmhal/usb.h +++ b/stmhal/usb.h @@ -42,6 +42,7 @@ typedef enum { } usb_storage_medium_t; void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium); +void pyb_usb_dev_stop(void); bool usb_vcp_is_enabled(void); bool usb_vcp_is_connected(void); void usb_vcp_set_interrupt_char(int c); |