Pages: [1]   Go Down
Author Topic: Problem with SerialUSB.write on the Due  (Read 1920 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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")smiley-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.
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
https://github.com/arduino/Arduino/tree/ide-1.5.x

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
Logged

C.

Pages: [1]   Go Up
Jump to: