How fast is Software-USB

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
kattoaster

Post by kattoaster » Fri Dec 14, 2007 7:48 pm

but how can i send the couple of bytes to the avr? i'm sorry but i'm a real newbie in avr-usb.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Dec 14, 2007 7:50 pm

Please look at example applications. Automator, for example, sends blocks of 128 bytes to the devices and stores them in the EEPROM. Or, if you take USBasp, Thomas Fischl's AVR programmer, it sends and receives variable sized blocks of data.

kattoaster

Post by kattoaster » Fri Dec 14, 2007 7:54 pm

thank you

kattoaster

Post by kattoaster » Fri Dec 14, 2007 9:57 pm

sorry, but i have one more question:
how many bytes i transfer with:

Code: Select all

unsigned char iodata[8];
if ((result = sendUSBVendorCmdIn( avr_speed, 0, 0, iodata, 1)) < 0)
 {
             printf("Fehler!\r\n");
             return -1;
 }


and how many bytes with:

Code: Select all

unsigned char iodata[8];
if ((result = sendUSBVendorCmdIn( avr_speed, 0, 0, iodata, 2)) < 0)
 {
             printf("Fehler!\r\n");
             return -1;
 }


my initialisation for result is:

Code: Select all

int sendUSBVendorCmdOut(int request, int value, int index, void *replydata, int len)
{
   int result;

   result = usb_control_msg(usbIODevice,                                           // USB Device Pointer
                             USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,  // USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER
                             request,                                              // request see USB documentation
                             value,                                                 // value see USB documentation
                             index,                                                 // index see USB documentation
                             replydata,                                             // buffer for the replay data
                             len,                                                   // len of the replay buffer
                             1000);                                                 // timeout in ms
   return result;
}

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Dec 14, 2007 10:02 pm

If your sendUSBVendorCmdIn() is defined analogous to sendUSBVendorCmdOut(), you receive one byte in the first case and two in the second. Please note that you actually transfer many more bytes, that's the overhead of control transfers.

For efficient transfers, send or receive at least 100 bytes (if possible) in each call to usb_control_msg().

Guest

Post by Guest » Fri Dec 14, 2007 10:13 pm

so if i send to the controller

Code: Select all

if ((result = sendUSBVendorCmdIn( avr_speed, 0, 0, iodata, 100)) < 0) 
 {
             printf("Fehler!\r\n");
             return -1;
 }


with

Code: Select all

unsigned char iodata[100];

i transfer 100 byte? or is this wrong?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Fri Dec 14, 2007 10:15 pm

Since your function name is sendUSBVendorCmdIn(), I guess you transfer 100 bytes from the device to the host. In and Out are defined from the host's point of view.

But you are right, this should transfer 100 bytes unless an error occurs. A possible error would be that the host and the device don't agree on the transfer size.

kattoaster

Post by kattoaster » Fri Dec 14, 2007 10:41 pm

thanks a lot for your support

Guest

Post by Guest » Mon Dec 17, 2007 1:32 pm

christian wrote:When you increase the transfer size, please note that the driver has a limit at 254 bytes.


My question is: would it be theoretically possible to extend the driver for bigger sizes or is this a limit of the USB specs?

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Mon Dec 17, 2007 2:11 pm

This limit is not in the USB spec and it would be possible to extend AVR-USB for bigger message sizes. However, since this requires 16 bit arithmetics, it would bloat the driver size. Another #ifdef would make it harder to maintain.

We have done some transfer speed measurements and found that increasing the message size even further does not improve speed, at least not considerably. A good reason for a 16 bit size would be a USB descriptor (e.g. HID) bigger than 254 bytes, but that was not a problem so far.

roger
Posts: 12
Joined: Sat Dec 20, 2008 5:27 pm

Post by roger » Mon Dec 29, 2008 8:40 pm

I'm able to get at least 7230 bytes/s (tested with pyUSB) using usbFunctionRead() and sending 254 bytes at a time.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Mon Dec 29, 2008 9:24 pm

Adding to my comment from a year ago: An option for 16 bit message size has been added in one of the recent releases. This was necessary to allow descriptors above 254 bytes. You can now experiment with bigger messages sizes, if you like.

Post Reply