From @EmbedHA on January 3, 2014 13:19
On the Arduino DUE, using IDE 1.5.4, following issue was found.
For a time of up to ca. 6.6ms after a SerialUSB.readBytes statement, the reception of serial bytes is corrupted by randomly dropped bytes - mostly one byte, sometimes two. This was tested tested from 115200baud down to 28800baud for the serial input and for serial1 and serial2.
An extensive description of a setup  to check the issue, sample code to demonstrate the problem, test logs etc. can be found in the Arduino forum: http://forum.arduino.cc/index.php?topic=207299.0
Copied from original issue: arduino/Arduino#1784
Activity
agdl commentedon Feb 8, 2017  
From @morganchristiansson on April 17, 2014 10:11
I found a way to deal with dropped bytes by sending a "ready to receive signal" or "done processing previous command" from the arduino to let it know it's entered a tight read loop to process the next message, so that can deal with the data stream without buffers overflowing or corrupting.
I was sending data as fast as I could send it, and this resulted in random dropped bytes everywhere. This stopped happening after I started waiting for the arduino to finish processing previous command and re-enter tight read loop before sending more data.
agdl commentedon Feb 8, 2017  
From @EmbedHA on April 17, 2014 17:52
Thanks for describing this workaround. It did this meanwhile. However, this does not change the fact that there is this problem remaining in the Arduino libraries. I have the impression that the USB functions are very buggy. I posted another USB problem in the forum, namely freeze of the program when USB connection is disconnected while receiving/sending data.
agdl commentedon Feb 8, 2017  
From @odbol on November 5, 2015 23:14
@EmbedHA do you have a link to that post? I am having the exact same problem: my Due sketch freezes if you unplug the USB. Didn't used to happen on 1.5.5.
agdl commentedon Feb 8, 2017  
From @EmbedHA on November 6, 2015 6:52
Hello,
I gave up on Arduino and use Atmel Studio now directly with ASF. By checking if there is a USB connection at all, and also the free size of the USB transmit buffer before writing into it, this can be avoided. Such functions are available under ASF. The problem occurs if you perform a write over USB but your data does not fit any more into the transmit buffer of the USB driver. Obviously, the USB driver waits then until some transmit over the interface has taken place, but if that does not occur it hangs.
Best Regards
Christian
Am 06.11.2015 um 00:14 schrieb Tyler Freeman notifications@github.com:
agdl commentedon Feb 8, 2017  
From @odbol on November 6, 2015 7:31
@EmbedHA that's exactly what I'm looking for. What functions are you using to checkout the USB connection? Do you have any ASF code you can point me to?
agdl commentedon Feb 8, 2017  
From @EmbedHA on November 6, 2015 7:53
To check for the connection, you need to have callback function. With ASF, this is specified in the conf_usb.h. I do not know if it is possible by some trick under Arduino to have this be considered during compilation. The function is called upon established connection. There is a corresponding callback for disconnection. This alone does not help, you have to check also the transmit buffer. The ASF function is udi_cdc_get_free_tx_buffer. There is good online documentation from Atmel for the ASF framework.
Am 06.11.2015 um 08:31 schrieb Tyler Freeman notifications@github.com:
agdl commentedon Feb 8, 2017  
From @morganchristiansson on November 6, 2015 11:53
I started using the Arduino compatible Teensy board which doesn't have this problem and has excellent USB performance for my project. https://www.pjrc.com/teensy/td_serial.html
Teensy also has better I/O, performance and memory.