-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
USBCDC::flush is blocking #7554
Comments
@tablatronix TinyUSB requires ESP32-S3 can only use one or the other. Not both at the same time. |
Ok so I posted the wrong method, I will take a look at |
I am working around this now by checking I tried to use void HWCDC::flush(void)
{
if(tx_ring_buf == NULL || tx_lock == NULL || !initial_empty){
return;
}
if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
return;
} |
There also is something wrong with HWCDC ISRs and wifi.. To get wifi working with HWCDC, I have to And there is some delay proportional to the size of the buffer, so something is waiting until it's full ? |
yup same issue, fixed the same way , well kludged. But yeah if we can make HWCDC not get stuck blocking/waiting when no client is present or when no async event will ever be reached. I see that write - |
I have tested it and I can't reproduce the issue. When you run the ESP32S3, the USB cable is unplugged? |
Usb is plugged but no serial connected. Could this be an osx issue with dtr? Behavior differs with and without a serial terminal on the socket |
I have Win11 here. I don't know if this is an osx issue only. But, yes, when a Serial Terminal is initiated, there is a signal to USBCDC that tells to Arduino that the connection has been started. https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/USBCDC.cpp#L238-L240 The sketch can test if it has been connected already by using if(Serial) {
log_i("USB Serial Terminal has started and connected to CDC.");
} else {
log_i("USB Serial Terminal in not connected to CDC.");
} Given that |
Hi @tablatronix I'm having the same problem and I proposed a PR #7721 If you can (super easy with PlatformIO) you can test using this branch: https://github.com/imwhocodes/arduino-esp32/tree/usb-unconnected-stall-fix
Yes this is True but in the UART case there is no concept of "connection", I would argue that if no usb is connected all write should be NO-OP and not even try to actually write on the medium |
@imwhocodes Thank you , YES exactly |
OK, this is an important change. In the current implementation if USB isn't connected, the sent data is buffered into a Ringbuffer. Anyway, this Ringbuffer may go full before USB is connected to the Host. By other hand, based on the PR, the bytes sent before the user opens the connection or after the connection is closed are lost - just like it would be with a UART. |
Adding to this disussion, it seems that there is another user requesting that while CDC isn't connected, it shouldn't buffer any sent data. |
Just ran into this problem porting code to a XIAO S3 board which has only a single S3-native USB port. Therefore a simple API that detects the presence of a USB CDC connection is needed. Let the developer test if there is a connection and decided what to do. Either wait for one to appear, or ignore it and carry on. Please. |
is there a workaround to make it work currently? |
I have workarounded the problem like this
it's not the same but it works for me. |
@sblantipodi If you are using Platformio you can add this:
To your |
Thanks @imwhocodes I'll give it a try. ... do you see some issues in using the workaround I described above instead of using Serial.flush() ? |
This is still an issue, testing on S3 ESP-IDF version: 4.4.5.230614 |
I'll test it with the latest Arduino Core. |
Looks like Im seeing this bug in Arduino v2.0.11 based on ESP-IDF v4.4.5 on my esp32-c3 AirM2M_CORE_ESP32C3. |
Can this issue also be related to the fact that an ESP32-C3-MINI CDC resets the board when you try to access the serial via Windows OS? |
@evansgl no this is not an RTS issue, afaik |
I ran into this issue with a Seeed Xiao ESP32S3 when using platformio with both frameworks: My quick and dirty workaround was to connect a separate USB serial adapter to UART1 which was configured against GPIO43 and GPIO44 via menuconfig. PLATFORM: Espressif 32 (6.5.0) |
@tablatronix @imwhocodes @Xylopyrographer @sblantipodi @beachmiles @evansgl @ck2510 It also won't work properly when the sketch waits for the CDC to be connected using a Serial Monitor, using a code like These and some other issue were fixed by the PR #9275 It has been fixed for arduino core 3.0.0-RC1 and it is available in the master branch. Check the PR examples. |
3.0 changes are backpatched to 2.x. I have solved with setTxTimeout(0) and remove flush() commands. |
As I'm fairly new to platformio, may I ask what to do, to include the backpatched changes? Cannot use >core 3.0 unfortunately. Thank you and best regards |
v2.x contains bugfixes than implemented in 3.x, so you need to upgrade to latest v2 only. |
Thank you. Could you please quickly check if I'm doing that right in my platformio.ini file? It's a project where USB HID joystick and serial output are provided by the ESP32 S3. Without serial monitor opened, the joystick output is reliable. When the serial monitor is opened, joystick and serial output block after some time. Thank you and best regards. Edit: |
I use the default ExpressIF
|
Thank you. I'd say something changed till yesterday.
The serial output doesn't seem to stall. The USB HID output does though . BR |
Board
ESP32 S3
Device Description
S3 mini devkit
Hardware Configuration
Nothing special S3 mini
Version
v2.0.5
IDE Name
pio
Operating System
osx:latest
Flash frequency
40
PSRAM enabled
no
Upload speed
921600
Description
USBCDC flush() will block until you connect to it and it can flush.. seems odd,
!tud_cdc_n_connected
is reporting wrong?Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: