Permalink
Browse files

Backport USB RX fix

Backport fix for USB serial port overrun.

Signed-off-by: Paul Brook <paul@codesourcery.com>
  • Loading branch information...
1 parent 3d14b0a commit bd9ccb4c705d97347ee6ae48bbd50761b03c980c Paul Brook committed Sep 27, 2012
Showing with 9 additions and 3 deletions.
  1. +8 −2 cores/minimus/CDC.cpp
  2. +1 −1 cores/minimus/USBCore.cpp
View
@@ -141,16 +141,22 @@ void Serial_::end(void)
void Serial_::accept(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
- int c = USB_Recv(CDC_RX);
int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
- if (i != buffer->tail) {
+
+ // while we have room to store a byte
+ while (i != buffer->tail) {
+ int c = USB_Recv(CDC_RX);
+ if (c == -1)
+ break; // no more data
buffer->buffer[buffer->head] = c;
buffer->head = i;
+
+ i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
}
}
@@ -603,7 +603,7 @@ ISR(USB_GEN_vect)
{
#ifdef CDC_ENABLED
USB_Flush(CDC_TX); // Send a tx frame if found
- while (USB_Available(CDC_RX)) // Handle received bytes (if any)
+ if (USB_Available(CDC_RX)) // Handle received bytes (if any)
Serial.accept();
#endif

0 comments on commit bd9ccb4

Please sign in to comment.