Skip to content

Commit 6b17247

Browse files
authored
feat(jtag/hwcdc): uses SOF detection from IDF
Restores back IDF 5.1 SOF detection method in order to fix the HW CDC uploading process. Enabling SOF mask in the ISR routine causes a problem with esptool uploading when using CDC/JTAG port.
1 parent dea5be6 commit 6b17247

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

cores/esp32/HWCDC.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ static intr_handle_t intr_handle = NULL;
3939
static SemaphoreHandle_t tx_lock = NULL;
4040
static volatile bool connected = false;
4141

42-
static volatile unsigned long lastSOF_ms;
43-
static volatile uint8_t SOF_TIMEOUT;
42+
// SOF in ISR causes problems for uploading firmware
43+
//static volatile unsigned long lastSOF_ms;
44+
//static volatile uint8_t SOF_TIMEOUT;
4445

4546
// timeout has no effect when USB CDC is unplugged
4647
static uint32_t tx_timeout_ms = 100;
@@ -147,7 +148,8 @@ static void hw_cdc_isr_handler(void *arg) {
147148

148149
inline bool HWCDC::isPlugged(void) {
149150
// SOF ISR is causing esptool to be unable to upload firmware to the board
150-
return true;//(lastSOF_ms + SOF_TIMEOUT) >= millis();
151+
// Timer test for SOF seems to work when uploading firmware
152+
return usb_serial_jtag_is_connected();//(lastSOF_ms + SOF_TIMEOUT) >= millis();
151153
}
152154

153155
bool HWCDC::isCDC_Connected() {
@@ -157,11 +159,13 @@ bool HWCDC::isCDC_Connected() {
157159
if (!isPlugged()) {
158160
connected = false;
159161
running = false;
160-
SOF_TIMEOUT = 5; // SOF timeout when unplugged
162+
// SOF in ISR causes problems for uploading firmware
163+
//SOF_TIMEOUT = 5; // SOF timeout when unplugged
161164
return false;
162-
} else {
163-
SOF_TIMEOUT = 50; // SOF timeout when plugged
164-
}
165+
}
166+
//else {
167+
// SOF_TIMEOUT = 50; // SOF timeout when plugged
168+
//}
165169

166170
if (connected) {
167171
running = false;
@@ -249,8 +253,9 @@ static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
249253
HWCDC::HWCDC() {
250254
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit);
251255
perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit);
252-
lastSOF_ms = 0;
253-
SOF_TIMEOUT = 5;
256+
// SOF in ISR causes problems for uploading firmware
257+
// lastSOF_ms = 0;
258+
// SOF_TIMEOUT = 5;
254259
}
255260

256261
HWCDC::~HWCDC() {

0 commit comments

Comments
 (0)