Skip to content

Replace tud_cdc_connected() with tud_ready() to ensure proper USB state detection #63

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pico_sdk_sigrok/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ include(pico_sdk_import.cmake)
project(pico_sdk_sigrok C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# DTR is not used for USB CDC connection, so we can set this to 1
# This will allow PulseView to connect independently of the DTR signal
add_definitions(-DPICO_STDIO_USB_CONNECTION_WITHOUT_DTR=1)
pico_sdk_init()

add_executable(pico_sdk_sigrok
Expand Down
Binary file modified pico_sdk_sigrok/build/pico_sdk_sigrok.uf2
Binary file not shown.
4 changes: 2 additions & 2 deletions pico_sdk_sigrok/pico_sdk_sigrok.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ volatile bool mask_xfer_err;
void my_stdio_usb_out_chars(const char *buf, int length) {
static uint64_t last_avail_time;
uint32_t owner;
if (tud_cdc_connected()) {
if (tud_ready()) {
for (int i = 0; i < length;) {
int n = length - i;
int avail = (int) tud_cdc_write_available();
Expand All @@ -81,7 +81,7 @@ void my_stdio_usb_out_chars(const char *buf, int length) {
} else {
tud_task();
tud_cdc_write_flush();
if (!tud_cdc_connected() ||
if (!tud_ready() ||
(!tud_cdc_write_available() && time_us_64() > last_avail_time + PICO_STDIO_USB_STDOUT_TIMEOUT_US)) {
break;
}
Expand Down