arduino / arduino/ArduinoCore-sam
Arduino Due SerialUSB bug on monitor close/USB unplug
- Dominant language
- HTML
- Stars
- 91
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
Hi all,
I'm trying to develop an application where the arduino Due is continuously working (always powered), and I can connect to it using the native USB, so I can get data about the process. I have found unexpected behavior of the Due board when it is unplugged, or the serial port is closed.
For the following test I have used this Arduino Code. With this one two different problems are observed.
```
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
SerialUSB.begin(115200);
}
void loop() {
SerialUSB.print("H");
SerialUSB.print("e");
SerialUSB.print("y");
SerialUSB.print(" ");
SerialUSB.print(":");
SerialUSB.println(")");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(200); // wait for a second
}
```
I have found this issues
->If Serial monitor is closed while sending data through the native USB (SerialUSB) the main loop gets freezed, until the serial monitor is opened again. (With the test code, it can be observed that the led stops blinking).
->If unplugged the Native USB while sending data (and keep powered with the other USB), when a new monitor is opened, the received data order is changed. How can it be? The data order gets changed, and while unplugged the led stops blinking.
I also found a post where one of the bugs is mentioned:
[https://forum.arduino.cc/index.php?topic=560839.0](url)
As Sanworks_J explains this problem only appears when the computer used as serial monitor is Windows 10. I have check both problems in Linux, and in this case the board works correctly.
I have followed this Steps to in the second issue.
-->Connect both the programming USB (just for power, no data) and Native USB.
--> Upload the sketch to the board, and open the serial monitor, native USB. (Data received correctly).
--> While serial monitor is opened, unplug the Native USB (while powered with the other USB)
--> Plug the Native USB again. Close the monitor opened before(because it is stopped).
--> Open a new serial monitor, and the received data from that moment the data order is wrong.
Since that moment, the received messages are as follows.
```
)eH y):H
ye:
)eH y):H
ye:
```
When it should be:
```
Hey :)
Hey :)
Hey :)
```
I have made this test in different PCs and with different Arduino Due boards, with the same results in Win10. When used Linux it doesn't happen, but the program gets stopped when unplugged the USB, this problem remains in Linux.
Any possible solution to this issue?
Thanks in advance.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided Due sketch and reproduce the behavior by closing the native-USB serial monitor or unplugging and reconnecting it while powered through the programming USB. Compare Windows 10 and Linux behavior while tracing the SerialUSB/native USB handling. Done means the loop continues after disconnect or monitor close and the reopened monitor receives the messages in the original order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100