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 <robert@hammelrath.com>
This commit is contained in:
robert-hh
2024-07-17 20:43:51 +02:00
committed by Damien George
parent 847ee20d9b
commit a734ee9057
2 changed files with 3 additions and 1 deletions

View File

@@ -125,7 +125,6 @@ inline static bool mp_usb_device_builtin_enabled(const mp_obj_usb_device_t *usbd
static inline void mp_usbd_init(void) { static inline void mp_usbd_init(void) {
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init() // Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
extern bool tusb_init(void);
tusb_init(); tusb_init();
} }

View File

@@ -95,6 +95,9 @@ void tud_cdc_rx_cb(uint8_t itf) {
} }
mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len) { mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len) {
if (!tusb_inited()) {
return 0;
}
size_t i = 0; size_t i = 0;
while (i < len) { while (i < len) {
uint32_t n = len - i; uint32_t n = len - i;