From 1f5675d1784677505eab03ea34ad7bd73c077d19 Mon Sep 17 00:00:00 2001 From: Hardy Griech Date: Sun, 23 Apr 2023 18:46:33 +0200 Subject: [PATCH] Removed glitches on probe startup. With the previous version cdc_uart characters from target where sent back to target. Don't know if that had something to do with cdc flush/clear, but now this effect is gone. Price is that the CDC threads are polling for connection (which is not bad anyway). Note: propability is just reduced. I think this has something to do with tinyusb --- CMakeLists.txt | 5 +++-- Makefile | 4 ++-- include/tusb_config.h | 2 +- src/cdc_debug.c | 19 ++++++++----------- src/cdc_uart.c | 23 ++++++++--------------- 5 files changed, 22 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 964663641..b6e6ddbc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,8 +194,9 @@ target_link_libraries(${PROJECT} PRIVATE if(PICO_BOARD STREQUAL "pico_w") target_link_libraries(${PROJECT} PRIVATE - pico_cyw43_arch_lwip_sys_freertos - pico_lwip_iperf + #pico_cyw43_arch_lwip_sys_freertos + #pico_lwip_iperf + pico_cyw43_arch_none ) endif() diff --git a/Makefile b/Makefile index 75f546af4..9989955e2 100755 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # VERSION_MAJOR := 1 -VERSION_MINOR := 12 +VERSION_MINOR := 13 BUILD_DIR := build PROJECT := picoprobe @@ -20,7 +20,7 @@ CMAKE_FLAGS += -DCMAKE_EXPORT_COMPILE_COMMANDS=True ifeq ($(PICO_BOARD),) # pico|pico_w|pico_debug_probe - PICO_BOARD := pico_w + PICO_BOARD := pico_debug_probe endif diff --git a/include/tusb_config.h b/include/tusb_config.h index 35c8e7aa2..2006e51aa 100644 --- a/include/tusb_config.h +++ b/include/tusb_config.h @@ -77,7 +77,7 @@ #define CFG_TUD_CDC_SIGROK 0 // no sigrok for debug probe #endif #if !defined(NDEBUG) - #define CFG_TUD_CDC_DEBUG 1 // CDC for debug output of the probe + #define CFG_TUD_CDC_DEBUG 1 // CDC for debug output of the probe #else #define CFG_TUD_CDC_DEBUG 0 #endif diff --git a/src/cdc_debug.c b/src/cdc_debug.c index 29649df07..af60cf5cf 100644 --- a/src/cdc_debug.c +++ b/src/cdc_debug.c @@ -58,7 +58,7 @@ static EventGroupHandle_t events; static uint8_t cdc_debug_buf[CFG_TUD_CDC_TX_BUFSIZE]; -static bool m_connected = false; +static volatile bool m_connected = false; @@ -70,8 +70,10 @@ void cdc_debug_thread(void *ptr) for (;;) { #if CFG_TUD_CDC_DEBUG if ( !m_connected) { - // wait here some time (until my terminal program is ready) - m_connected = true; + // wait here until connected (and until my terminal program is ready) + while ( !m_connected) { + vTaskDelay(pdMS_TO_TICKS(100)); + } vTaskDelay(pdMS_TO_TICKS(100)); } @@ -107,17 +109,12 @@ void cdc_debug_thread(void *ptr) void cdc_debug_line_state_cb(bool dtr, bool rts) { - /* CDC drivers use linestate as a bodge to activate/deactivate the interface. - * Resume our UART polling on activate, stop on deactivate */ - if (!dtr && !rts) { - vTaskSuspend(task_printf); -#if CFG_TUD_CDC_DEBUG - tud_cdc_n_write_clear(CDC_DEBUG_N); -#endif + // CDC drivers use linestate as a bodge to activate/deactivate the interface. + if ( !dtr && !rts) { m_connected = false; } else { - vTaskResume(task_printf); + m_connected = true; } } // cdc_debug_line_state_cb diff --git a/src/cdc_uart.c b/src/cdc_uart.c index 5bea313f5..193d10026 100644 --- a/src/cdc_uart.c +++ b/src/cdc_uart.c @@ -64,7 +64,7 @@ static TaskHandle_t task_uart = NULL; static StreamBufferHandle_t stream_uart; -static bool m_connected = false; +static volatile bool m_connected = false; #define EV_TX_COMPLETE 0x01 @@ -85,8 +85,10 @@ void cdc_thread(void *ptr) uint32_t cdc_rx_chars; if ( !m_connected) { - // wait here some time (until my terminal program is ready) - m_connected = true; + // wait here until connected (and until my terminal program is ready) + while ( !m_connected) { + vTaskDelay(pdMS_TO_TICKS(100)); + } vTaskDelay(pdMS_TO_TICKS(100)); } @@ -182,11 +184,7 @@ void cdc_uart_line_coding_cb(cdc_line_coding_t const* line_coding) * CDC bitrate updates are reflected on \a PICOPROBE_UART_INTERFACE */ { - vTaskSuspend(task_uart); - tud_cdc_n_write_clear(CDC_UART_N); - tud_cdc_n_read_flush(CDC_UART_N); uart_set_baudrate(PICOPROBE_UART_INTERFACE, line_coding->bit_rate); - vTaskResume(task_uart); } // cdc_uart_line_coding_cb #endif @@ -194,17 +192,12 @@ void cdc_uart_line_coding_cb(cdc_line_coding_t const* line_coding) void cdc_uart_line_state_cb(bool dtr, bool rts) { - /* CDC drivers use linestate as a bodge to activate/deactivate the interface. - * Resume our UART polling on activate, stop on deactivate */ - if (!dtr && !rts) { - vTaskSuspend(task_uart); -#if CFG_TUD_CDC_UART - tud_cdc_n_write_clear(CDC_UART_N); -#endif + // CDC drivers use linestate as a bodge to activate/deactivate the interface. + if ( !dtr && !rts) { m_connected = false; } else { - vTaskResume(task_uart); + m_connected = true; } } // cdc_uart_line_state_cb