File tree 2 files changed +9
-3
lines changed
hardware/arduino/cores/arduino
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -141,16 +141,22 @@ void Serial_::end(void)
141
141
void Serial_::accept (void )
142
142
{
143
143
ring_buffer *buffer = &cdc_rx_buffer;
144
- int c = USB_Recv (CDC_RX);
145
144
int i = (unsigned int )(buffer->head +1 ) % SERIAL_BUFFER_SIZE;
146
145
147
146
// if we should be storing the received character into the location
148
147
// just before the tail (meaning that the head would advance to the
149
148
// current location of the tail), we're about to overflow the buffer
150
149
// and so we don't write the character or advance the head.
151
- if (i != buffer->tail ) {
150
+
151
+ // while we have room to store a byte
152
+ while (i != buffer->tail ) {
153
+ int c = USB_Recv (CDC_RX);
154
+ if (c == -1 )
155
+ break ; // no more data
152
156
buffer->buffer [buffer->head ] = c;
153
157
buffer->head = i;
158
+
159
+ i = (unsigned int )(buffer->head +1 ) % SERIAL_BUFFER_SIZE;
154
160
}
155
161
}
156
162
Original file line number Diff line number Diff line change @@ -603,7 +603,7 @@ ISR(USB_GEN_vect)
603
603
{
604
604
#ifdef CDC_ENABLED
605
605
USB_Flush (CDC_TX); // Send a tx frame if found
606
- while (USB_Available (CDC_RX)) // Handle received bytes (if any)
606
+ if (USB_Available (CDC_RX)) // Handle received bytes (if any)
607
607
Serial.accept ();
608
608
#endif
609
609
You can’t perform that action at this time.
0 commit comments