Skip to content

Commit

Permalink
Removed glitches on probe startup.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rgrr committed Apr 23, 2023
1 parent b4e967b commit 1f5675d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

VERSION_MAJOR := 1
VERSION_MINOR := 12
VERSION_MINOR := 13

BUILD_DIR := build
PROJECT := picoprobe
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion include/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions src/cdc_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;



Expand All @@ -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));
}

Expand Down Expand Up @@ -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

Expand Down
23 changes: 8 additions & 15 deletions src/cdc_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}

Expand Down Expand Up @@ -182,29 +184,20 @@ 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



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

Expand Down

0 comments on commit 1f5675d

Please sign in to comment.