Page 2 of 2

Posted: Fri Dec 14, 2007 7:48 pm
by kattoaster
but how can i send the couple of bytes to the avr? i'm sorry but i'm a real newbie in avr-usb.

Posted: Fri Dec 14, 2007 7:50 pm
by christian
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.

Posted: Fri Dec 14, 2007 7:54 pm
by kattoaster
thank you

Posted: Fri Dec 14, 2007 9:57 pm
by kattoaster
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;
}

Posted: Fri Dec 14, 2007 10:02 pm
by christian
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().

Posted: Fri Dec 14, 2007 10:13 pm
by Guest
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?

Posted: Fri Dec 14, 2007 10:15 pm
by christian
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.

Posted: Fri Dec 14, 2007 10:41 pm
by kattoaster
thanks a lot for your support

Posted: Mon Dec 17, 2007 1:32 pm
by Guest
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?

Posted: Mon Dec 17, 2007 2:11 pm
by christian
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.

Posted: Mon Dec 29, 2008 8:40 pm
by roger
I'm able to get at least 7230 bytes/s (tested with pyUSB) using usbFunctionRead() and sending 254 bytes at a time.

Posted: Mon Dec 29, 2008 9:24 pm
by christian
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.