Skip to content

Commit 6d19774

Browse files
committed
stmhal: Stop USB before entering DFU by software.
1 parent 008343f commit 6d19774

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

stmhal/modpyb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
/// \function bootloader()
6666
/// Activate the bootloader without BOOT* pins.
6767
STATIC NORETURN mp_obj_t pyb_bootloader(void) {
68+
pyb_usb_dev_stop();
6869
storage_flush();
6970

7071
HAL_RCC_DeInit();

stmhal/usb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium) {
7575
#endif
7676
}
7777

78+
void pyb_usb_dev_stop(void) {
79+
if (dev_is_enabled) {
80+
USBD_Stop(&hUSBDDevice);
81+
dev_is_enabled = 0;
82+
}
83+
}
84+
7885
bool usb_vcp_is_enabled(void) {
7986
return dev_is_enabled;
8087
}

stmhal/usb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef enum {
4242
} usb_storage_medium_t;
4343

4444
void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium);
45+
void pyb_usb_dev_stop(void);
4546
bool usb_vcp_is_enabled(void);
4647
bool usb_vcp_is_connected(void);
4748
void usb_vcp_set_interrupt_char(int c);

0 commit comments

Comments
 (0)