Problem with SerialUSB.write on the Due

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"):wink:
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.

Could someone let me know where the Arduino bug list is so that this issue (SerialUSB.write on Due) can be collected into the next revision?

Also, in CDC.cpp there are a number of locations in which SERIAL_BUFFER_SIZE should be replaced by CDC_SERIAL_BUFFER_SIZE.

Thanks in advance.

Verified the Serial communication from Native port with the changes to USBCore posted here by dreschel :

  • my 4096 byte long send package started working OK after making the changes proposed by dreschel !
  • earlier only 512 bytes came through and of course thought I had problem in my own code , but it was actually in USBcore

with this experience I recommend also making changes to next Arduino Due program release and of course the earlier change concerning
Native port BsOD,

BR and thanks to dreschel,

Seppo

dreschel,

Thanks for catching this one!

The best way to include the fix upstream is making a pull request with the patched USBCore.cpp on the ide_1.5.x branch:

if you can include also the CDC/SERIAL_BUFFER_SIZE fix it would be great.

If you don't have the time to fill a pull request, just send me a patch and I'll take care of it.

C

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;

It seems that it is unaltered.

I will investigate a bit more.

The type change is unnecessary.
The crucial change is

data += n;

which is there: github.com/arduino/ArduinoCore-sam/.../USBCore.cpp#L204