Skip to content

Commit d903a03

Browse files
committed
shared/tinyusb: Fix data loss after interrupt character.
After detecting interrupt character and returning early, mark the CDC interface as pending if there's still data in the USB buffer. This ensures subsequent data (like user typing new commands after Ctrl-C) is not lost. Without this, data that arrived in USB packets after the interrupt would be discarded until the next USB RX interrupt naturally occurred. Signed-off-by: Andrew Leech <[email protected]>
1 parent 393908a commit d903a03

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

shared/tinyusb/mp_usbd_cdc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ void tud_cdc_rx_cb(uint8_t itf) {
114114
// Schedule keyboard interrupt
115115
mp_sched_keyboard_interrupt();
116116

117-
// Stop processing (discard remaining bytes in temp and USB buffer)
117+
// Mark interface as pending if there's still data in USB buffer
118+
// (so subsequent data like user typing new commands isn't lost)
119+
if (tud_cdc_n_available(itf) > 0) {
120+
cdc_itf_pending |= (1 << itf);
121+
}
122+
123+
// Stop processing (discard remaining bytes in current packet)
118124
return;
119125
}
120126
}

0 commit comments

Comments
 (0)