Skip to content

USB (serial) logging freezes the device unless buffer is emptied. #5797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AndKe opened this issue Jan 3, 2017 · 5 comments
Closed

USB (serial) logging freezes the device unless buffer is emptied. #5797

AndKe opened this issue Jan 3, 2017 · 5 comments
Assignees
Labels
Type: Bug USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer

Comments

@AndKe
Copy link

AndKe commented Jan 3, 2017

Try this simple code:(on any leonardo)
I have found Leonardo to fail, and same microcontroller, on a pro micro to work:

 unsigned long last;

 void setup() {
   Serial.begin(115200);
   pinMode(13, OUTPUT);
 }

 void loop() {
   if (millis() - last > 999)  {
     last = millis();
     Serial.println("one second");
     digitalWrite(13, !digitalRead(13));
   }
 }

Observe how LED stops flashing whenever you open/close the terminal
(Ctrl-Shift-M)

To put it simply: if the log target is not ready, (DTR ?) - it all goes
to h*ll

@facchinm
Copy link
Member

facchinm commented Jan 4, 2017

Serial over USB (CDC) doesn't have any timeout on AVR. We solved the issue on SAMD with arduino/ArduinoCore-samd#154 , we could use the same approach here unless the current one is the expected behaviour (and I'm sure I've seen at least a project using this start/stop "feature" to control the sketch execution).
@cmaglie @sandeepmistry any thought on that?

@NicoHood
Copy link
Contributor

NicoHood commented Jan 4, 2017

So to summarize:
The program blocks because the usb send function blocks. Usb send is executed even though DTR is set (why?). This happens here:
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/CDC.cpp#L225

The question is which part of the usb core blocks the sending. Because avr works a bit different:
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/USBCore.cpp#L265

I am not sure why DTR is left HIGH if the port is closed. I could not reproduce this bug. If i close the serial monitor the led continues blinking. I'd rather fix your os ;)

@AndKe
Copy link
Author

AndKe commented Jan 4, 2017

the OS is Linux (not an option to run some spy/malware/bloat), the Arduino IDE is current version. And I can only reproduce it on Leonardo, Pro Micro (same microcontroller) works as expected (does not react to console being open/closed.)

@facchinm
Copy link
Member

facchinm commented Jan 4, 2017

@AndKe ,
that's really strange... Are you using the same core on both the boards or Pro Micro uses another core/variant? Which Linux distro are you running?
On vanilla Arch the led blinks whether the serial monitor is open or closed. On AVR cores < 1.6.12 there was a bug in suspend/resume (solved with #5135) which was affecting Ubuntu/Mint, maybe it's your case?

@facchinm facchinm added the Waiting for feedback More information must be provided before we can proceed label Jan 4, 2017
@facchinm facchinm self-assigned this Jan 4, 2017
@AndKe
Copy link
Author

AndKe commented Jan 6, 2017

That was 1.6.13 - now tested on 1.8.0 - and cannot reproduce the problem anymore.

@AndKe AndKe closed this as completed Jan 6, 2017
@per1234 per1234 removed the Waiting for feedback More information must be provided before we can proceed label Sep 11, 2017
@per1234 per1234 changed the title Dangerous bug in Leonardo : USB (serial) logging freezes the device unless buffer is emptied. USB (serial) logging freezes the device unless buffer is emptied. Apr 7, 2021
@per1234 per1234 added Type: Bug USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer labels Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer
Projects
None yet
Development

No branches or pull requests

4 participants