-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix stall on usb write: try to write only if usb is actually connected #7721
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
Conversation
Luca seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if the PR is necessary. Plese check my comments below.
Thanks @imwhocodes for the PR. I used this Testing Sketch:I have an ESP32-S3 with 2 USB ports here. One for UART and another for USB CDC.
The idea of this testing sketch is to write a message in UART and USB CDC every 1 second. I used PuTTY as terminal to connect to the Win11 COM port from the S3 UART and used Arduino Serial Monitor to connect to the USB CDC Win11 COM port. In this way, Putty will display the loop UART messages while I can experiment with the USB CDC port, plugging, unplugging, closing the Serial Terminal etc. void setup() {
Serial.begin(115200);
Serial0.begin(115200);
while(!Serial0) delay(1);
Serial0.print("\n=================\nPrinting on UART\n=================\n");
}
void loop() {
static uint32_t now = millis();
if (millis() > now + 1000) {
Serial0.printf("[%d] Loop running...\n", millis());
Serial.printf("[%d] Loop running USB CDC...\n", millis());
now += 1000;
}
} Conclusion of the experiment:1- If I start the S3 only with the Serial Port plugged, I get the loop working fine, every 1 second, even when it is trying to write to the CDC port as well. Therefore, it never stalls. 2- If I start the S3 with both ports plugged and then open the Arduino Serial Monitor (which will only work when Windows enumerates the USB CDC), I see both ports with messages. Because the messages are buffered into the Ring Buffer, I can see all of them from the beginning. Now, if I unplug the USB from the S3, the serial monitor stops displaying new messages, which is OK. Now close the Serial Monitor Window. Plug the USB back again. |
Ok I did some testing and found the problem: #include <Arduino.h>
void setup() {
Serial.begin(115200);
Serial0.begin(115200);
while(!Serial0) delay(1);
Serial0.print("\n=================\nPrinting on UART\n=================\n");
Serial0.flush();
Serial.print("\n=================\nPrinting on USB CDC\n=================\n");
Serial.flush(); // <-- HERE PROGRAM STALL
}
void loop() {
static uint32_t now = millis();
if (millis() > now + 1000) {
Serial0.printf("[%d] Loop running UART...\n", millis());
Serial0.flush();
Serial.printf("[%d] Loop running USB CDC...\n", millis());
Serial.flush();
now += 1000;
}
} I'm working on platformio, here you have the complete test project Honestly I still think that the timeout is a stop-gap measure, proper way should be to check if usb is connected (indicated by the value of Thanks, |
Maybe related to #7554 |
@imwhocodes - What is the OS of the computer used for the |
MacOS and Ubuntu |
@imwhocodes - please review and sign the CLA in order to continue with the process. Thanks! |
I'm sorry, but it seems that CI won't let it pass because of commit e392b55 Please close this PR and open a new one with a single commit from your valid GH user ID. |
This PR needs more investigation and testing, milestone changed to 3.0.0. |
@SuGlider PTAL. Maybe good to mix in with the SOA monitor code I gave you a while back. |
Hello @imwhocodes, can you please sign CLA? |
Commit is signed with "Luca" but my user-name is "imwhocodes" so it refuse my signing |
Please recommit with the proper author configuration. |
👋 Hello imwhocodes, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
We (Tasmota) use this to detect if JTAG USB is connected:
|
This PR will be reviewed and maybe it will use a different approcha based on USB SOF event. |
This PR will be closed in favor of #9275 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR demonstrates an issue, but the solution was changed to use USB SOF signal from IDF 5.1 implementation. It will be solved within Arduino Core 3.0.0.
Thanks @imwhocodes !!
Description of Change
While developing on local esp32-s3 the program stalled if no pc was connected to the USB
USB was written by both normal
Stream::write
and the native log infrastructureThis fix the issue by checking if USB is enabled before trying to actually write
Related links
I'm aware of 1d595fd by @SuGlider but it is not clear to me as this could completely address the 'unconnected USB problem': changing
tx_timeout_ms
impact only if there are 2 threads writing to the USB and one of them is already stuck trying to writeMaybe I'm missing something,
Luca