Skip to content

Commit f92b235

Browse files
committed
Minor bug fixes to the 8U2 USB-to-serial firmware.
1 parent 32388c9 commit f92b235

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

hardware/arduino/firmwares/arduino-usbserial/Arduino-usbserial.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ int main(void)
8888

8989
for (;;)
9090
{
91-
/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
92-
int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
93-
if (!(ReceivedByte < 0) && !(RingBuffer_IsFull(&USBtoUSART_Buffer)))
94-
RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
91+
/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
92+
if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
93+
{
94+
int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
95+
96+
/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
97+
if (!(ReceivedByte < 0))
98+
RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
99+
}
95100

96101
/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
97102
RingBuff_Count_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
@@ -153,10 +158,7 @@ void SetupHardware(void)
153158
/** Event handler for the library USB Configuration Changed event. */
154159
void EVENT_USB_Device_ConfigurationChanged(void)
155160
{
156-
157-
158-
if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface)))
159-
;
161+
CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
160162
}
161163

162164
/** Event handler for the library USB Unhandled Control Request event. */
@@ -205,12 +207,13 @@ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCI
205207
UCSR1C = 0;
206208

207209
/* Special case 57600 baud for compatibility with the ATmega328 bootloader. */
208-
UCSR1A = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600) ? 0 : (1 << U2X1);
209-
UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1));
210-
UCSR1C = ConfigMask;
211210
UBRR1 = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600)
212211
? SERIAL_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)
213212
: SERIAL_2X_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
213+
214+
UCSR1C = ConfigMask;
215+
UCSR1A = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600) ? 0 : (1 << U2X1);
216+
UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1));
214217
}
215218

216219
/** ISR to manage the reception of data from the serial port, placing received bytes into a circular buffer
@@ -233,11 +236,7 @@ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const C
233236
bool CurrentDTRState = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR);
234237

235238
if (CurrentDTRState)
236-
{
237-
AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK;
238-
}
239+
AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK;
239240
else
240-
{
241-
AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK;
242-
}
241+
AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK;
243242
}

hardware/arduino/firmwares/arduino-usbserial/Descriptors.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
172172
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | CDC_RX_EPNUM),
173173
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
174174
.EndpointSize = CDC_TXRX_EPSIZE,
175-
.PollingIntervalMS = 0x00
175+
.PollingIntervalMS = 0x01
176176
},
177177

178178
.CDC_DataInEndpoint =
@@ -182,7 +182,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
182182
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | CDC_TX_EPNUM),
183183
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
184184
.EndpointSize = CDC_TXRX_EPSIZE,
185-
.PollingIntervalMS = 0x00
185+
.PollingIntervalMS = 0x01
186186
}
187187
};
188188

0 commit comments

Comments
 (0)