Usb serial fix queue full crash (#1763)

* fixed usb serial queue crashing

* fixed usb input buffer handling

* fixed black screen issue
This commit is contained in:
Bernd Herzog 2024-01-12 21:49:10 +01:00 committed by GitHub
parent 0a8194fa10
commit 409242507c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 15 deletions

View file

@ -348,19 +348,23 @@ void cmd_sd_write_binary(BaseSequentialStream* chp, int argc, char* argv[]) {
return;
}
long size = (int)strtol(argv[0], NULL, 10);
size_t size = (size_t)strtol(argv[0], NULL, 10);
chprintf(chp, "send %d bytes\r\n", size);
uint8_t buffer;
uint8_t buffer[USB_BULK_BUFFER_SIZE];
for (long i = 0; i < size; i++) {
if (chSequentialStreamRead(chp, &buffer, 1) == 0)
do {
size_t bytes_to_read = size > USB_BULK_BUFFER_SIZE ? USB_BULK_BUFFER_SIZE : size;
size_t bytes_read = chSequentialStreamRead(chp, &buffer[0], bytes_to_read);
if (bytes_read != bytes_to_read)
return;
auto error = shell_file->write(&buffer, 1);
auto error = shell_file->write(&buffer[0], bytes_read);
if (report_on_error(chp, error)) return;
}
size -= bytes_read;
} while (size > 0);
chprintf(chp, "ok\r\n");
}