Skip to content

Commit ca901a8

Browse files
authored
feat(tinyusb_cdc): write timeout
Added a timeout check to prevent locking during CDC writes.
1 parent c9a5d27 commit ca901a8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cores/esp32/USBCDC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,11 @@ size_t USBCDC::write(const uint8_t *buffer, size_t size) {
405405
return 0;
406406
}
407407
size_t to_send = size, so_far = 0;
408+
// writeTimeout will prevent that TinyUSB failure locks the while(to_send) loop
409+
uint32_t writeTimeout = millis() + tx_timeout_ms;
408410
while (to_send) {
409-
if (!tud_cdc_n_connected(itf)) {
411+
if (!tud_cdc_n_connected(itf) || millis() > writeTimeout) {
412+
log_e("USB is disconnected or CDC writing has timed out.");
410413
size = so_far;
411414
break;
412415
}

0 commit comments

Comments
 (0)