USB CDC speed and truncated binary data

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Been thanked: 15 times

USB CDC speed and truncated binary data

Post by piers »

I'm testing the USB serial driver on the STM32F103, which now works fine (after noticing that there is no internal pullup like on the STM32F4). However, I have some issues:

When sending binary data it gets corrupted in some strange way, some byte values are never received, some sometimes.
The uC does nothing but sending bytes 0x00 to 0xff repeatedly. Now when I make a histogram of the received bytes it looks like this:
Image
So bytes 3, 17, 19, 26 and 28 are never received, and other bytes depending on the order.

When sending the bytes in descending order it gives similar results:
Image

Does anyone know what could be the problem? Are some bytes used as control characters or so?
When I'm just sending values from 32 till 127 everything is fine.

Also the speed is quite low, the maximum speed I could get is 85kByte/s, while it should be possible to reach more than 1MByte/s. Is this a limitation of the implementation in ChibiOS?

This is the sending code:

Code: Select all

while (TRUE) {
      for (n=0; n<256; n++) {
        chSequentialStreamWrite((BaseSequentialStream *)&SDU1, &n, 1);
      }
}


I measure the speed with:

Code: Select all

dd if=/dev/ttyACM0 of=rx &pid=$!; sleep 10; kill -USR1 $pid; sleep 1; kill $pid

This gives 85kByte/s when just sending bytes from 32 till 127.

Thanks,
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB CDC speed and truncated binary data

Post by Giovanni »

Hi,

Non-ASCII values should have no effect, this is really odd, nothing in the SW would explain that and I can't think even to a possible HW reason.
Is there a shell using the serial over USB port too? that could somehow make distinctions among characters but still it would be strange.

On the Linux side the communication driver can interpret control characters (^c, ^d, ^h, ^j, ^z and so on), is the port configured in non-cooked binary mode?

About throughput, probably the driver is not fully optimized because double buffering is not yet supported but writing a single byte at time has an overhead, probably you should do large write operations if performance is an issue.

Giovanni
User avatar
piers
Posts: 42
Joined: Fri Apr 06, 2012 1:02 am
Been thanked: 15 times

Re: USB CDC speed and truncated binary data

Post by piers »

Thanks, I wasn't aware that serial ports by default are openened in cooked, or canonical mode, setting the right mode flags with stty fixed it.

Code: Select all

stty -F /dev/ttyACM0 clocal cread


Regarding the speed, sending with larger write operations increased the speed somewhat, by writing chunks of 1024 Bytes the speed goes to 113kB/s.
Over 2Mbaud UART the speeds are similar, so half the theoretical max of 220kB/s.

I guess I can live with that for now, I'll also try it on a STM32F4.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB CDC speed and truncated binary data

Post by Giovanni »

Please let me know how it goes. The new driver should improve performance when the SerialUSB queues sizes are increased, you should be able to trade memory for performance (still untested).

The STM32F1 USB driver will receive a similar enhancement during the weekend.

Giovanni
Post Reply