chipKIT® Development Platform

Inspired by Arduino™

Fubarino SD USB Serial.write transfer rate

Created Tue, 30 Jun 2015 07:33:19 +0000 by MpaoDG


MpaoDG

Tue, 30 Jun 2015 07:33:19 +0000

HI, I'm developing a simple ccd vision system and I need to rapidly transfer about 17Mb of data ( 2574 x 6896 bytes with pixel values ) from the Fubarino SD to a VB PC application.

I get an acceptable transfer rate interfacing the Fubarino SD board to a FTDI FT2232H reading pixel values from a PORT and writing them to the FTDI chip in FIFO mode. In this configuration the VB.NET application reads buffers ranging from a few hundred to a few thousand of bytes, as from the log file : .... 18:40:08.657 ImageArray Get buffer length :420 18:40:08.659 ImageArray Get buffer length :1012 18:40:08.662 ImageArray Get buffer length :1206 18:40:08.663 ImageArray Get buffer length :208 18:40:08.670 ImageArray Get buffer length :2952 18:40:08.671 ImageArray Get buffer length :1036 18:40:08.672 ImageArray Get buffer length :106 18:40:08.672 ImageArray Get buffer length :308 ....

To reduce components count, I tried to do the same with the embedded USB port in the Fubarino SD board. After opening the port with Serial.begin(), I send data with this code :

for (nlinee=0; nlinee < 2574; nlinee++) {
Serial.write(valCol,6896);
}

where valCol is a byte array of 6896 values.

Log file now gives : .... 07:49:35.178 ImageArray Get buffer length :63 07:49:35.178 ImageArray Get buffer length :63 07:49:35.179 ImageArray Get buffer length :29 07:49:35.179 ImageArray Get buffer length :63 07:49:35.179 ImageArray Get buffer length :63 07:49:35.179 ImageArray Get buffer length :63 07:49:35.180 ImageArray Get buffer length :126 07:49:35.180 ImageArray Get buffer length :63 07:49:35.180 ImageArray Get buffer length :126 07:49:35.181 ImageArray Get buffer length :63 07:49:35.181 ImageArray Get buffer length :63 ....

and the transfer rate is of course not acceptable.

I tried to feed serial.write with bytes, bytes arrays, strings, but there are just minor changes in the transfer behavior. The received buffer length remains of 63 bytes, with few longer buffers of 632 or 633 bytes.

As far as I know, the PIC32MX795F512H in Fubarino SD 1.5 has a full speed USB port and I hope there is a way to improve the transfer speed, either using serial.write or bypassing it. Any hint ?

The environment is: Windows 7 Home Premium SP1 MPIDE : 0023 - windows - 20140821 Driver : Stk500v2 - 31/3/2013 - vers. 1.1.0.0. Schmalz Haus VB - Visual Studio Community 2013

Thanks ! Marco


EmbeddedMan

Tue, 07 Jul 2015 18:45:33 +0000

Marco,

I'll bet you can do much faster than that. I think the trick is in how you read out the data from the USB buffer on the PC side. How often are you calling Read() in your PC code?

*Brian


GrahamM242

Wed, 08 Jul 2015 11:19:20 +0000

It'll be interesting to see what kind of tricks can be used to improve speed, as I'm looking at doing something similar. Sadly I don't know enough about how USB works (yet) to know how much tuning can be done on the host or device end.


EmbeddedMan

Wed, 08 Jul 2015 14:29:16 +0000

Here's some good information : [url]https://www.pjrc.com/teensy/benchmark_usb_serial_receive.html[/url]

*Brian


MpaoDG

Thu, 09 Jul 2015 11:18:09 +0000

Brian,

on the PC side there is a loop that will read from the serial port until the number of received bytes (S_Inc) is equal to the pixel number of the image (S_Len). The incoming buffer is appended to a StringBuilder object (SB) that manipulates strings very fast. This is the code :

SB.Clear()
            Do                                     
                Incoming = objSerial.Receive()                         
                Lbytes = Incoming.Length                          
                SB.Append(Incoming)                            
                S_Inc = S_Inc + Lbytes                   
            Loop Until S_Inc &gt;= S_Len

However in the meantime, I've done some similar tests with the Teensy 3.1 board, using the same acquisition software. In this case, on the PC side, length of the input buffer is consistently ot 4096 bytes per read and transfer time is accordingly much shorter :

10:43:54.905 ImageArray Get buffer length :4096 10:43:54.905 ImageArray Get buffer length :4096 10:43:54.920 ImageArray Get buffer length :4096 10:43:54.920 ImageArray Get buffer length :4096 10:43:54.920 ImageArray Get buffer length :4096 10:43:54.920 ImageArray Get buffer length :4096 10:43:54.936 ImageArray Get buffer length :4096 10:43:54.936 ImageArray Get buffer length :4096 10:43:54.936 ImageArray Get buffer length :4096 10:43:54.936 ImageArray Get buffer length :4096 10:43:54.951 ImageArray Get buffer length :4096 10:43:54.951 ImageArray Get buffer length :4096 10:43:54.951 ImageArray Get buffer length :4096

Marco