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