I noticed that when sending 64 or more bytes from a pc to the Due's native USB port, bytes get lost.
This sketch reproduces it:
static const int led = 13;
void setup() {
// initialize serial:
SerialUSB.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
// if there's any serial available, read it:
int i = 0;
while (SerialUSB.available() > 0) {
SerialUSB.read();
i++;
}
SerialUSB.println(i);
digitalWrite(led, HIGH);
delay(250);
digitalWrite(led, LOW);
delay(250);
}
If you send say 80 bytes to the serial port (e.g. simply via an echo to /dev/ttyACM1), the sketch prints series of numbers like this : 0 0 0 63 0 0, which indicates that (at least) 17 bytes are lost.
It can easily be fixed in CDC.cpp: the code defines a ring buffer of size **CDC_**SERIAL_BUFFER_SIZE (==512). But the code that uses it uses the SERIAL_BUFFER_SIZE macro which is 64. So replacing SERIAL_BUFFER_SIZE with CDC_SERIAL_BUFFER_SIZE in CDC.cpp fixed the problem for me (I wanted to run ArduinoISP which requires receiving 128 byte messages from avrdude).
It will go wrong if you feed the due more than 511 bytes at once. Therefore it would be better to use USB's built in handshaking mechanism (make the device reply with NAK or NYET until it has room to store more incoming data). The same was done for the Leonardo. I could look into how to do that with the due's otg controller, but if someone already knows, that would save time...