I have been doing some testing of the Native USB port by sending a large chunk of data (1 Megabyte) from the Due to a Windows 7 I3 notebook computer.
I create a 16K (16384) buffer of ramp data (0 to 255) and then transmit it to the PC using:
for (int j = 0;j < 64;j++){
SerialUSB.write(test_buf,16384);
}
Everything tested fine, I had a C# program reading in the 1 Megabyte, checking for the 0 to 255 repeating ramp. 100% OK.
Then on the Arduino Due side, I decided to fill half the array with a different pattern, to make sure the PC side would catch the bad data. It didn't.
What I found was that SerialUSB.write repeats the first 512 bytes for any array transmission larger than 512 bytes.
Could someone point me to where SerialUSB.write is defined in the Arduino structure?
Thanks!
Yes, I am replying to my own post. The problem seemed to lie in USBCore.cpp, routine USBD_Send. The data pointer in the loop at the bottom was not being updated. Here are the changes to USBD_Send (two lines) I made to take care of the issue:
// Blocking Send of data to an endpoint
uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
{
uint32_t n;
int r = len;
//const uint8_t* data = (const uint8_t*)d;
//THIS IS A CHANGE FROM CONST TO UPDATE THE POINTER - WRD
uint8_t* data = (uint8_t*)d;
if (!_usbConfiguration)
{
TRACE_CORE(printf("pb conf\n\r")
return -1;
}
while (len)
{
if(ep==0) n = EP0_SIZE;
else n = EPX_SIZE;
if (n > len)
n = len;
len -= n;
UDD_Send(ep & 0xF, data, n);
//THIS IS AN ADDITION: UPDATING THE POINTER - WRD
data += n;
}
//TXLED1; // light the TX LED
//TxLEDPulse = TX_RX_LED_PULSE_MS;
return r;
}
The Arduino Due line: SerialUSB.write(test_buf,16384); now appears to actually send all of the 16384 bytes.
And by the way, with 64 * 16K transfers, I am getting around 8Mb per second transfer rates.
Does anybody knows if the bug correction proposed in this thread is included in new releases? I'm checking the USBcore.cpp file from my 1.6.10 installation and i find
int r = len;
const u8* data = (const u8*)d;
u8 timeout = 250;