Skip to content

ESP32-S3, can't send and receive message from Serial at the same time. #10323

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

Open
1 task done
raybantracing opened this issue Sep 10, 2024 · 10 comments
Open
1 task done
Assignees
Labels
Area: Peripherals API Relates to peripheral's APIs. Status: Awaiting Response awaiting a response from the author

Comments

@raybantracing
Copy link

Board

Lolin ESP32-S3 and TinyS3

Device Description

Hardware Configuration

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Win11 and Ubuntu 24

Flash frequency

240

PSRAM enabled

no

Upload speed

115200

Description

USB hangs when receiving and sending messages over Serial.
This happens on "virtual USB" devices but not on UART devices that uses hw chips like CH340 and similar.

The problem occurs randomly and may happen after 5 minutes or after 2 hours.

Sketch

#include <Arduino.h> //this needs to be first, or it all crashes and burns...

void setup() {
  Serial.setTimeout(10);
  Serial.setRxBufferSize(2000);
  Serial.begin(115200);
  Serial.setDebugOutput(true);
}

unsigned long prevMill = 0;
const long everyMillis = 1000;

void loop() {
  byte pre[2000];
  Serial.readBytes((byte *) pre, 2000);

  while(Serial.available() > 0) {
    char t = Serial.read();
  }
  unsigned long currentMillisA = millis();
  if (currentMillisA - prevMill >= everyMillis) {
    prevMill = currentMillisA;
    Serial.print("framerate:");
    Serial.println(currentMillisA);
  }
}

Python:

import serial
import time

arduino = serial.Serial(port='COM10', baudrate=115200, timeout=10)

def send_message():
    while True:        
        arduino.write(b'this is a long string this is a long string this is a long string this is a long string this is a long string this is a long string') 
        response = arduino.readline().decode('utf-8').strip() 
        if response:
            print(f"Received: {response}")
        time.sleep(0.010) 

if __name__ == "__main__":
    send_message()



### Debug Message

```plain
-

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.
@raybantracing raybantracing added the Status: Awaiting triage Issue is waiting for triage label Sep 10, 2024
@SuGlider SuGlider self-assigned this Sep 10, 2024
@SuGlider
Copy link
Collaborator

Correct. This issues is known from #6221
Fixing it will take some time... We will have to change tinyUSB source code used by Arduino.

@SuGlider
Copy link
Collaborator

@raybantracing - Could you please test it using Arduino 3.0.0-RC1 version? This uses the last stable TinyUSB version that I have found.

@raybantracing
Copy link
Author

@SuGlider I have tested it with Arduino 3.0.0-RC1 and same problem.

suppose that I reduce the chunk size sent by the PC to 64 bytes,
I expect that this will significantly slow down the communication, but will this workaround the problem?

@raybantracing
Copy link
Author

raybantracing commented Sep 11, 2024

I answer it my self, I modified my PC code to be able to send chunk up to 64 bytes and no it does not workaround the problem.
ESP USB stack continue to crash, if the chunk is bigger, it crashes faster but current USB implementation is very very weak.

@SuGlider
Copy link
Collaborator

Just to confirm:
The issue is related to USB-OTG (TinyUSB) using CDC or to Hardware CDC and JTAG?
What is the USB mode used when the application is built?

@raybantracing
Copy link
Author

@SuGlider issue happen on both modes,
I tried both TinyUSB and Hardware CDC and JTAG mode and same issue.

@SuGlider
Copy link
Collaborator

Thank you for the confirmation.

@raybantracing
Copy link
Author

@SuGlider
ESP32 family USB stack (the one that doesn't uses UART chips) became pretty unusable in this state, I think that this is a major issue for lot's of applications.

I know that this fix will require time but is there someone working on it? :)

@Jason2866 Jason2866 added Area: Peripherals API Relates to peripheral's APIs. and removed Status: Awaiting triage Issue is waiting for triage labels Mar 13, 2025
@Jason2866
Copy link
Collaborator

@raybantracing is the issue still there with actual Arduino core 3.1.3 and with 3.2.0-rc2?

@Jason2866 Jason2866 added the Status: Awaiting Response awaiting a response from the author label Mar 13, 2025
@SuGlider
Copy link
Collaborator

I guess that it is still there...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Status: Awaiting Response awaiting a response from the author
Projects
None yet
Development

No branches or pull requests

3 participants