• AVR Freaks

Hot!Adding an extra USB interface, 16F1455 family

Author
sjb741
Super Member
  • Total Posts : 858
  • Reward points : 0
  • Joined: 2010/01/25 08:45:39
  • Location: 0
  • Status: offline
2021/03/01 08:50:47 (permalink)
5 (1)

Adding an extra USB interface, 16F1455 family

I'm trying to add a CDC interface to existing HID keyboard project by following these MLA examples
  1. apps\usb\device\cdc_basic
  2. apps\usb\device\composite_hid_msd
Item (1) above has a CDC Interface descriptor and item 2 contains an example for a configuration descriptor with 2 interfaces (HID, MSD).
 
I think the steps are as follows
  1. Add usb_device_cdc.c //In MLA
  2. Change the configuration descriptor - add the CDC interface
  3. Periodically call the CDC usb handler (in addition to the existing call to the HID handler)
When I do this, the device still enumerates as a HID keypad, but no "COM" port is added. Also, the HID keyboard application code ceases to work.
 
Here's the descriptor
const uint8_t configDescriptor1[]=
{
// Configuration Descriptor
    0x09,//sizeof(USB_CFG_DSC), // Size of this descriptor in bytes
    USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type
    DESC_CONFIG_WORD(0x0029 + 1*58), // Total length of data for this cfg
    2, // Number of interfaces in this cfg
    1, // Index value of this configuration
    0, // Configuration string index
    _DEFAULT | _SELF, // Attributes, see usb_device.h
    50, // Max power consumption (2X mA)
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    
//Interface Descriptor [HID]
    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
    BOOT_INTF_SUBCLASS, // Subclass code
    HID_PROTOCOL_KEYBOARD, // Protocol code
    0, // Interface string index

// HID Class-Specific Descriptor at OFFSET = 18)
    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(63), //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(8), //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(8), //size
    0x01, //Interval
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    
//Interface Descriptor [CDC] The CDC interface descriptor has size = 58
    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
    _EP01_IN, //EndpointAddress
    _INTERRUPT, //Attributes
    0x0A,0x00, //size
    0x02, //Interval

// 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
    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
    _EP02_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
    _EP02_IN, //EndpointAddress
    _BULK, //Attributes
    0x40,0x00, //size
    0x00 //Interval

};//configDescriptor1

#1

5 Replies Related Threads

    sjb741
    Super Member
    • Total Posts : 858
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Adding an extra USB interface, 16F1455 family 2021/03/08 09:40:42 (permalink)
    0
    I reverted to example VID/PID because it seems win7 x64 needs signed drivers.
     
    Also made some changes after looking here.
     
    The HID device is now missing, and in its place is a COM port with "This device cannot start. (Code 10)".
     
    usb_config.h now contains updated values
    #define USB_MAX_NUM_INT 2//1 //Set this number to match the maximum interface number used in the descriptors for this firmware project
    #define USB_MAX_EP_NUMBER 3//1 //Set this number to match the maximum endpoint number used in the descriptors for this firmware project

    I copied the CDC "ENDPOINT ALLOCATION" from the cdc_basic demo, then changed the EP number for HID

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

    /* CDC */
    #define CDC_COMM_INTF_ID        0x0
    #define CDC_COMM_EP              1
    #define CDC_COMM_IN_EP_SIZE      10

    #define CDC_DATA_INTF_ID        0x01
    #define CDC_DATA_EP             2
    #define CDC_DATA_OUT_EP_SIZE    64
    #define CDC_DATA_IN_EP_SIZE     64

    //#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 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


    /* HID */
    #define HID_INTF_ID             0x00
    #define HID_EP                       3
    #define HID_INT_OUT_EP_SIZE     1
    #define HID_INT_IN_EP_SIZE      8
    #define HID_NUM_OF_DSC          1
    #define HID_RPT01_SIZE          63
    //#define USER_GET_REPORT_HANDLER USBHIDCBGetReportHandler    
    #define USER_SET_REPORT_HANDLER USBHIDCBSetReportHandler    
    #define USB_DEVICE_HID_IDLE_RATE_CALLBACK(reportID, newIdleRate)    USBHIDCBSetIdleRateHandler(reportID, newIdleRate)

     
    #2
    RISC
    Super Member
    • Total Posts : 6056
    • Reward points : 0
    • Status: offline
    Re: Adding an extra USB interface, 16F1455 family 2021/03/08 16:06:24 (permalink)
    0
    Hi,
    Are you trying to develop a "composite" device ?
    I mean both HID and CDC ?
    Regards

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #3
    sjb741
    Super Member
    • Total Posts : 858
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Adding an extra USB interface, 16F1455 family 2021/03/09 03:23:11 (permalink)
    0
    Hi
     
    Yes, exactly that.
     
    At present it seems the HID shows for a while then vanishes. HID works alone, so it looks like the CDC part is breaking both.
     
    I am considering adding status LEDs to see where the code gets to because halting in the debugger can cause disconnection also.
     
    I really need to put together a complete list of constants which need changing - like max endpoint count - when a new interface is added.
     
    Another thing is the MLA code has commented-out "sizeof" statements in usb_descriptors.c. I am unsure why, for instance
        /* Endpoint Descriptor */
        //sizeof(USB_EP_DSC),DSC_EP,_EP02_IN,_INT,CDC_INT_EP_SIZE,0x02,
        0x07,/*sizeof(USB_EP_DSC)*/


    #4
    Jerry Messina
    Super Member
    • Total Posts : 701
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: Adding an extra USB interface, 16F1455 family 2021/03/09 20:22:37 (permalink)
    +1 (1)
    sjb741
     I am considering adding status LEDs to see where the code gets to because halting in the debugger can cause disconnection also. 

    See if there's a "freeze peripherals" option in the debugger settings, and unchecked it.
    That will let the USB engine continue to run when halted and it shouldn't drop off.
    #5
    sjb741
    Super Member
    • Total Posts : 858
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Adding an extra USB interface, 16F1455 family 2021/03/10 02:20:58 (permalink)
    0
    That does sound like a good idea Smile: Smile
    #6
    Jump to:
    © 2021 APG vNext Commercial Version 4.5