diff --git a/lib/serial/GwSerial.h b/lib/serial/GwSerial.h index 75f73a8..83d98a6 100644 --- a/lib/serial/GwSerial.h +++ b/lib/serial/GwSerial.h @@ -4,7 +4,8 @@ #include "GwLog.h" #include "GwBuffer.h" #include "GwChannelInterface.h" -#include "hal/usb_serial_jtag_ll.h" + +#define USBCDC_RESTART_TIME 100 class GwSerialStream; class GwSerial : public GwChannelInterface{ protected: @@ -71,15 +72,24 @@ template } #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 + /** + * issue #81 + * workaround for the HWCDC beeing stuck at some point in time + * with availableForWrite == 0 but the ISR being disabled + * we simply give a small delay of 100ms for availableForWrite being 0 + * and afterwards call isConnected that seems to retrigger the ISR + */ int availableForWrite(HWCDC* c){ int rt=c->availableForWrite(); if (rt > 0) { lastWritable=millis(); return rt; } - if (usb_serial_jtag_ll_txfifo_writable() == 1){ - LOG_INFO("USBserial restart"); - usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + unsigned long now=millis(); + if (now > (lastWritable+USBCDC_RESTART_TIME)){ + lastWritable=now; + LOG_ERROR("***Restart USBCDC***"); + c->isConnected(); //this seems to retrigger the ISR } return rt; }