Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8a37e72

Browse files
pbrookcmaglie
authored andcommittedMay 23, 2014
Fix race condition in USB CDC transmit
If the Start of Frame interrupt triggers just after the call to USB_SendSpace in USB_Send then we can get data loss. When the first bank is full and the second partially full, the SOF handler will release the second bank via USB_Flush. Data is then lost due to overflow as USB_Send continues writing data to the now-closed bank. Fix this by re-checking the FIFO status inside LockEP, immediately before doing the data write. Signed-off-by: Paul Brook <[email protected]>
1 parent 0e11bbb commit 8a37e72

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎arduino/cores/arduino/USBCore.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,12 @@ int USB_Send(u8 ep, const void* d, int len)
290290

291291
if (n > len)
292292
n = len;
293-
len -= n;
294293
{
295294
LockEP lock(ep);
295+
// Frame may have been released by the SOF interrupt handler
296+
if (!ReadWriteAllowed())
297+
continue;
298+
len -= n;
296299
if (ep & TRANSFER_ZERO)
297300
{
298301
while (n--)

0 commit comments

Comments
 (0)
Please sign in to comment.