I'm trying to create a composite USB device with multiple CDCs. To do this, I'm merging in the LPCXPresso54114_dev_composite_cdc_vcom_cdc_vcom_bm example with the LPC54114 usbdrom_cdc example from the Keil Pack Installer. Both work separately.
The USB ROM API from Keil is far easier to work with. But I'm struggling to get it to work in a composite configuration. My software is throwing a ERR_USBD_BAD_INTF_DESC code.
Here's my FS Configuration Descriptor code:
const uint16_t config_desc_data_length=( /* wTotalLength */
(1*USB_CONFIGUARTION_DESC_SIZE )+ /* length of initial descriptor */
(
(1*USB_INTERFACE_ASSOCIATION_DESC_SIZE )+ /* interface association descriptor */
(1*USB_INTERFACE_DESC_SIZE )+ /* communication control interface*/
(0x0013 )+ /* CDC functions */
(1*USB_ENDPOINT_DESC_SIZE )+ /* interrupt endpoint */
(1*USB_INTERFACE_DESC_SIZE )+ /* communication interface */
(2*USB_ENDPOINT_DESC_SIZE )+ /* bulk endpoints */
(0)
) * 2
) ;
/**
* USB FSConfiguration Descriptor
* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor)
*/
ALIGNED(4) uint8_t USB_FsConfigDescriptor[] = {
/* Configuration 1 */
USB_CONFIGUARTION_DESC_SIZE, /* bLength: 9 */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(config_desc_data_length),
0x04, /* bNumInterfaces */
0x01, /* bConfigurationValue: 0x01 is used to select this configuration */
0x00, /* iConfiguration: no string to describe this configuration */
USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */
/*USB_CONFIG_REMOTE_WAKEUP*/,
USB_CONFIG_POWER_MA(100), /* bMaxPower, device power consumption is 100 mA */
/* First Interface Pair */
/* Interface association descriptor IAD */
USB_INTERFACE_ASSOCIATION_DESC_SIZE, /* bLength: 8 */
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_CIF_NUM_1, /* bInterfaceNumber: Number of Interface: 0 */ /* The first interface number associated with this function */
0x02, /* The number of contiguous interfaces associated with this function */
CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass: Communication Interface Class */
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass: Abstract Control Model */
0x00, /* bInterfaceProtocol: no protocol used */
0x04, /* Function string descriptor index */
/* 1st Communications Interface */
/*Interface 0, Alternate Setting 0, CCI Descriptor*/
USB_INTERFACE_DESC_SIZE, /* bLength: 9 */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_CIF_NUM_1, /* 0: interface number */
0x00, /* Alternate Setting */
0x01, /* endpoint count */
CDC_COMMUNICATION_INTERFACE_CLASS, /* CCI class*/
CDC_ABSTRACT_CONTROL_MODEL, /* ACM */
0x00, /* Protocol */
0x04, /* Interface */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size: 5 */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_HEADER, /* bDescriptorSubtype: Header Func Desc */
WBVAL(CDC_V1_10), /* 1.10 */ /* bcdCDC */
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength: 5 */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_CALL_MANAGEMENT, /* bDescriptorSubtype: Call Management Func Desc */
0x01, /* bmCapabilities: device handles call management */
USB_CDC_DIF_NUM_1, /* 1: bDataInterface: CDC data IF ID */
/*Abstract Control Management Functional Descriptor*/
0x04, /* bFunctionLength: 4 */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength: 5 */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_UNION, /* 6: bDescriptorSubtype: Union func desc */
USB_CDC_CIF_NUM_1, /* bMasterInterface: Communication class interface is master */
USB_CDC_DIF_NUM_1, /* bSlaveInterface0: Data class interface is slave 0 */
/*Endpoint 1 Descriptor*/ /* event notification (optional) */
USB_ENDPOINT_DESC_SIZE, /* bLength: 7 */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(1), /* 0x82: bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0010), /* wMaxPacketSize */
0x08, /* 8ms */ /* bInterval */
/* 1st Data Interface */
/* Interface 1, Alternate Setting 0, Data class interface descriptor*/
USB_INTERFACE_DESC_SIZE, /* bLength: 9 */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_DIF_NUM_1, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: no alternate setting */
0x02, /* bNumEndpoints: two endpoints used */
CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass: Data Interface Class */
0x00, /* bInterfaceSubClass: no subclass available */
0x00, /* bInterfaceProtocol: no protocol used */
0x04, /* iInterface: */
/* Endpoint, EP Bulk Out */
USB_ENDPOINT_DESC_SIZE, /* bLength: 7 */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_OUT(3), /* 0x01: bEndpointAddress */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
WBVAL(64), /* wMaxPacketSize */
0x00, /* bInterval: ignore for Bulk transfer */
/* Endpoint, EP Bulk In */
USB_ENDPOINT_DESC_SIZE, /* bLength: 7 */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(3), /* 0x81: bEndpointAddress */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
WBVAL(64), /* wMaxPacketSize */
0x00, /* bInterval: ignore for Bulk transfer */
/* Second Interface Pair */
/* Interface association descriptor IAD */
USB_INTERFACE_ASSOCIATION_DESC_SIZE, /* bLength: 8 */
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE, /* bDescriptorType */
0x02, /* bInterfaceNumber: Number of Interface */
0x02, /* bAlternateSetting: Alternate setting */
CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass: Communication Interface Class */
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass: Abstract Control Model */
0x00, /* bInterfaceProtocol: no protocol used */
0x04, /* iInterface: */
/* 2nd Communications Interface */
/*Interface 2, Alterante Setting 0, CCI Descriptor*/
USB_INTERFACE_DESC_SIZE, /* bLength: 9 */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_CIF_NUM_2, /* 2: interface number */
0x00, /* unknown */
0x01, /* endpoint count */
CDC_COMMUNICATION_INTERFACE_CLASS, /* CCI class*/
CDC_ABSTRACT_CONTROL_MODEL, /* ACM */
0x00, /* Protocol */
0x04, /* Interface */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_HEADER, /* bDescriptorSubtype: Header Func Desc */
WBVAL(CDC_V1_10), /* 1.10 */ /* bcdCDC */
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_CALL_MANAGEMENT, /* bDescriptorSubtype: Call Management Func Desc */
0x01, /* bmCapabilities: device handles call management */
0x01, /* 1: bDataInterface: CDC data IF ID */ /* Indicates multiplexed commands are handled via data interface */
/*Abstract Control Management Functional Descriptor*/
0x04, /* bFunctionLength */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength */
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */
CDC_UNION, /* 6: bDescriptorSubtype: Union func desc */
USB_CDC_CIF_NUM_2, /* 2: bMasterInterface: Communication class interface is master */
USB_CDC_DIF_NUM_2, /* 3: bSlaveInterface0: Data class interface is slave 0 */
/*Endpoint 1 Descriptor*/ /* event notification (optional) */
USB_ENDPOINT_DESC_SIZE, /* bLength: 7 */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(2), /* 0x82: bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0010), /* wMaxPacketSize */
0x08, /* 8ms */ /* bInterval */
/* 2nd Data Interface */
/* Interface 3, Alternate Setting 0, Data class interface descriptor*/
USB_INTERFACE_DESC_SIZE, /* bLength: 9 */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_DIF_NUM_2, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: no alternate setting */
0x02, /* bNumEndpoints: two endpoints used */
CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass: Data Interface Class */
0x00, /* bInterfaceSubClass: no subclass available */
0x00, /* bInterfaceProtocol: no protocol used */
0x04, /* iInterface: */
/* Endpoint, EP Bulk Out */
USB_ENDPOINT_DESC_SIZE, /* bLength: 7 */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_OUT(4), /* 0x04: bEndpointAddress */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
WBVAL(64), /* wMaxPacketSize */
0x00, /* bInterval: ignore for Bulk transfer */
/* Endpoint, EP Bulk In */
USB_ENDPOINT_DESC_SIZE, /* bLength: 7 */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(4), /* 0x84: bEndpointAddress */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
WBVAL(64), /* wMaxPacketSize */
0x00, /* bInterval: ignore for Bulk transfer */
/* Terminator */
0 /* bLength */
};
Anyone see what I'm doing wrong?
Never mind. Found the first bug. Forgot to set the maximum number of endpoints.
ErrorCode_t init_usb()
{
ErrorCode_t ret = LPC_OK;
/* initilize call back structures */
memset((void *) &usbParameters, 0, sizeof(USBD_API_INIT_PARAM_T));
usbParameters.usb_reg_base = USB0_BASE;
usbParameters.max_num_ep = 6; // <-- Formerly 3
usbParameters.high_speed_capable = 0; /* Full speed only. */
usbParameters.mem_base = USB_STACK_MEM_BASE;
usbParameters.mem_size = USB_STACK_MEM_SIZE;
/* Set the USB descriptors */
usbDescriptors.device_desc = (uint8_t *) USB_DeviceDescriptor;
usbDescriptors.string_desc = (uint8_t *) USB_StringDescriptor;
usbDescriptors.high_speed_desc = (uint8_t *) USB_FsConfigDescriptor;
usbDescriptors.full_speed_desc = (uint8_t *) USB_FsConfigDescriptor;
usbDescriptors.device_qualifier = 0;
ret = USBD_API->hw->Init(&g_hUsb, &usbDescriptors, &usbParameters);
return ret;
}
Hopefully I can get the rest to work.
Hi @dean_sands
Technically it's possiable to use USB ROM API to implement USB composite device but we don't have related LPC5411x demo code and there is no plan to update the demo.
For composite USB, our recommendation is MCUXPresso SDK.
There were discussion on version on this topic. FYI:
Have a nice day,
Jun Zhang