Skip to content

Commit a734ee9

Browse files
robert-hhdpgeorge
authored andcommitted
shared/tinyusb/mp_usbd_cdc: Skip writing to an uninitialized USB device.
During execution of `boot.py` the USB device is not yet initialized. Any attempt to write to the CDC (eg calling `print()`) would lock up the device. This commit skips writing when the USB device is not initialized. Any output from `boot.py` is lost, but the device does not lock up. Also removed unnecessary declaration of `tusb_init()`. Signed-off-by: robert-hh <[email protected]>
1 parent 847ee20 commit a734ee9

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

shared/tinyusb/mp_usbd.h

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ inline static bool mp_usb_device_builtin_enabled(const mp_obj_usb_device_t *usbd
125125

126126
static inline void mp_usbd_init(void) {
127127
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
128-
extern bool tusb_init(void);
129128
tusb_init();
130129
}
131130

shared/tinyusb/mp_usbd_cdc.c

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void tud_cdc_rx_cb(uint8_t itf) {
9595
}
9696

9797
mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len) {
98+
if (!tusb_inited()) {
99+
return 0;
100+
}
98101
size_t i = 0;
99102
while (i < len) {
100103
uint32_t n = len - i;

0 commit comments

Comments
 (0)