Skip to content
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

Restore ability to read usb_cdc buffer when serial client is disconnected #10177

Merged
merged 1 commit into from
Mar 24, 2025
Merged
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
8 changes: 2 additions & 6 deletions shared-module/usb_cdc/Serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data,
// Read up to len bytes immediately.
// The number of bytes read will not be larger than what is already in the TinyUSB FIFO.
uint32_t total_num_read = 0;
if (tud_cdc_n_connected(self->idx)) {
total_num_read = tud_cdc_n_read(self->idx, data, len);
}
total_num_read = tud_cdc_n_read(self->idx, data, len);

if (wait_forever || wait_for_timeout) {
// Continue filling the buffer past what we already read.
Expand All @@ -48,9 +46,7 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data,
data += num_read;

// Try to read another batch of bytes.
if (tud_cdc_n_connected(self->idx)) {
num_read = tud_cdc_n_read(self->idx, data, len);
}
num_read = tud_cdc_n_read(self->idx, data, len);
total_num_read += num_read;
}
}
Expand Down