Merge pull request #4922 from dhalbert/usb-cdc-buffers

Failed to advance buffer ptrs in usb_cdc.Serial properly
This commit is contained in:
Scott Shawcroft 2021-06-25 10:58:32 -07:00 committed by GitHub
commit 6900513e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,10 @@ size_t common_hal_usb_cdc_serial_read(usb_cdc_serial_obj_t *self, uint8_t *data,
uint32_t 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.
len -= total_num_read;
data += total_num_read;
// Read more if we have time.
// Use special routine to avoid pulling in uint64-float-compatible math routines.
uint64_t timeout_ms = float_to_uint64(self->timeout * 1000); // Junk value if timeout < 0.
@ -78,6 +82,10 @@ size_t common_hal_usb_cdc_serial_write(usb_cdc_serial_obj_t *self, const uint8_t
tud_cdc_n_write_flush(self->idx);
if (wait_forever || wait_for_timeout) {
// Continue writing the rest of the buffer.
len -= total_num_written;
data += total_num_written;
// Write more if we have time.
// Use special routine to avoid pulling in uint64-float-compatible math routines.
uint64_t timeout_ms = float_to_uint64(self->write_timeout * 1000); // Junk value if write_timeout < 0.