This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB Gadget Serial Data Throughput

Other Parts Discussed in Thread: AM1808

I'm starting this thread to get my arms around USB on a ARM.

I need an interface for driving the AM1808 as a device (not a host).  Simple 4 to 100 byte commands will be sent down to the AM1808 across USB, the ARM will do some stuff, then send a simple response back.  This need to be fast latency.

So, I created a test that sends down 4 bytes, and gets a 2 byte response.  I selected Gadget Serial (set to 115200 baud), since I don't know how to do anything else.  I assume Gadget Ether is about the same speed, and Gadget FS doesn't seem to fit my needs.

I run a 1000 loops of this simple program, and it takes 4.98 seconds????????   Does 5ms a command/response sound reasonable?  What should I do next to speed this up.  I really need like 0.1ms per loop.  Is the baud rate a problem, or g_serial is just slow?

 

CODE: maybe some new USB person will be able to use this to help him not go through all the pain of figuring it out on your own.  It's quite simple, when you have basic examples.  Not much sharing on this site.

 

On the host:

>sudo /sbin/modprobe usbserial vendor=0x0525 product=0xA4A7

Host Program:  (abbreviated)

usbserial_fh = open( "/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY );

fcntl( usbserial_fh, F_SETFL, FNDELAY );

g_returnvalue = write( usbserial_fh, "4Ao\r", 4 ); // SEND

g_returnvalue = read( usbserial_fh, &read_data[rcount], 2 );  // wait for return message, in loop, wait for "OK"


On AM1808:  make sure you've compiled in gadget device side in your kernel.  not there by default.

>modprobe g_serial use_acm=1

AM1808 Program: (abbreviated)

usbserial_fh = open( "/dev/ttyGS0", O_RDWR | O_NOCTTY | O_NDELAY );

fcntl( usbserial_fh, F_SETFL, FNDELAY );

g_returnvalue = read( usbserial_fh, &read_data[rcount], 200 );  // WAIT for message in loop

write( usbserial_fh, "OK", 2 );   // send OK when you see it

 

To Test:   This is handy.

Host: > sudo minicom -D /dev/ttyACM0

AM1808: >cat /dev/ttyGS0

 

  • Patrick,

    g_serial is a simple usb application and I believe would be suitable for the king of message passing app that you are developing.

    The concern I have is that your app seems to need very agressive turnaround (including processing).  I feel a 5ms turnaround is fine (pl. note that your app is operating in user space and hence there is a kernel to user space switch involved).

    W.r.t reducing the turnaround time I would recommend as below

    • Can you try async sequence
      • Tx and Rx are not tied together?
    • Can you queue more messages rather than one ?
    • Is it at all possible for you to move your user level app to kernel space (this would avoid the user-kernel switch at the cost of increased complexity on the app).  This would give you better timings.

    regards

    swami

  • - I realize TX and RX are independent.  Won't help me in this case.

    - Queuing is always possible, but I'm doing a apples to apples comparison of speed, so latency is what we are looking at.

    - Hadn't thought about writing the entire program in kernel space, I wouldn't have thought it would speed it up that much.

    This is kinda strange, I assumed USB was fast, since it's at 480Mbps (I understand there a round robin timeshare and sampling period).  Just as a comparison, I wrote the exact same test using the AM1808's Ethernet, using standard sockets calls, in Linux.  And, was able to get 0.37 milliseconds loopback time.  Seems like inverse orders of magnitude difference.

    Wade

  • Hi

    Since your transfer is through USB you have to find out what resources is given during enumeration of your device. Every device has the ability to tell the host how often it shall be polling the device for data. By looking at the USB descriptors of your device you may find this value. Hope this helps

    Regards

    Øyvind