Trouble understanding device descriptors for USB LUFA

263 views
Skip to first unread message

p_lin

unread,
Nov 7, 2012, 2:55:09 PM11/7/12
to lufa-s...@googlegroups.com
Hi everyone,

I've been working off of the temperature data logger example. As is, the device shows up both as a mass storage device and generic HID.  I'd like to disable the mass storage device option, but I'm running into a lot of trouble.

So far, I modified descriptors.c and descriptors.h.  by commenting out:

USB_Descriptor_Interface_t            MS_Interface;
USB_Descriptor_Endpoint_t             MS_DataInEndpoint;
USB_Descriptor_Endpoint_t             MS_DataOutEndpoint;

in the struct  USB_Descriptor_Configuration_t;

This doesn't work...what else do I need to modify?

I tried changing ConfigurationDescriptor.Config.TotalInterfaces to 1
and ..HID_Interface.InterfaceNumber to 0

Do I need to change something in the DeviceDescriptor too?  I'm pretty lost here.

thanks for any input!

Dean Camera

unread,
Nov 27, 2012, 4:15:42 AM11/27/12
to LUFA Library Support List
Hi p_lin,

> I tried changing ConfigurationDescriptor.Config.TotalInterfaces to 1
> and ..HID_Interface.InterfaceNumber to 0

That should be just about all you need to do - also ensure that you
remove any code in the main file relating to the mass storage class.
You will also need to ensure that your OS does not cache the old
device and configuration descriptors. Try changing your application's
VID/PID values to force the host to reload its drivers.

Cheers!
- Dean

On Nov 8, 6:55 am, p_lin <anupam.pat...@gmail.com> wrote:
> Hi everyone,
>
> I've been working off of the temperature data logger example. As is, the
> device shows up both as a mass storage device and generic HID.  I'd like to
> disable the mass storage device option, but I'm running into a lot of
> trouble.
>
> So far, I modified descriptors.c<https://code.google.com/p/lufa-lib/source/browse/trunk/Projects/TempD...>and descriptors.h.  by commenting out:

p_lin

unread,
Dec 7, 2012, 12:52:01 PM12/7/12
to lufa-s...@googlegroups.com
Hi Dean,

Changing the VID/PID values worked... But I cannot set any values using the host application. I get an error saying " a device attached to the system is not functioning" when I try to "set values".

I verified that the VID/PID values in the host application work too.

Here is what I updated in my descriptors.h file

/** Endpoint number of the Generic HID reporting IN endpoint. */
#define GENERIC_IN_EPNUM               1

/** Size in bytes of the Generic HID reporting endpoint. */
#define GENERIC_EPSIZE                 16

/** Size in bytes of the Generic HID reports (including report ID byte). */
#define GENERIC_REPORT_SIZE            sizeof(Device_Report_t)

/* Type Defines: */
/** Type define for the device configuration descriptor structure. This must be defined in the
*  application code, as the configuration descriptor contains several sub-descriptors which
*  vary between devices, and which describe the device's usage to the host.
*/
typedef struct
{
USB_Descriptor_Configuration_Header_t Config;
// Mass Storage Interface
//USB_Descriptor_Interface_t            MS_Interface;
//USB_Descriptor_Endpoint_t             MS_DataInEndpoint;
//USB_Descriptor_Endpoint_t             MS_DataOutEndpoint;
// Settings Management Generic HID Interface
USB_Descriptor_Interface_t            HID_Interface;
USB_HID_Descriptor_HID_t              HID_GenericHID;
USB_Descriptor_Endpoint_t             HID_ReportINEndpoint;
} USB_Descriptor_Configuration_t;

/* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
                                   const uint8_t wIndex,
                                   const void** const DescriptorAddress)
                                   ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);

#endif

///////////////////////////////////////////////////////////////////////////////
Here is what I updated in my descriptors.c file

const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Config =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},

.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces        = 1,

.ConfigurationNumber    = 1,
.ConfigurationStrIndex  = NO_DESCRIPTOR,

.ConfigAttributes       = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),

.MaxPowerConsumption    = USB_CONFIG_POWER_MA(100)
},
/*
.MS_Interface =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},

.InterfaceNumber        = 0,
.AlternateSetting       = 0,

.TotalEndpoints         = 2,

.Class                  = MS_CSCP_MassStorageClass,
.SubClass               = MS_CSCP_SCSITransparentSubclass,
.Protocol               = MS_CSCP_BulkOnlyTransportProtocol,

.InterfaceStrIndex      = NO_DESCRIPTOR
},

.MS_DataInEndpoint =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},

.EndpointAddress        = (ENDPOINT_DIR_IN | MASS_STORAGE_IN_EPNUM),
.Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize           = MASS_STORAGE_IO_EPSIZE,
.PollingIntervalMS      = 0x01
},

.MS_DataOutEndpoint =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},

.EndpointAddress        = (ENDPOINT_DIR_OUT | MASS_STORAGE_OUT_EPNUM),
.Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize           = MASS_STORAGE_IO_EPSIZE,
.PollingIntervalMS      = 0x01
},
*/

.HID_Interface =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},

.InterfaceNumber        = 0,
.AlternateSetting       = 0,

.TotalEndpoints         = 1,

.Class                  = HID_CSCP_HIDClass,
.SubClass               = HID_CSCP_NonBootSubclass,
.Protocol               = HID_CSCP_NonBootProtocol,

.InterfaceStrIndex      = NO_DESCRIPTOR
},

.HID_GenericHID =
{
.Header                 = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},

.HIDSpec                = VERSION_BCD(01.11),
.CountryCode            = 0x00,
.TotalReportDescriptors = 1,
.HIDReportType          = HID_DTYPE_Report,
.HIDReportLength        = sizeof(GenericReport)
},

.HID_ReportINEndpoint =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},

.EndpointAddress        = (ENDPOINT_DIR_IN | GENERIC_IN_EPNUM),
.Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize           = GENERIC_EPSIZE,
.PollingIntervalMS      = 0x01
},
};



Any help would be greatly appreciated!

p_lin

unread,
Dec 7, 2012, 12:53:41 PM12/7/12
to lufa-s...@googlegroups.com
Also, my .config  in Descriptors.c

.Config =
{
.Header                 = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},

.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces        = 1,

.ConfigurationNumber    = 1,
.ConfigurationStrIndex  = NO_DESCRIPTOR,

.ConfigAttributes       = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),

.MaxPowerConsumption    = USB_CONFIG_POWER_MA(100)
},

On Tuesday, November 27, 2012 1:15:43 AM UTC-8, Dean Camera wrote:

Dean Camera

unread,
Dec 11, 2012, 8:21:44 PM12/11/12
to lufa-s...@googlegroups.com
p_lin,

Unfortunately nothing stands out to me from your code as being incorrect - although it's hard to tell without seeing the full picture. Can you zip up your complete code and post it here, so I can take a look? It may just be that you haven't removed the mass storage code, or haven't made some adjustments to the HID class instance in the main application.

Cheers!
- Dean
Message has been deleted

Dean Camera

unread,
Dec 16, 2012, 10:55:16 PM12/16/12
to lufa-s...@googlegroups.com
p_lin,

The first thing that comes to mind is that you haven't updated the HID struct in your main application file so that the InterfaceNumber value matches the updated descriptors:

USB_ClassInfo_HID_Device_t Generic_HID_Interface =
{
.Config =
{
.InterfaceNumber              = 1,

.ReportINEndpointNumber       = GENERIC_IN_EPNUM,
.ReportINEndpointSize         = GENERIC_EPSIZE,
.ReportINEndpointDoubleBank   = false,

.PrevReportINBuffer           = PrevHIDReportBuffer,
.PrevReportINBufferSize       = sizeof(PrevHIDReportBuffer),
},
};

The ".InterfaceNumber              = 1," needs to be updated to be ".InterfaceNumber              = 0," so that the HID driver does not reject requests made to the HID interface in your device.

Cheers!
- Dean

On Friday, December 14, 2012 1:59:22 AM UTC+11, p_lin wrote:
Hi Dean,

I've attached the project files here -- basically it is a datalogger, reading from 3 sensors. If the sensor value crosses a threshold, it counts that event in the chip's eeprom.

Thank you SO much for offering to take a look!
Reply all
Reply to author
Forward
0 new messages