endpoint descriptors in flash

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

endpoint descriptors in flash

Post by tommy » Tue Nov 22, 2011 3:52 pm

Hi everyone,

I am using V-USB on ATTiny2313 and want to emulate a USB-Soundcard. For this reseaon I need to provide an in-endpoint 1 with transfer-type bulk. I built my firmware with the V-USB example "Custom Class" and implemened my own configuration descriptor (including a interface descriptor and a endpoint descriptor) in my flash data memory. Archiving the described behavior I set the properties-flags in usbconfig.h:

Code: Select all

#define CONFIGURATION_DESCRIPTOR_SIZE 25
#define USB_CFG_DESCR_PROPS_CONFIGURATION           (USB_PROP_LENGTH(CONFIGURATION_DESCRIPTOR_SIZE))


Further, I defined my descriptors in main.c:

Code: Select all

PROGMEM char usbDescriptorConfiguration[CONFIGURATION_DESCRIPTOR_SIZE] = {

   /* USB configuration descriptor */
    9,          /* length of descriptor in bytes */
    2,         /* descriptor type, 2==ConfigurationDescriptor */
    18,         /* total length of data returned, including inline descriptors byte 1*/
    0,          /* total length of data returned, including inline descriptors byte 2 */
    1,          /* number of interfaces in this configuration */
    1,          /* index of this configuration */
    0,          /* configuration name string index */
    (1 << 7),   /* attributes for device is not self-powered */
    40/2,       /* max USB current in 2mA units */

    /* interface descriptor follows inline: */
    9,         /* length of descriptor in bytes */
    4,          /* descriptor type, 4==InterfaceDescriptor */
    0,         /* index of this interface */
    1,         /* alternate setting for this interface */
    1,          /* endpoints excl 0: number of endpoint descriptors to follow */
    0,          /* Interface class configured at device-descriptor level */
    0,          /* Interface subclass configured at device-descriptor level */
    0,          /* Interface protocol configured at device level */
    0,          /* string index for interface */      /*  ----> maybe belongs to endpoint descriptor  */

    /* endpoint descriptor follows inline: */
    7,          /* length of endpoint descriptor */
    5,        /* descriptor type, 5==EndpointDescriptor */
    (char)0x81, /* IN endpoint number 1 */       
    0x02,       /* attributes for endpoint (bulk-in) */ 
    8,          /* maximum packet size byte 1*/
    0,          /* maximum packet size byte 2*/
    0          /* interrupt poll interval in ms, ingnored on other */
};


So far my "USB-Soundcard" is identified by my linux host PC, kernel module is loaded but the probing fails because, I guess, the USB-Core does not receive my descriptors properly.

dmesg says:

Code: Select all

[686983.913097] usb 3-1.1: new low speed USB device using ohci_hcd and address 47
[686984.018124] usb 3-1.1: config 1 interface 0 altsetting 1 has 0 endpoint descriptors, different from the interface descriptor's value: 1
[686984.018131] usb 3-1.1: config 1 interface 0 has no altsetting 0
[686984.031299] usb 3-1.1: configuration #1 chosen from 1 choice
[686984.059164] snd-usb: probe of 3-1.1:1.0 failed with error -5
[686984.059254] usbcore: registered new interface driver snd-usb-caia


First I thouth about some compiler optimizations of my PROGMEM-array, but now almost every optimization-level is deactivated. Any suggestions about the reason why my endpoint descriptor seems wrong?

Do I count the size of my PROGMEM-array wrong (=25)?

Kind Regards,

Tommy

Tommy

Re: endpoint descriptors in flash

Post by Tommy » Tue Nov 22, 2011 4:10 pm

Solved!

"total length of data returned" in "PROGMEM-array" shoud be 25 instead of 18. :)

tommy

Re: endpoint descriptors in flash

Post by tommy » Tue Nov 22, 2011 4:15 pm

Does anyone know why my USB-Core now says:

dmesg:

Code: Select all

usb 3-1.1.: config 1 interace 0 altsetting 1 endpoint 0x81 is Bulk; changing to Interrupt


Why is it changing my nice bulk-in endpoint to a interrupt endpoint? :D

Kind Regards,

Tommy

Daid
Rank 2
Rank 2
Posts: 55
Joined: Mon Apr 18, 2011 12:19 pm

Re: endpoint descriptors in flash

Post by Daid » Tue Nov 22, 2011 5:45 pm

Because bulk endpoints are not supported by the low-speed spec officially.
Some versions of Linux try to map bulk endpoints to interrupt endpoints on low speed devices and this mapping is broken. You need a kernel patch (included in the newest vanilla kernels >=2.6.23) on these kernels. Windows Vista enforces the standard and you need a driver to map the bulk endpoints to interrupt endpoints. See Osamu Tamura's site for details.
http://vusb.wikidot.com/usb-device-classes

tommy

Re: endpoint descriptors in flash

Post by tommy » Tue Nov 22, 2011 5:51 pm

Thank you very much for your answer!

The following links explain the patch in detail:

viewtopic.php?t=1030
http://www.ulrichradig.de/forum/viewtop ... =34&t=1401

Post Reply