Skip to content
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

Fix CDC write() when DTR is not set #3839

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NicoHood
Copy link
Contributor

Fix #1182

This should not give any disadvantage. You still can check via while(!Serial); if the Serial port is opened. If you write to a not opened port this should not cause any problems. This is how other firmwares like lufa handle it. Also you dont need to set a DTR state to co0mmunicate with the device. This enables more options.

https://github.com/abcminiuser/lufa/blob/master/Projects/USBtoSerial/USBtoSerial.c#L197
https://github.com/abcminiuser/lufa/blob/master/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c#L193

We could also check the baud info, but since it is set to 57600 by default this doesnt make sense. Maybe we should change this as well?
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/CDC.cpp#L34

TODO (from peter)

  • Could you also modify the Due core? Will test it if needed.
  • Could you also adapt the comment, it does not hold anymore
  • The configured flag is not cleared upon disconnection, but that might not be that important right now.

@NicoHood
Copy link
Contributor Author

@matthijskooijman build this please

@cmaglie
Copy link
Member

cmaglie commented Sep 22, 2015

@ArduinoBot build this please

@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer labels Sep 22, 2015
@cmaglie cmaglie self-assigned this Sep 22, 2015
@NicoHood
Copy link
Contributor Author

The PR like this does not work for me I've noticed. If the host is not listening my RawHID dev sketch will block for a long time. I tried to check for baud() but this also didnt help (set the value default to zero of course).

But adding && availableForWrite() helped.

I will add this to the patch. The only thing we could also add would be baud() but that was not needed in this case. Tested under linux 64 bit elementary os.

@PeterVH
Copy link

PeterVH commented Sep 26, 2015

I think testing for availableForWrite() inside write() is not correct. It looses the automatic flow control USB provides: if the process on the host temporarily does not catch up with the data you send it, the write method should block till data is sent. If this is not acceptable for an application, it should call availableForWrite() by itself.

It is not cleared on disconnect? Where do we have to handle this? (this is very important)

Just consulted the datasheet. The VBUSTI irq fires upon connect/disconnect. The VBUS status bit in USBSTA tells you the current state. Did not try this though.

@NicoHood
Copy link
Contributor Author

Without the writeavailable my device locked up. Have to check this again. Feel free to also test it, I will not have time to debug this in the next days.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) feature request A request to make an enhancement (not a bug fix) USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArduinoISP on the Leonardo does not work on windows
5 participants