arduino / arduino/ArduinoCore-avr

USB Serial freezes on Arduino Pro Micro / Mac OS

Open
#53 8 comments 0 reactions 0 assignees View on GitHub
bug waiting for feedback
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I have Arduino Pro Micro connected via USB to my Mac (Mac OS Sierra 10.12.6). Arduino IDE is 1.8.7, and the board is identified there as "Board: SparkFun Pro Micro / Processor: ATmega32U4 5V/16 Mhz". Board info gives: "BN: Unknown board / VID: 1B4F / PID: 9206".

If I send to it more than 384 bytes of data at once, only 384 bytes will be displayed, and the board will freeze, freezing Arduino Serial Monitor as well (or `screen`) until I unplug the board from USB. While frozen, I can't upload new sketch to it either.

Here's the simplest code that I use:

```cpp
void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available())
{
Serial.write(Serial.read());
}
}
```

So it reads the data at the fastest speed possible and just echoes it back. If I don't echo the data back, but just read it to empty the serial buffer, the problem still persists.

Once I upload this sketch to Arduino, I can either open the Serial Monitor, or use `screen /dev/cu.usbmodem14121 9600` from the console. As I type on the keyboard in `screen`, or send entire strings via the Serial Monitor, the input will be echoed back. But If I copy a large block of text (more than 384 symbols) and paste that into the `screen` session or paste and send via Serial Monitor, only the first 384 symbols will be echoed back, and Arduino will freeze.

Rebooting the Mac doesn't help.

I noticed that if I force the serial speed to 1200bps (for example, by using `screen /dev/cu.usbmodem14121 1200`), then I will see no freezing. 2400bps and above results in the same freezing issue. I tested this on 3 different Arduino Pro Micro boards from different vendors, and all have the same issue. I used bare boards, with no external components attached to pins.

I understand that these boards connect USB directly to ATmega32U4 chip, so the problem seems to be either in the chip itself (less likely) or the USB drivers / USB Serial implementation in Arduino (more likely).

I originally submitted this issue at https://github.com/arduino/Arduino/issues/8260 and @facchinm suggested to move the issue here and provided the following additional information:

> the `Serial` object exposed by boards based on 32u4 is USB based, so HardwareSerial is not involved. The code is [here](https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/CDC.cpp). Changing baud rate should not affect the CDC subsystem EXCEPT for 1200bps, which triggers a reboot to bootloader every time the port is opened with that baud. So the problem is always reproducible.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with cores/arduino/CDC.cpp, the USB-based Serial implementation identified in the issue, and reproduce the sketch's behavior on an ATmega32U4 board. Test sending more than 384 bytes at 2400 bps or above, then verify that the complete input is echoed and the board, Serial Monitor, and screen do not freeze.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp, macos
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.