Skip to content

Commit 87db022

Browse files
authored
Merge branch 'master' into uart-examples
2 parents 1f70a3f + 6b33cbb commit 87db022

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

cores/esp32/HWCDC.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ static uint8_t rx_data_buf[64];
3232
static intr_handle_t intr_handle = NULL;
3333
static volatile bool initial_empty = false;
3434
static xSemaphoreHandle tx_lock = NULL;
35-
static uint32_t tx_timeout_ms = 200;
35+
36+
// workaround for when USB CDC is not connected
37+
static uint32_t tx_timeout_ms = 0;
38+
static bool tx_timeout_change_request = false;
39+
3640
static esp_event_loop_handle_t arduino_hw_cdc_event_loop_handle = NULL;
3741

3842
static esp_err_t arduino_hw_cdc_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, BaseType_t *task_unblocked){
@@ -72,9 +76,14 @@ static void hw_cdc_isr_handler(void *arg) {
7276
if (usb_serial_jtag_ll_txfifo_writable() == 1) {
7377
// We disable the interrupt here so that the interrupt won't be triggered if there is no data to send.
7478
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
75-
7679
if(!initial_empty){
7780
initial_empty = true;
81+
// First time USB is plugged and the application has not explicitly set TX Timeout, set it to default 100ms.
82+
// Otherwise, USB is still unplugged and the timeout will be kept as Zero in order to avoid any delay in the
83+
// application whenever it uses write() and the TX Queue gets full.
84+
if (!tx_timeout_change_request) {
85+
tx_timeout_ms = 100;
86+
}
7887
//send event?
7988
//ets_printf("CONNECTED\n");
8089
arduino_hw_cdc_event_post(ARDUINO_HW_CDC_EVENTS, ARDUINO_HW_CDC_CONNECTED_EVENT, &event, sizeof(arduino_hw_cdc_event_data_t), &xTaskWoken);
@@ -197,6 +206,9 @@ void HWCDC::end()
197206

198207
void HWCDC::setTxTimeoutMs(uint32_t timeout){
199208
tx_timeout_ms = timeout;
209+
// it registers that the user has explicitly requested to use a value as TX timeout
210+
// used for the workaround with unplugged USB and TX Queue Full that causes a delay on every write()
211+
tx_timeout_change_request = true;
200212
}
201213

202214
/*

docs/source/api/timer.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
##########
1+
#####
22
Timer
3-
##########
3+
#####
44

55
About
66
-----
@@ -19,7 +19,7 @@ ESP32-S3 4
1919
========= ================
2020

2121
Arduino-ESP32 Timer API
22-
----------------------------
22+
-----------------------
2323

2424
timerBegin
2525
**********
@@ -31,11 +31,9 @@ This function is used to configure the timer. After successful setup the timer w
3131
hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp);
3232
3333
* ``num`` select timer number.
34-
* ``divider`` select timer divider.
35-
* ``resolution`` select timer resolution.
34+
* ``divider`` select timer divider. Sets how quickly the timer counter is “ticking”.
35+
* ``countUp`` select timer direction. Sets if the counter should be incrementing or decrementing.
3636

37-
* range is 1-14 bits (1-20 bits for ESP32).
38-
3937
This function will return ``timer`` structure if configuration is successful.
4038
If ``NULL`` is returned, error occurs and the timer was not configured.
4139

0 commit comments

Comments
 (0)