I'm trying to create a composite USB device with 3 CDC VCOMs. The code is hard-faulting when the USB IRQ Handler goes to the ISR. Everything looks good when bringing up the USB configuration with the USB ROM.
/******************************************/
/* Function Name: usb_cdc_connect */
/* Return Type: ErrorCode_t */
/* gets the parameters, creates the */
/* handles, registers the endpoints IRQs, */
/* and connects to the USB */
/******************************************/
ErrorCode_t usb_cdc_connect() {
USBD_CDC_INIT_PARAM_T cdcParameters[3];
ErrorCode_t ret = LPC_OK;
uint32_t endpointIndex;
uint32_t usb_block;
uint8_t *ptr;
char result;
//Set Params
memset((void *) &cdcParameters, 0, 2 * sizeof(USBD_CDC_INIT_PARAM_T));
usb_block = usbParameters.mem_size / 4;
ptr = usbDescriptors.high_speed_desc;
cdcParameters[0].mem_base = usbParameters.mem_base;
cdcParameters[0].mem_size = usb_block;
cdcParameters[0].cif_intf_desc = ptr = (uint8_t *) findInterfaceDescriptor(ptr, CDC_COMMUNICATION_INTERFACE_CLASS);
cdcParameters[0].dif_intf_desc = ptr = (uint8_t *) findInterfaceDescriptor(ptr, CDC_DATA_INTERFACE_CLASS);
ret = USBD_API->cdc->init(g_hUsb, &cdcParameters[0], &g_hCDC[0]);
PRINTF("Initializing first CDC...");
result = (LPC_OK == ret);
PRINTF(result ? "Successful\r\n" : "Failure\r\n");
PRINTF("Return value: 0x%08X\r\n", ret);
if (ret == LPC_OK) {
endpointIndex = ((USB_CDC_IN_EP_0 & 0x0F) << 1) + 1;
ret = USBD_API->core->RegisterEpHandler(g_hUsb, endpointIndex, bulkInHandler, &USB_CDC_Ctx[0]);
if (ret == LPC_OK) {
endpointIndex = ((USB_CDC_OUT_EP_0 & 0x0F) << 1);
ret = USBD_API->core->RegisterEpHandler(g_hUsb, endpointIndex, bulkOutHandler, &USB_CDC_Ctx[0]);
}
}
USB_CDC_Ctx[0].cdc = g_hCDC[0];
USB_CDC_Ctx[0].in_endpoint = USB_CDC_IN_EP_0;
USB_CDC_Ctx[0].out_endpoint = USB_CDC_OUT_EP_0;
/* ############################################################################################## */
cdcParameters[1].mem_base = usbParameters.mem_base + usb_block;
cdcParameters[1].mem_size = usb_block;
cdcParameters[1].cif_intf_desc = ptr = (uint8_t *) findInterfaceDescriptor(ptr, CDC_COMMUNICATION_INTERFACE_CLASS);
cdcParameters[1].dif_intf_desc = ptr = (uint8_t *) findInterfaceDescriptor(ptr, CDC_DATA_INTERFACE_CLASS);
ret = USBD_API->cdc->init(g_hUsb, &cdcParameters[1], &g_hCDC[1]);
PRINTF("Initializing second CDC...");
result = (LPC_OK == ret);
PRINTF(result ? "Successful\r\n" : "Failure\r\n");
PRINTF("Return value: 0x%08X\r\n", ret);
if (ret == LPC_OK) {
endpointIndex = ((USB_CDC_IN_EP_2 & 0x0F) << 1) + 1;
ret = USBD_API->core->RegisterEpHandler(g_hUsb, endpointIndex, bulkInHandler, &USB_CDC_Ctx[1]);
if (ret == LPC_OK) {
endpointIndex = ((USB_CDC_OUT_EP_2 & 0x0F) << 1);
ret = USBD_API->core->RegisterEpHandler(g_hUsb, endpointIndex, bulkOutHandler, &USB_CDC_Ctx[1]);
}
}
USB_CDC_Ctx[1].cdc = g_hCDC[1];
USB_CDC_Ctx[1].in_endpoint = USB_CDC_IN_EP_2;
USB_CDC_Ctx[1].out_endpoint = USB_CDC_OUT_EP_2;
/* ############################################################################################## */
cdcParameters[2].mem_base = usbParameters.mem_base + (usb_block * 2);
cdcParameters[2].mem_size = usb_block;
cdcParameters[2].cif_intf_desc = ptr = (uint8_t *) findInterfaceDescriptor(ptr, CDC_COMMUNICATION_INTERFACE_CLASS);
cdcParameters[2].dif_intf_desc = ptr = (uint8_t *) findInterfaceDescriptor(ptr, CDC_DATA_INTERFACE_CLASS);
ret = USBD_API->cdc->init(g_hUsb, &cdcParameters[2], &g_hCDC[2]);
PRINTF("Initializing third CDC...");
result = (LPC_OK == ret);
PRINTF(result ? "Successful\r\n" : "Failure\r\n");
PRINTF("Return value: 0x%08X\r\n", ret);
if (ret == LPC_OK) {
endpointIndex = ((USB_CDC_IN_EP_3 & 0x0F) << 1) + 1;
ret = USBD_API->core->RegisterEpHandler(g_hUsb, endpointIndex, bulkInHandler, &USB_CDC_Ctx[2]);
if (ret == LPC_OK) {
endpointIndex = ((USB_CDC_OUT_EP_3 & 0x0F) << 1);
ret = USBD_API->core->RegisterEpHandler(g_hUsb, endpointIndex, bulkOutHandler, &USB_CDC_Ctx[2]);
}
}
USB_CDC_Ctx[2].cdc = g_hCDC[2];
USB_CDC_Ctx[2].in_endpoint = USB_CDC_IN_EP_3;
USB_CDC_Ctx[2].out_endpoint = USB_CDC_OUT_EP_3;
NVIC_SetPriority(USB0_IRQn, USB_DEVICE_INTERRUPT_PRIORITY);
/* enable USB interrrupts */
NVIC_EnableIRQ(USB0_IRQn);
/* now connect */
USBD_API->hw->Connect(g_hUsb, 1);
return ret;
}
const uint16_t config_desc_data_length = ( /* wTotalLength */
(1 * USB_CONFIGURATION_DESC_SIZE) + /* length of initial descriptor */
(
(1 * USB_INTERFACE_ASSOCIATION_DESC_SIZE) + /* interface association descriptor */
(1 * USB_INTERFACE_DESC_SIZE) + /* communication control interface*/
(5 + 5 + 4 + 5) + /* CDC functions */
(1 * USB_ENDPOINT_DESC_SIZE) + /* interrupt endpoint */
(1 * USB_INTERFACE_DESC_SIZE) + /* communication interface */
(2 * USB_ENDPOINT_DESC_SIZE) + /* bulk endpoints */
(0)
) * 3
);
/**
* USB FSConfiguration Descriptor
* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor)
*/
ALIGNED(4)
uint8_t USB_FsConfigDescriptor[] = {
/* Configuration 1 */
USB_CONFIGURATION_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_0, /* 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_0, /* 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_0, /* 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_0, /* bMasterInterface: Communication class interface is master */
USB_CDC_DIF_NUM_0, /* 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_CDC_INT_EP_0, /* 0x81: 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_0, /* 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_CDC_OUT_EP_0, /* 0x02: 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_CDC_IN_EP_0, /* 0x82: 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_CDC_INT_EP_2, /* 0x83: 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_CDC_OUT_EP_2, /* 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_CDC_IN_EP_2, /* 0x84: bEndpointAddress */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
WBVAL(64), /* wMaxPacketSize */
0x00, /* bInterval: ignore for Bulk transfer */
/* ###################################################################################################### */
/* Third Interface Pair */
/* Interface association descriptor IAD */
USB_INTERFACE_ASSOCIATION_DESC_SIZE, /* bLength: 8 */
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_CIF_NUM_3, /* 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 */
/* 3rd Communications Interface */
/*Interface 0, Alternate Setting 0, CCI Descriptor*/
USB_INTERFACE_DESC_SIZE, /* bLength: 9 */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_CDC_CIF_NUM_3, /* 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_3, /* 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_3, /* bMasterInterface: Communication class interface is master */
USB_CDC_DIF_NUM_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_CDC_INT_EP_3, /* 0x85: bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0010), /* wMaxPacketSize */
0x08, /* 8ms */ /* bInterval */
/* 3rd 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_3, /* 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_CDC_OUT_EP_3, /* 0x06: 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_CDC_IN_EP_3, /* 0x86: bEndpointAddress */
USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
WBVAL(64), /* wMaxPacketSize */
0x00, /* bInterval: ignore for Bulk transfer */
/* Terminator */
0 /* bLength */
};
Hello @dean_sands
1) First method is debug step by step check issue.
2)Recommend use Config tool inside MCUXpresso IDE to config. Can refer to:
BR
Alice