-
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
Workaround for when USB CDC is unplugged #7583
Conversation
cores/esp32/HWCDC.cpp
Outdated
@@ -32,7 +32,7 @@ static uint8_t rx_data_buf[64]; | |||
static intr_handle_t intr_handle = NULL; | |||
static volatile bool initial_empty = false; | |||
static xSemaphoreHandle tx_lock = NULL; | |||
static uint32_t tx_timeout_ms = 200; | |||
static uint32_t tx_timeout_ms = 0; // workaround for when USB CDC is not connected |
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.
with this being 0, it means that is the ring buffer is full, the code will not give it time to empty some space and will just discard the input. Maybe wait if the is not enough space? Fixing it for when USB is disconnected, but breaking it for when connected is not all that nice :)
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.
Waiting when there is no space (timeout) is exacty the issue... when the board is turned on with the USB unplugged. That is what causes the delay from the point when the RingBuffer gets full and it never is flushed because there is no USB connection.
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.
There is no event that tells the user that USB is or not plugged. Even the ARDUINO_HW_CDC_CONNECTED_EVENT works only the first time, but if we unplug the board, it doesn't tell anything.
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.
@me-no-dev - Added code to test if USB is plugged and the application has never changed Tx Timeout. In that case, it will set Tx Timeout to default 100ms.
Otherwise (USB has never been plugged or the Application has explicitly changed Tx Timeout Value), it will keep it zero or the new value set by the application.
Sets back default TX timeout whenever USB is plugged, otherwise it is kept as zero.
* Workaround for when USB CDC is unplugged * Considers default TX timeout Sets back default TX timeout whenever USB is plugged, otherwise it is kept as zero. * fixed left over code
Description of Change
By default Tx Timeout is 200 and it causes a delay every time that HW USB CDC is written when the USB is unplugged.
Setting it to 0 by default solves this issue and it has no side effect.
As stated in the issue #6983, it affects boards that use Batteries and are not connected to a USB port.
Tests scenarios
This issue affects ESP32-C2 and ESP32-S3 with HW Serial.
Related links
Fix #6983