Skip to content

Commit 4c41dec

Browse files
committed
Bootloader: fixed blocking read from USB-CDC
For some reason the blocking read from the original USB-CDC driver is not reliable. As a workaround it has been reimplemented using a polling loop with the non-blocking read function that, instead, is much more reliable. Eventually the USB_Read_blocking(..) in cdc_enumerate.c will be fixed in the future.
1 parent 3a1c454 commit 4c41dec

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

bootloaders/zero/drivers/cdc_enumerate.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,5 +750,16 @@ uint32_t cdc_read_buf_xmd(void* data, uint32_t length)
750750
return 0;
751751

752752
/* Blocking read till specified number of bytes is received */
753-
return USB_Read_blocking(&pCdc, (char *)data, length);
753+
// XXX: USB_Read_blocking is not reliable
754+
// return USB_Read_blocking(&pCdc, (char *)data, length);
755+
756+
char *dst = (char *)data;
757+
uint32_t remaining = length;
758+
while (remaining) {
759+
uint32_t readed = USB_Read(&pCdc, (char *)dst, remaining);
760+
remaining -= readed;
761+
dst += readed;
762+
}
763+
764+
return length;
754765
}

bootloaders/zero/samd21_sam_ba.bin

-80 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)