-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Native USB CDC hangs up on ESP32-S2 after about 320 characters #6221
Comments
@technoblogy Could you test it with the complete latest Arduino Core Version? Please let me know. Results with ESP-ROM version information - using 115200 baud for reading the boot messages
|
@SuGlider I'm not quite sure how to do this. If I download arduino-esp32-master it's not in a form that I can put in |
@technoblogy This is how it will look like: You shall see |
I installed from the development link:
Is that correct? It still seems to be version 2.0.2. |
@technoblogy These are the commands for Linux:
After cloning the master branch into To update the GitHub in you computer, just go to the |
Thanks - I'll try it. |
@SuGlider I followed your instructions which worked without error, but when I try to compile I get: fork/exec /Users/david/Documents/Arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++: no such file or directory I can see that file, but it's in the path: /Users/david/Documents/Arduino/hardware/espressif/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++ |
Did you also run |
Yes, and it ran without errors. |
ha! could you post a log from get.py? |
Log from get.py:
|
Ok. It seems fine. |
Complete log:
|
Try reinstall Arduino Core 2.0.2. I hope it may make it work. |
I haven't got Arduino Core 2.0.2, I'm on 1.8.13. |
I think that 1.8.13 is the version of the Arduino IDE. ESP Arduino Core 2.0.2 is the version of the Espressif Arduino Framework. You will see it when installing ESP board in the IDE. |
OK, I had deleted my ESP32 2.0.2 installation. I've reinstalled it and then got an error about esptool. I added an esptool folder containing esptool and it now compiles from ESP32 Arduino (in sketchbook). However I still get the same behaviour with the UM featherS2 board. In other words the Serial Monitor prints: 64 ie it hangs up after 320 characters and doesn't reach 512. Sorry :( |
Did you select the ESO board from |
No, I selected UM FeatherS2. I don't have an entry for ESO. What's ESO? |
Sorry, I meant ESP. You must select your board or at least the |
I'm sorry I don't yet have an ESP32-S2 Devkit board (I've got one on order). I tried with an UM Feather S2 board: I tried with an Adafruit QT Py ESP32-S2 board: I tried with an Adafruit ESP32 Feather board: So the complete latest Arduino Core Version behaves just like the 2.0.2 release version: it works on ESP32 but has Serial problems for me on ESP32-S2. |
Ok. My suggestion is to hold up to we launch Arduino 2.0.3 which will include all those fixes. Then you can try the example again and test it. In case the issue still occurs, please reopen this issue and mention my login, so I can look at it. I'll close it in this meantime. |
@SuGlider - I was going to suggest the same. Thanks - I'll report back! |
I see that I've already tested with 2.0.12; see: and with 3.0.0-alpha2; see: and I also reported a workaround that made the problem go away, which may help tracking down the issue: Is anything likely to have changed in 3.0.0-alpha3, so should I test that too? |
I'll investigate it again... I'll get back with some answer in a couple days. |
That would be great. Let me know if I can help. |
Issue is (re)confirmed for the USB OTG using ESP32-S2 and ESP32-S3. |
@technoblogy - I've found the root cause of this issue: as soon as the RX Buffer is full, with 256 bytes, the remaining bytes from the 512 are discarted by Buffer Overflow. This happens because the USB HOST (the PC) sends all the 512 bytes at once and the ESP32 executes the TinyUSB CDC ISR continuosly not giving FreeRTOS Scheduler time to execute the Arduino Task for the When all the 512 bytes are finally sent by the HOST, the A sollution, that depends on how the CDC data exchange is done, would be to increase the RX Buffer size with the maximum space that the USB HOST would send at once. In this case, the RX Buffer can be set to 1024 and this would solve this specific issue with the LISP code uploading sletch. A broader solution that doesn't depend on the size of the RX Buffer is to change the This broader solution is under investigation for implementation. |
@SuGlider that's great news! Unfortunately there's no size of RX Buffer that would be sufficient for every Lisp upload, so I remain hopeful that you succeed in finding the broader solution. |
@SuGlider you wrote:
I was wondering when you would expect to be able to fix this? I've just tested this using ESP32 Arduino Core 3.0.3, and the problem still seems to be there on the ESP32-S3 and ESP32-C3. Details: ESP32 Core 3.0.3, Arduino IDE 2.3.2, MacBook Pro with macOS Catalina 10.15.7. |
I ran the test program on a Linux PC and I can confirm that the issue still happens there too. I use a x86_64 PC with Linux Mint 22 Cinnamon and a Cardputer uLisp Machine, i.e. an ESP32-S3 based M5Stack Cardputer running uLisp. |
I was also going to use the S2 as my primary MCU, but USB screwed me over. I wrote a simple ESP test code: #include <Arduino.h>
static bool connected = false;
static bool light = false;
void setup() {
Serial.begin();
Serial.enableReboot(true);
delay(3000);
Serial.setDebugOutput(true);
Serial.println("Start");
// Serial.setRxBufferSize(2048);
pinMode(15, OUTPUT);
}
void loop() {
static unsigned long lastMillis = 0;
bool is_connect = static_cast<bool>(Serial);
/** add this will not recurrence. */
// Serial.readString();
if (is_connect != connected) {
connected = is_connect;
if (connected) {
delay(1000);
Serial.println("Connected");
Serial.printf("BaudRate: %u\n", Serial.baudRate());
}
}
if (millis() - lastMillis > 1000) {
lastMillis = millis();
Serial.println(random(-2, 2));
digitalWrite(15, light);
light = !light;
}
} Then under Linux, use and then, I wrote an C code to read data: // C library headers
#include <stdio.h>
#include <string.h>
// Linux headers
#include <errno.h> // Error integer and strerror() function
#include <fcntl.h> // Contains file controls like O_RDWR
#include <termios.h> // Contains POSIX terminal control definitions
#include <unistd.h> // write(), read(), close()
int main(const int argc, const char *argv[])
{
if(argc != 2) {
printf("Usage: %s <device>\n", argv[0]);
return 1;
}
// Open the serial port. Change device path as needed (currently set to an standard FTDI USB-UART cable type device)
int serial_port = open(argv[1], O_RDWR);
// Create new termios struct, we call it 'tty' for convention
struct termios tty;
// Read in existing settings, and handle any error
if(tcgetattr(serial_port, &tty) != 0) {
printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
return 1;
}
tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity (most common)
tty.c_cflag &=
~CSTOPB; // Clear stop field, only one stop bit used in communication (most common)
tty.c_cflag &= ~CSIZE; // Clear all bits that set the data size
tty.c_cflag |= CS8; // 8 bits per byte (most common)
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control (most common)
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
tty.c_lflag &= ~ICANON;
tty.c_lflag &= ~ECHO; // Disable echo
tty.c_lflag &= ~ECHOE; // Disable erasure
tty.c_lflag &= ~ECHONL; // Disable new-line echo
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR |
ICRNL); // Disable any special handling of received bytes
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
// tty.c_oflag &= ~OXTABS; // Prevent conversion of tabs to spaces (NOT PRESENT ON LINUX)
// tty.c_oflag &= ~ONOEOT; // Prevent removal of C-d chars (0x004) in output (NOT PRESENT ON LINUX)
tty.c_cc[VTIME] = 10; // Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
tty.c_cc[VMIN] = 0;
// Set in/out baud rate to be 9600
cfsetispeed(&tty, B115200);
cfsetospeed(&tty, B115200);
// Save tty settings, also checking for error
if(tcsetattr(serial_port, TCSANOW, &tty) != 0) {
printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
return 1;
}
// Write to serial port
unsigned char msg[] = {'H', 'e', 'l', 'l', 'o', '\r'};
write(serial_port, msg, sizeof(msg));
while(true) {
// Allocate memory for read buffer, set size according to your needs
char read_buf[256];
// Normally you wouldn't do this memset() call, but since we will just receive
// ASCII data for this example, we'll set everything to 0 so we can
// call printf() easily.
memset(&read_buf, '\0', sizeof(read_buf));
// Read bytes. The behaviour of read() (e.g. does it block?,
// how long does it block for?) depends on the configuration
// settings above, specifically VMIN and VTIME
int num_bytes = read(serial_port, &read_buf, sizeof(read_buf));
// n is the number of bytes read. n may be 0 if no bytes were received, and can also be -1 to signal an error.
if(num_bytes < 0) {
printf("Error reading: %s", strerror(errno));
return 1;
}
// Here we assume we received ASCII data, but you might be sending raw bytes (in that case, don't try and
// print it to the screen like this!)
printf("Read %i bytes. Received message: %s\n", num_bytes, read_buf);
}
close(serial_port);
return 0; // success
}; this will be ok. and the key setting code is I don't know if my questions are the same or if it helps |
@Changes729 Thanks, this is interesting. However, I'm not sure whether your code fixes the issue as I'm not fluent in C. |
esp32-s2 and s3 USB implementation is broken, it hangs when used intesively. |
Board
Adafruit QT-Py ESP32-S2
Device Description
Plain board.
Hardware Configuration
No.
Version
v2.0.2
IDE Name
Arduino IDE
Operating System
macOS 10.13.6
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
921600
Description
Entering text into the Serial Monitor causes the Serial to hang up after about 320 characters. Run the following sketch, then cut and paste all the following text (total 512 characters) into the Serial Monitor input field, and press Return:
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
The Serial Monitor prints:
64
128
192
256
320
ie it hangs up after 320 characters and doesn't reach 512.
NB I've implemented the patch suggested by @SuGlider from PR #6133 in Issue #6205.
Sketch
Debug Message
Other Steps to Reproduce
Also tested on UM FeatherS2 - hangs up in the same way.
Works fine on ESP32-C3 DevKit and Adafruit ESP32 Feather.
I've tried adding
Serial.setRxBufferSize(1024)
but has no effect.I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: