arduino / arduino/ArduinoCore-avr
16u2 USB2Serial firmware does low baud rates wrong
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
http://forum.arduino.cc/index.php?topic=385567.msg2670448#msg2670448
The xxxU2 firmware for implementing USB to Serial does not handle very low bitrates (300bps) correctly.
These low bitrates are not possible on a 16MHz AVR using the U2X doublespeed setting (which is used for Arduino, normally.) The AVR firmware contains code that checks for an overly high divisor and unsets U2X, but it does not recalculate the divisor.
```
/* Special case 57600 baud for compatibility with the ATmega328 bootloader. */
UBRR1 = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600)
? SERIAL_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)
: SERIAL_2X_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
UCSR1C = ConfigMask;
UCSR1A = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600) ? 0 : (1 << U2X1);
UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1));
```
The SAM firmware does not have any checks at all to unset U2X.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the xxxU2 firmware's AVR and SAM serial configuration paths, then inspect the shown UBRR1 and U2X1 handling. Verify how the divisor is selected for very low rates such as 300bps, including the AVR fallback and the SAM path. Done means low baud rates configure correctly without an invalid doublespeed setting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100