Skip to content

Commit

Permalink
#81: restart HWCDC interrupt after 100ms
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Nov 4, 2024
1 parent e3bab58 commit 041b550
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/serial/GwSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -71,15 +72,24 @@ template<typename T>
}

#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;
}
Expand Down

0 comments on commit 041b550

Please sign in to comment.