Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Serial JTAG Rx FiFo Interrupt Issue #9316

Closed
1 task done
kiran-desilva opened this issue Mar 1, 2024 · 1 comment
Closed
1 task done

USB Serial JTAG Rx FiFo Interrupt Issue #9316

kiran-desilva opened this issue Mar 1, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@kiran-desilva
Copy link

Board

ESP32-S3

Device Description

Any ESP32-S3

Hardware Configuration

Bare

Version

v2.0.6

IDE Name

PlatformIO

Operating System

Any

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

Hey, I think I have found a bug in the HWCDC library when using the USB Serial/Jtag interface. If any bytes are sent over serial before Serial.begin() gets called, the ESP will no longer respond over Serial, although the application will be running fine on the ESP. I believe this occurs due to how interrupts are handled specifically on the USB Serial/ JTAG hardware.

It appears that when data is sent to the ESP, the USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT interrupt flag will not be raised if USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail is set. When HWCDC::begin(...) is called, the interrupts are disabled, all the interrupt bits are cleared and then the three interrupts the isr handler is looking for are re-enabled. This results in USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT being cleared, and never raised again until reset.

The fix I currently have is removing the line where the interrupts are cleared (line 241 HWCDC.cpp on master) and am happy to submit a PR however I wanted to check if you guys see any direct issues with this fix.

I have attached a simple python program to recreate the bug in conjunction with the sketch attached below. The following build flags must also be passed inorder to enable USB Serial/JTAG.
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1

Thanks!

serialbug.txt

Sketch

#include <Arduino.h>
#include <HWCDC.h>
#include <hal/usb_serial_jtag_ll.h>
#include <string>


uint32_t prevTime = 0;


void setup() {
  // delay(2);

  Serial.begin(115200);
  Serial.println("begin");
}

void loop() {

  if (millis() - prevTime > 500)
  {
    prevTime = millis();
    std::string output;
    output += "rxFifo: " + std::to_string(usb_serial_jtag_ll_rxfifo_data_available());
    output += " Serial avaliable: " + std::to_string(Serial.available());
    Serial.println(output.c_str());

  }

  while (Serial.available())
  {
    uint8_t b = Serial.read();
    Serial.print(Serial.available());
    Serial.print(" - ");
    Serial.write(b);
    Serial.println();
  }
  vTaskDelay(1); // watchdog
}

Debug Message

None

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@kiran-desilva kiran-desilva added the Status: Awaiting triage Issue is waiting for triage label Mar 1, 2024
@SuGlider SuGlider self-assigned this Mar 1, 2024
@SuGlider SuGlider added Type: Bug 🐛 All bugs and removed Status: Awaiting triage Issue is waiting for triage labels Mar 1, 2024
@SuGlider SuGlider added this to the 3.0.0-RC1 milestone Mar 1, 2024
@SuGlider
Copy link
Collaborator

SuGlider commented Mar 1, 2024

@kiran-desilva - Thanks for the detailed issue report! Issue confirmed.
It can be also reproduced using the Serial Monitor, by just adding a delay(5000); before Serial.begin(). This gives me time to send data before begin() is executed.

The solution you have proposed is the right one. Please proceed with the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants