• AVR Freaks

Helpful ReplyProblem with CDC (with IAD) + HID composite device ?

Page: < 12 Showing page 2 of 2
Author
tonyb61
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2010/08/26 04:16:23
  • Location: 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/03/03 02:27:12 (permalink)
0
FluxCapacitor

No prob Tony. Glad it helped. I have joined two different bit of code together, the HID Joystick and CDC Serial Emulator examples. The other thing you might want to try is my USB config and descriptor files in case there is some very hard to see bug in your version. If you want those let me know.


If you could post these I would like to try them out. It must be something wrong in mine as we use the same usb stack otherwise ? I have tried out both the cdc serial emulator, and the composite msd+cdc and these work fine as well.
Thanks
Tony

#21
FluxCapacitor
New Member
  • Total Posts : 12
  • Reward points : 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/03/03 03:22:18 (permalink) ☄ Helpfulby smercurio 2016/02/25 13:44:35
0
Remember that these join the HID joystick and CDC Virtual Serial examples. I also made some mods to the standard HID report for simplicity of my testing.

Descriptor:

   
/** INCLUDES *******************************************************/
#include "usb.h"
#include "usb_function_hid.h"
#include "usb_function_cdc.h"

/** CONSTANTS ******************************************************/
#if defined(__18CXX)
#pragma romdata
#endif

/* Device Descriptor */
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
    0x12,    // Size of this descriptor in bytes
    USB_DESCRIPTOR_DEVICE,                // DEVICE descriptor type
    0x0200,                 // USB Spec Release Number in BCD format
    0xEF,                   // Class Code
    0x02,                   // Subclass code
    0x01,                   // Protocol code
    USB_EP0_BUFF_SIZE,      // Max packet size for EP0, see usb_config.h
    MY_VID,                 // Vendor ID, see usb_config.h
    MY_PID,                 // Product ID, see usb_config.h
    0x0001,                 // Device release number in BCD format
    0x01,                   // Manufacturer string index
    0x02,                   // Product string index
    0x00,                   // Device serial number string index
    0x01                    // Number of possible configurations
};

/* Configuration 1 Descriptor */
ROM BYTE configDescriptor1[]={
    /* Configuration Descriptor */
    0x09,//sizeof(USB_CFG_DSC),            // Size of this descriptor in bytes
    USB_DESCRIPTOR_CONFIGURATION,       // CONFIGURATION descriptor type
    DESC_CONFIG_WORD(0x006B),           // Total length of data for this cfg
    3,                                  // Number of interfaces in this cfg
    1,                                  // Index value of this configuration
    0,                                  // Configuration string index
    _DEFAULT | _SELF,                   // Attributes, see usb_device.h
    250,                                 // Max power consumption (2X mA)

    /* Interface Descriptor */
    0x09,//sizeof(USB_INTF_DSC),           // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,           // INTERFACE descriptor type
    0,                                  // Interface Number
    0,                                  // Alternate Setting Number
    2,                                  // Number of endpoints in this intf
    HID_INTF,                           // Class code
    0,                                    // Subclass code
    0,                                     // Protocol code
    0,                                  // Interface string index

    /* HID Class-Specific Descriptor */
    0x09,//sizeof(USB_HID_DSC)+3,    // Size of this descriptor in bytes RRoj hack
    DSC_HID,                            // HID descriptor type
    DESC_CONFIG_WORD(0x0111),           // HID Spec Release Number in BCD format (1.11)
    0x00,                               // Country Code (0x00 for Not supported)
    HID_NUM_OF_DSC,                     // Number of class descriptors, see usbcfg.h
    DSC_RPT,                            // Report descriptor type
    DESC_CONFIG_WORD(HID_RPT01_SIZE),   //sizeof(hid_rpt01),      // Size of the report descriptor
   
    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,                //Endpoint Descriptor
    HID_EP | _EP_IN,                        //EndpointAddress
    _INTERRUPT,                               //Attributes
    DESC_CONFIG_WORD(HID_INT_IN_EP_SIZE),   //size
    0x01,                                    //Interval

    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,                //Endpoint Descriptor
    HID_EP | _EP_OUT,                        //EndpointAddress
    _INTERRUPT,                              //Attributes
    DESC_CONFIG_WORD(HID_INT_OUT_EP_SIZE),  //size
    0x01,                                    //Interval

   

    /* Interface Association Descriptor */
    0x08, //sizeof(USB_IAD_DSC), // Size of this descriptor in byte
    0x0B, // Interface assocication descriptor type
    1, // The first associated interface
    2, // Number of contiguous associated interface
    COMM_INTF, // bInterfaceClass of the first interface
    ABSTRACT_CONTROL_MODEL, // bInterfaceSubclass of the first interface
    V25TER, // bInterfaceProtocol of the first interface
    0, // Interface string index

    /* Interface Descriptor */
    9,//sizeof(USB_INTF_DSC),   // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,               // INTERFACE descriptor type
    1,                      // Interface Number
    0,                      // Alternate Setting Number
    1,                      // Number of endpoints in this intf
    COMM_INTF,              // Class code
    ABSTRACT_CONTROL_MODEL, // Subclass code
    V25TER,                 // Protocol code
    0,                      // Interface string index

    /* CDC Class-Specific Descriptors */
    sizeof(USB_CDC_HEADER_FN_DSC),
    CS_INTERFACE,
    DSC_FN_HEADER,
    0x10,0x01,

    sizeof(USB_CDC_ACM_FN_DSC),
    CS_INTERFACE,
    DSC_FN_ACM,
    USB_CDC_ACM_FN_DSC_VAL,

    sizeof(USB_CDC_UNION_FN_DSC),
    CS_INTERFACE,
    DSC_FN_UNION,
    CDC_COMM_INTF_ID,
    CDC_DATA_INTF_ID,

    sizeof(USB_CDC_CALL_MGT_FN_DSC),
    CS_INTERFACE,
    DSC_FN_CALL_MGT,
    0x00,
    CDC_DATA_INTF_ID,

    /* Endpoint Descriptor */
    //sizeof(USB_EP_DSC),DSC_EP,_EP02_IN,_INT,CDC_INT_EP_SIZE,0x02,
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
    _EP02_IN,            //EndpointAddress
    _INTERRUPT,                       //Attributes
    0x08,0x00,                  //size
    0x02,                       //Interval   

    /* Interface Descriptor */
    9,//sizeof(USB_INTF_DSC),   // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,               // INTERFACE descriptor type
    2,                      // Interface Number
    0,                      // Alternate Setting Number
    2,                      // Number of endpoints in this intf
    DATA_INTF,              // Class code
    0,                      // Subclass code
    NO_PROTOCOL,            // Protocol code
    0,                      // Interface string index
   
    /* Endpoint Descriptor */
    //sizeof(USB_EP_DSC),DSC_EP,_EP03_OUT,_BULK,CDC_BULK_OUT_EP_SIZE,0x00,
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
    _EP03_OUT,            //EndpointAddress
    _BULK,                       //Attributes
    0x40,0x00,                  //size
    0x00,                       //Interval

    /* Endpoint Descriptor */
    //sizeof(USB_EP_DSC),DSC_EP,_EP03_IN,_BULK,CDC_BULK_IN_EP_SIZE,0x00
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
    _EP03_IN,            //EndpointAddress
    _BULK,                       //Attributes
    0x40,0x00,                  //size
    0x00,                       //Interval
};


//Language code string descriptor
ROM struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={
sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409
}};

//Manufacturer string descriptor
ROM struct{BYTE bLength;BYTE bDscType;WORD string[30];}sd001={
sizeof(sd001),USB_DESCRIPTOR_STRING,
{'','','','','','',' ','','','','','','','','','','','',
'','','','','','','','','','','',''
}};

//Product string descriptor
ROM struct{BYTE bLength;BYTE bDscType;WORD string[14];}sd002={
sizeof(sd002),USB_DESCRIPTOR_STRING,
{'','','','','','','','','','','','','',''
}};

//Array of configuration descriptors
ROM BYTE *ROM USB_CD_Ptr[]=
{
    (ROM BYTE *ROM)&configDescriptor1
};

//Array of string descriptors
ROM BYTE *ROM USB_SD_Ptr[]=
{
    (ROM BYTE *ROM)&sd000,
    (ROM BYTE *ROM)&sd001,
    (ROM BYTE *ROM)&sd002
};

ROM struct{BYTE report[HID_RPT01_SIZE];}hid_rpt01={{
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x05,                    // USAGE (Game Pad)
    0xa1, 0x01,                    //   COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x35, 0x00,                    //   PHYSICAL_MINIMUM (0)
    0x45, 0x01,                    //   PHYSICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x10,                    //   REPORT_COUNT (16)
    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)
    0x29, 0x10,                    //   USAGE_MAXIMUM (Button 16)
    0x05, 0x09,                    //   USAGE_PAGE (Button)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)

    0x95, 0x10,                    //   REPORT_COUNT (16)
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
    0x29, 0x10,                    //   USAGE_MAXIMUM (Repeat)
    0x05, 0x08,                    //   USAGE_PAGE (Bits In)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)

    0xc0                           //               END_COLLECTION
}
};

/** EOF usb_descriptors.c ***************************************************/



Config:

   
/*********************************************************************
 * Descriptor specific type definitions are defined in: usbd.h
 ********************************************************************/

#ifndef USBCFG_H
#define USBCFG_H

/** DEFINITIONS ****************************************************/
#define USB_EP0_BUFF_SIZE        64    // Valid Options: 8, 16, 32, or 64 bytes.
                                // Using larger options take more SRAM, but
                                // does not provide much advantage in most types
                                // of applications.  Exceptions to this, are applications
                                // that use EP0 IN or OUT for sending large amounts of
                                // application related data.
                                   
#define USB_MAX_NUM_INT         1   // For tracking Alternate Setting
#define USB_MAX_EP_NUMBER        5

//Device descriptor - if these two definitions are not defined then
//  a ROM USB_DEVICE_DESCRIPTOR variable by the exact name of device_dsc
//  must exist.
#define USB_USER_DEVICE_DESCRIPTOR &device_dsc
#define USB_USER_DEVICE_DESCRIPTOR_INCLUDE extern ROM USB_DEVICE_DESCRIPTOR device_dsc

//Configuration descriptors - if these two definitions do not exist then
//  a ROM BYTE *ROM variable named exactly USB_CD_Ptr[] must exist.
#define USB_USER_CONFIG_DESCRIPTOR USB_CD_Ptr
#define USB_USER_CONFIG_DESCRIPTOR_INCLUDE extern ROM BYTE *ROM USB_CD_Ptr[]

#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG
//#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY
//#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0        //NOTE: This mode is not supported in PIC18F4550 family rev A3 devices

#define USB_INTERRUPT
#define USB_POLLING
#define USB_PULLUP_OPTION USB_PULLUP_ENABLE
#define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER
#define USB_SPEED_OPTION USB_FULL_SPEED

//------------------------------------------------------------------------------------------------------------------
//Option to enable auto-arming of the status stage of control transfers, if no
//"progress" has been made for the USB_STATUS_STAGE_TIMEOUT value.
//If progress is made (any successful transactions completing on EP0 IN or OUT)
//the timeout counter gets reset to the USB_STATUS_STAGE_TIMEOUT value.
//
//During normal control transfer processing, the USB stack or the application
//firmware will call USBCtrlEPAllowStatusStage() as soon as the firmware is finished
//processing the control transfer.  Therefore, the status stage completes as
//quickly as is physically possible.  The USB_ENABLE_STATUS_STAGE_TIMEOUTS
//feature, and the USB_STATUS_STAGE_TIMEOUT value are only relevant, when:
//1.  The application uses the USBDeferStatusStage() API function, but never calls
//      USBCtrlEPAllowStatusStage().  Or:
//2.  The application uses host to device (OUT) control transfers with data stage,
//      and some abnormal error occurs, where the host might try to abort the control
//      transfer, before it has sent all of the data it claimed it was going to send.
//
//If the application firmware never uses the USBDeferStatusStage() API function,
//and it never uses host to device control transfers with data stage, then
//it is not required to enable the USB_ENABLE_STATUS_STAGE_TIMEOUTS feature.

#define USB_ENABLE_STATUS_STAGE_TIMEOUTS    //Comment this out to disable this feature. 

//Section 9.2.6 of the USB 2.0 specifications indicate that:
//1.  Control transfers with no data stage: Status stage must complete within
//      50ms of the start of the control transfer.
//2.  Control transfers with (IN) data stage: Status stage must complete within
//      50ms of sending the last IN data packet in fullfilment of the data stage.
//3.  Control transfers with (OUT) data stage: No specific status stage timing
//      requirement.  However, the total time of the entire control transfer (ex:
//      including the OUT data stage and IN status stage) must not exceed 5 seconds.
//
//Therefore, if the USB_ENABLE_STATUS_STAGE_TIMEOUTS feature is used, it is suggested
//to set the USB_STATUS_STAGE_TIMEOUT value to timeout in less than 50ms.  If the
//USB_ENABLE_STATUS_STAGE_TIMEOUTS feature is not enabled, then the USB_STATUS_STAGE_TIMEOUT
//parameter is not relevant.

#define USB_STATUS_STAGE_TIMEOUT     (BYTE)45   //Approximate timeout in milliseconds, except when
                                                //USB_POLLING mode is used, and USBDeviceTasks() is called at < 1kHz
                                                //In this special case, the timeout becomes approximately:
//Timeout(in milliseconds) = ((1000 * (USB_STATUS_STAGE_TIMEOUT - 1)) / (USBDeviceTasks() polling frequency in Hz))
//------------------------------------------------------------------------------------------------------------------

#define USB_SUPPORT_DEVICE
#define USB_NUM_STRING_DESCRIPTORS 3
#define USB_ENABLE_ALL_HANDLERS


/** DEVICE CLASS USAGE *********************************************/
#define USB_USE_CDC
#define USB_USE_HID


/** ENDPOINTS ALLOCATION *******************************************/

/* HID */
#define HID_INTF_ID             0x00
#define HID_EP                     1
#define HID_INT_OUT_EP_SIZE     8
#define HID_INT_IN_EP_SIZE      8
#define HID_NUM_OF_DSC          1
#define HID_RPT01_SIZE          37


/* CDC */
#define CDC_COMM_INTF_ID        0x01
#define CDC_COMM_EP              2
#define CDC_COMM_IN_EP_SIZE      8

#define CDC_DATA_INTF_ID        0x02
#define CDC_DATA_EP             3
#define CDC_DATA_OUT_EP_SIZE    64
#define CDC_DATA_IN_EP_SIZE     64

#define USB_CDC_SET_LINE_CODING_HANDLER mySetLineCodingHandler
#define USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL

//#define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D2 //Send_Break command
#define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1 //Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and Serial_State commands

#define MY_VID 0x04D8
#define MY_PID 0x0002

#endif //USBCFG_H

post edited by FluxCapacitor - 2011/03/03 07:09:54
#22
tonyb61
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2010/08/26 04:16:23
  • Location: 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/03/03 05:35:03 (permalink)
0
Thanks. I did try your versions out, but they did not fix my problem either so I came to the conclusion it must be my main.c. So I went through every line compared to the msd+cdc example, and found I had missed one line out that initialized the cdc endpoints, doh ! Annoying !!
So now everything is working as expected, so I can actually get on now with my code now !
Thanks again for your help
Tony
#23
telet
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2011/10/18 07:25:47
  • Location: 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/11/09 08:14:14 (permalink)
0
  Hello guys, I'm new using microchip usb devices. I started to work with cdc and hid devices. Both are working separately. When I want to make a composite device with hid and cdc, I can see the cdc and hid interface with usblyzer but only the hid interface seems to work. Probably there's something wrong in my configuration files but I can't see what exactly. I'll post both files usb_descriptors.c and usb_config.h. Can someone help me and see which settings are wrong? A good manual of microchip usb library should also help but unfortunately there no good pdf on the web. Thanks.
#24
FluxCapacitor
New Member
  • Total Posts : 12
  • Reward points : 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/11/09 15:38:02 (permalink)
0
telet

  Hello guys, I'm new using microchip usb devices. I started to work with cdc and hid devices. Both are working separately. When I want to make a composite device with hid and cdc, I can see the cdc and hid interface with usblyzer but only the hid interface seems to work. Probably there's something wrong in my configuration files but I can't see what exactly. I'll post both files usb_descriptors.c and usb_config.h. Can someone help me and see which settings are wrong? A good manual of microchip usb library should also help but unfortunately there no good pdf on the web. Thanks.



Hi Telet,


Before we dive into the details of your files. Have you compared the example code in this thread with your own? Did you apply the memory allocation fix for composite mode as I posted?

Cheers.
#25
telet
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2011/10/18 07:25:47
  • Location: 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/11/10 03:03:19 (permalink)
0
  Hello FluxCapacitor, Yes, I did read a lot of other posts. Trying to reallocate the memory give me the same problem. When I connect to the uart, usblyzer gives me a result but not that one I'm sending. Only a few unknown characters. The HID interface is working all the time even if I reallocate the hid memory. Currently I'm using the pic18F46J50. I already spend 3 days of trying to fix this problem but without result. A good working complete example would help. Thanks.
#26
FluxCapacitor
New Member
  • Total Posts : 12
  • Reward points : 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/11/10 06:42:41 (permalink)
0
telet

  Hello FluxCapacitor, Yes, I did read a lot of other posts. Trying to reallocate the memory give me the same problem. When I connect to the uart, usblyzer gives me a result but not that one I'm sending. Only a few unknown characters. The HID interface is working all the time even if I reallocate the hid memory. Currently I'm using the pic18F46J50. I already spend 3 days of trying to fix this problem but without result. A good working complete example would help. Thanks.



Hi Telet,


I noticed quite a few things with your files. Firstly some of your settings in the config were a little different to mine. That might be fine as you are using a different chip, but if you have issues take a look at these and compare. Also, while not a technical requirement, may I suggest that you lay out your code in a logical order for extra clarity eg, listing your endpoints in the config in numerical order, just makes it easier to follow. This thread has lots of working code sample in it to compare against and I would recommend a tool like WinMerge to check your files against any examples.


I only had a quick glance over the files but the biggest thing I noticed was that the interface association descriptor for the CDC interfaces was missing in your descriptor. Below is a code snippet that is missing, please see my thread examples above for its placement.


/* Interface Association Descriptor */
0x08, //sizeof(USB_IAD_DSC), // Size of this descriptor in byte
0x0B, // Interface assocication descriptor type
1, // The first associated interface
2, // Number of contiguous associated interface
COMM_INTF, // bInterfaceClass of the first interface
ABSTRACT_CONTROL_MODEL, // bInterfaceSubclass of the first interface
 V25TER, // bInterfaceProtocol of the first interface
0, // Interface string index




post edited by FluxCapacitor - 2011/11/10 07:00:27
#27
telet
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2011/10/18 07:25:47
  • Location: 0
  • Status: offline
Re:Problem with CDC (with IAD) + HID composite device ? 2011/11/18 08:02:24 (permalink)
0
  Hello FluxCapacitor, thanks for all your info. I found quick a lot of errors in my software. Implementing the IAD is indeed mandatory. In my apllication the HID interface is first described, then the CDC. That's not the problem but the USB_MAX_EP_NUMBER has to be 3. Also the end point addresses where the same for HID as for CDC.
#28
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5