diff --git a/ports/atmel-samd/usb.c b/ports/atmel-samd/usb.c index 4f7080dc88..e0b9ddc41c 100644 --- a/ports/atmel-samd/usb.c +++ b/ports/atmel-samd/usb.c @@ -175,9 +175,11 @@ static bool write_complete(const uint8_t ep, } volatile bool reset_on_disconnect = false; +volatile bool cdc_connected = false; static bool usb_device_cb_state_c(usb_cdc_control_signal_t state) { + cdc_connected = state.rs232.DTR; if (state.rs232.DTR) { } else if (!state.rs232.DTR && reset_on_disconnect) { reset_to_bootloader(); @@ -282,6 +284,10 @@ void usb_write(const char* buffer, uint32_t len) { if (!cdc_enabled()) { return; } + if (!cdc_connected) { + // TODO(tannewt): Should we write to a file instead? + return; + } uint8_t * output_buffer; uint8_t output_len; while (len > 0) {