Maximizing USB bulk transfer throughput
I'm just getting started with USB programming using the recently released Microchip library on the chipKIT board with the network shield. I've tried to learn as much as I can about proper USB programming and it's been good for the most part - however, I'm stuck at a ~75KB/s bulk transfer speed. I apologize for the cross-post on the chipKIT forums if you read both - I'm thinking there is a wider audience here, and I think this question has more to do with the Microchip library.
Some quick background - I need to create a simple USB device that spits on discrete messages to the host PC as fast as possible. The current strategy is to use minified JSON delimited by newlines sent via a bulk transfer endpoint. (of course this could be made faster using plain binary, but this will do for now).
I've trimmed down the GenericUSB example to test the maximum transfer rate, and created a Python receiver (wrapping libusb) for the host. The code is posted here if someone with more experience has a minute to take a look:
< Argh, I can't post URLs to the forum. The code is available at https://github.com/openxc...-transfer-benchmarking
On the chipKIT side, the main loop is pretty simple and is basically this:
// using our own loop seems faster than using the arduino's
handleInput = usb.GenWrite(DATA_ENDPOINT, messageBuffer, messageSize);
In Python it's a similar thing, a look that requests a read of some size until it hits 10MB transferred. This is the actual read function that gets called:
return self.device.read(self.endpoint, self.message_size)
If you download the benchmarkUSB.pde sketch to the chipKIT, then run "python receiver.py" it will read 10MB from the device with various "read request" sizes ranging from 64 bytes (one packet) to 1KB.
It's my understanding that requesting more data from the host at a time will increase throughput as messaging overhead drops - for some reason, this isn't the case for my code. You'll see as the request size increases the throughput actually drops from 75KB/s to even lower numbers.
Any help would be greatly appreciated, as I'm stumped at this point. I don't think the problem is in the Python code, because I've also tried this benchmark from Java (on Android) and had similar results. That code is also in the Github repository - like the Python it's a pretty simple benchmark, it just does a bulk read of a certain size until it hits 10MB.
(Another thing I've noticed is that the
#define USB_SPEED_OPTION USB_FULL_SPEED
line in usb_config.h seems to have no effect. Whether I define low or full speed, the throughput is the same measly 75KB/s.)
post edited by peplin - 2011/10/26 07:27:12