cdc_uart: be more careful about when the thread gets parked or resumed tud_cdc_connected tests dtr, not rts - so we should do the same. Don't unconditionally wake the uart thread when set_line_coding happens - Windows frequently calls this after every linestate change, including device close. Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
diff --git a/src/cdc_uart.c b/src/cdc_uart.c index ba44e4b..53d07cb 100644 --- a/src/cdc_uart.c +++ b/src/cdc_uart.c
@@ -26,7 +26,6 @@ #include <pico/stdlib.h> #include "FreeRTOS.h" #include "task.h" - #include "tusb.h" #include "probe_config.h" @@ -202,7 +201,8 @@ */ uint32_t micros = (1000 * 1000 * 16 * 10) / MAX(line_coding->bit_rate, 1); /* Modifying state, so park the thread before changing it. */ - vTaskSuspend(uart_taskhandle); + if (tud_cdc_connected()) + vTaskSuspend(uart_taskhandle); interval = MAX(1, micros / ((1000 * 1000) / configTICK_RATE_HZ)); debounce_ticks = MAX(1, configTICK_RATE_HZ / (interval * DEBOUNCE_MS)); probe_info("New baud rate %ld micros %ld interval %lu\n", @@ -256,7 +256,10 @@ } uart_set_format(PROBE_UART_INTERFACE, data_bits, stop_bits, parity); - vTaskResume(uart_taskhandle); + /* Windows likes to arbitrarily set/get line coding after dtr/rts changes, so + * don't resume if we shouldn't */ + if(tud_cdc_connected()) + vTaskResume(uart_taskhandle); } void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) @@ -270,7 +273,7 @@ /* CDC drivers use linestate as a bodge to activate/deactivate the interface. * Resume our UART polling on activate, stop on deactivate */ - if (!dtr && !rts) { + if (!dtr) { vTaskSuspend(uart_taskhandle); #ifdef PROBE_UART_RX_LED gpio_put(PROBE_UART_RX_LED, 0);