Skip to content

usb: c33: fix serial errors #106

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

Merged
merged 1 commit into from
Aug 25, 2023
Merged
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
59 changes: 29 additions & 30 deletions cores/arduino/usb/SerialUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,40 @@ size_t _SerialUSB::write(uint8_t c) {
return write(&c, 1);
}

size_t _SerialUSB::write(const uint8_t *buf, size_t length) {
if (!_running) {
#include "device/usbd_pvt.h"

size_t _SerialUSB::write(const uint8_t *buf, size_t size) {
if (!_running) {
return 0;
}

static uint64_t last_avail_time;
int written = 0;
if (connected()) {
for (size_t i = 0; i < length;) {
int n = length - i;
int avail = tud_cdc_write_available();
if (n > avail) {
n = avail;
}
if (n) {
int n2 = tud_cdc_write(buf + i, n);
tud_task();
tud_cdc_write_flush();
i += n2;
written += n2;
last_avail_time = millis();
} else {
tud_task();
tud_cdc_write_flush();
if (connected() ||
(!tud_cdc_write_available() && millis() > last_avail_time + 1000 /* 1 second */)) {
break;
}
}
if (!connected()) {
return 0;
}
usbd_int_set(false);
size_t to_send = size, so_far = 0;
while(to_send){
size_t space = tud_cdc_write_available();
if(!space){
usbd_int_set(true);
tud_cdc_write_flush();
continue;
}
if(space > to_send){
space = to_send;
}
size_t sent = tud_cdc_write( buf+so_far, space);
usbd_int_set(true);
if(sent){
so_far += sent;
to_send -= sent;
tud_cdc_write_flush();
} else {
size = so_far;
break;
}
} else {
// reset our timeout
last_avail_time = 0;
}
return written;
return size;
}

_SerialUSB::operator bool() {
Expand Down
2 changes: 1 addition & 1 deletion extras/tinyusb
Submodule tinyusb updated 297 files
4 changes: 2 additions & 2 deletions variants/PORTENTA_C33/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@


// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE ((TUD_OPT_HIGH_SPEED ? 512 : 64) * 8)
#define CFG_TUD_CDC_TX_BUFSIZE ((TUD_OPT_HIGH_SPEED ? 512 : 64) * 8)
#define CFG_TUD_CDC_RX_BUFSIZE (4096)
#define CFG_TUD_CDC_TX_BUFSIZE (64)

// CDC Endpoint transfer buffer size, more is faster
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
Expand Down