lpcware

Composite CDC+MSC, not working

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by riscy00 on Mon Nov 30 08:41:09 MST 2015
(1) I have working code for CDC with VCOM and working code for MSC (8K RAM) which based on demo code from LPC11Uxx

(2)  I have read the AN11232 app note for which I setup the descriptor. I looked into demo code LPC1343 which has CDC+MSC descriptor.

(3) Below is the descriptor for CDC+MSC, very similar to LPC1343

(4) I discovered the code in LPC1343 is not ROM based and it very different to ROM USB in LPC11U and LPC1549 (that I used).

//
//===========================================================================USB Standard Device Descriptor
//
ALIGNED(4) const uint8_t USB_DeviceDescriptor[] = {
USB_DEVICE_DESC_SIZE,// bLength //
USB_DEVICE_DESCRIPTOR_TYPE,// bDescriptorType //
WBVAL(0x0200),// bcdUSB = USB 2.00//
USB_DEVICE_CLASS_MISCELLANEOUS,// bDeviceClass //
0x02,// bDeviceSubClass //
0x01,// bDeviceProtocol //
USB_MAX_PACKET0,// bMaxPacketSize0 //
WBVAL(0x1FC9),// idVendor //
WBVAL(0x0083),// idProduct //
WBVAL(0x0100),// bcdDevice //
0x01,// iManufacturer //
0x02,// iProduct //
0x03,// iSerialNumber //
0x01// bNumConfigurations //
};

//
// ===========================================================================USB FSConfiguration Descriptor
//  All Descriptors (Configuration, Interface, Endpoint, Class, Vendor)
//
ALIGNED(4) uint8_t USB_FsConfigDescriptor[] = {
// Configuration 1 //
USB_CONFIGURATION_DESC_SIZE,// bLength //
USB_CONFIGURATION_DESCRIPTOR_TYPE,// bDescriptorType //
WBVAL(// wTotalLength //
1 * USB_CONFIGURATION_DESC_SIZE     +
//-------------------------------------MSC Class
1 * USB_INTERFACE_DESC_SIZE         +// MSC interface //
2 * USB_ENDPOINT_DESC_SIZE      +// bulk endpoints //
//-------------------------------------CDC Class
1 * USB_INTERFACE_ASSOC_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 data interface //
2 * USB_ENDPOINT_DESC_SIZE      +// bulk endpoints //
0
),
0x03,// bNumInterfaces //
0x01,// bConfigurationValue //
0x00,// iConfiguration //
USB_CONFIG_BUS_POWERED,// bmAttributes  //Power from USB.
USB_CONFIG_POWER_MA(500),// bMaxPower //

//==============================================================
//-------------------------------------Interface 0, Alternate Setting 0, MSC class interface descriptor //
USB_INTERFACE_DESC_SIZE,// bLength //
USB_INTERFACE_DESCRIPTOR_TYPE,// bDescriptorType //
USB_MSC_IF_NUM,// bInterfaceNumber: Number of Interface //
0x00,// bAlternateSetting: Alternate setting //
0x02,// bNumEndpoints: One endpoint used //
USB_DEVICE_CLASS_STORAGE,// bInterfaceClass: Communication Interface Class //
MSC_SUBCLASS_SCSI,// bInterfaceSubClass: Abstract Control Model //
MSC_PROTOCOL_BULK_ONLY,// bInterfaceProtocol: no protocol used //
0x04,// iInterface: //
//----------------------------------Endpoint, EP Bulk In //
USB_ENDPOINT_DESC_SIZE,// bLength //
USB_ENDPOINT_DESCRIPTOR_TYPE,// bDescriptorType //
//USB_ENDPOINT_IN(2),// bEndpointAddress //  LPC134x method.
USB_MSC_IN_EP,// bEndpointAddress //
USB_ENDPOINT_TYPE_BULK,// bmAttributes //
WBVAL(USB_FS_MAX_BULK_PACKET),// wMaxPacketSize //
0x00,// bInterval: ignore for Bulk transfer //
//----------------------------------Endpoint, EP Bulk Out //
USB_ENDPOINT_DESC_SIZE,// bLength //
USB_ENDPOINT_DESCRIPTOR_TYPE,// bDescriptorType //
//USB_ENDPOINT_OUT(2),// bEndpointAddress //  LPC134x method.
USB_MSC_OUT_EP,// bEndpointAddress //
USB_ENDPOINT_TYPE_BULK,// bmAttributes //
WBVAL(USB_FS_MAX_BULK_PACKET),// wMaxPacketSize //
0x00,// bInterval: ignore for Bulk transfer //

//==============================================================

//-------------------------------------Interface association descriptor IAD//
USB_INTERFACE_ASSOC_DESC_SIZE,// bLength //
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,// bDescriptorType //
USB_CDC_CIF_NUM,// bFirstInterface //
0x02,// bInterfaceCount //
CDC_COMMUNICATION_INTERFACE_CLASS,// bFunctionClass //
CDC_ABSTRACT_CONTROL_MODEL,// bFunctionSubClass //
0x00,// bFunctionProtocol //
0x06,// iFunction //

//==============================================================

//-------------------------------------Interface 0, Alternate Setting 0, Communication class interface descriptor //
USB_INTERFACE_DESC_SIZE,// bLength //
USB_INTERFACE_DESCRIPTOR_TYPE,// bDescriptorType //
USB_CDC_CIF_NUM,// bInterfaceNumber: Number of Interface //
0x00,// bAlternateSetting: Alternate setting //
0x01,// bNumEndpoints: One endpoint used //
CDC_COMMUNICATION_INTERFACE_CLASS,// bInterfaceClass: Communication Interface Class //
CDC_ABSTRACT_CONTROL_MODEL,// bInterfaceSubClass: Abstract Control Model //
0x00,// bInterfaceProtocol: no protocol used //
0x05,// iInterface: //

// Header Functional Descriptor//
0x05,// bLength: CDC header Descriptor size //
CDC_CS_INTERFACE,// bDescriptorType: CS_INTERFACE //
CDC_HEADER,// bDescriptorSubtype: Header Func Desc //
WBVAL(CDC_V1_10),// bcdCDC 1.10 //

// 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 //
USB_CDC_DIF_NUM,// bDataInterface: CDC data IF ID //

// 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,// bDescriptorSubtype: Union func desc //
USB_CDC_CIF_NUM,// bMasterInterface: Communication class interface is master //
USB_CDC_DIF_NUM,// bSlaveInterface0: Data class interface is slave 0 //
//-------------------------------------Endpoint 1 Descriptor//
USB_ENDPOINT_DESC_SIZE,// bLength //
USB_ENDPOINT_DESCRIPTOR_TYPE,// bDescriptorType //
//USB_ENDPOINT_IN(1),// bEndpointAddress //  LPC134x method.
USB_CDC_INT_EP,// bEndpointAddress //
USB_ENDPOINT_TYPE_INTERRUPT,// bmAttributes //
WBVAL(0x0010),// wMaxPacketSize //
0x02,// 2ms //           // bInterval //

//===========================================================

//-------------------------------------Interface 1, Alternate Setting 0, Data class interface descriptor//
USB_INTERFACE_DESC_SIZE,// bLength //
USB_INTERFACE_DESCRIPTOR_TYPE,// bDescriptorType //
USB_CDC_DIF_NUM,// 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 //
0x05,// iInterface: //
//-------------------------------------Endpoint, EP Bulk Out //
USB_ENDPOINT_DESC_SIZE,// bLength //
USB_ENDPOINT_DESCRIPTOR_TYPE,// bDescriptorType //
//USB_ENDPOINT_OUT(3),// bEndpointAddress //  LPC134x method.
USB_CDC_OUT_EP,// bEndpointAddress //
USB_ENDPOINT_TYPE_BULK,// bmAttributes //
WBVAL(USB_FS_MAX_BULK_PACKET),// wMaxPacketSize //
0x00,// bInterval: ignore for Bulk transfer //
//-------------------------------------Endpoint, EP Bulk In //
USB_ENDPOINT_DESC_SIZE,// bLength //
USB_ENDPOINT_DESCRIPTOR_TYPE,// bDescriptorType //
//USB_ENDPOINT_IN(3),// bEndpointAddress //  LPC134x method.
USB_CDC_IN_EP,// bEndpointAddress //
USB_ENDPOINT_TYPE_BULK,// bmAttributes //
WBVAL(64),// wMaxPacketSize //
0x00,// bInterval: ignore for Bulk transfer //
// Terminator //
0// bLength //
};


//
//=========================================================================== USB Device Qualifier (Do we need this??)
//
/*
ALIGNED(4) const uint8_t USB_DeviceQualifier[] = {
USB_DEVICE_QUALI_SIZE,// bLength
USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE,// bDescriptorType
WBVAL(0x0200),// bcdUSB: 2.00
0x00,// bDeviceClass
0x00,// bDeviceSubClass
0x00,// bDeviceProtocol
USB_MAX_PACKET0,// bMaxPacketSize0
0x01,// bNumOtherSpeedConfigurations
0x00// bReserved
};
*/


(5) Below is the init code, not sure what I am doing


void USB_Main_Init(void)// ex Main.
{
USBD_API_INIT_PARAM_T usb_param;
USB_CORE_DESCS_T desc;
ErrorCode_t ret = LPC_OK;

Chip_USB_Init();// Enable USB Clock.// enable clocks
g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->pUSBD;// initialize USBD ROM API pointer.

memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));// initialize call back structures
usb_param.usb_reg_base = LPC_USB0_BASE;

//--------------------------------------------------------------------- Bug Fixes
/*WORKAROUND for artf44835 ROM driver BUG:
    Code clearing STALL bits in endpoint reset routine corrupts memory area
    next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
    EP2_IN are used we need to specify 3 here. But as a workaround for this
    issue specify 4. So that extra EPs control structure acts as padding buffer
    to avoid data corruption. Corruption of padding memory doesn’t affect the
    stack/program behaviour.
*/
usb_param.max_num_ep = 4 + 1;// May need to adjust to 4+1.
//---------------------------------------------------------------------------
usb_param.mem_base = USB_STACK_MEM_BASE;
usb_param.mem_size = USB_STACK_MEM_SIZE;

desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];// Set the USB descriptors
desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
// Note, to pass USBCV test full-speed only devices should have both
// descriptor arrays point to same location and device_qualifier set to 0.
desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
desc.device_qualifier = 0;

ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);// USB Initialization
if (ret == LPC_OK)
{
ret = mscDisk_init(g_hUsb, &desc, &usb_param);
ret = vcom_init(g_hUsb, &desc, &usb_param);// Init VCOM section
if (ret == LPC_OK)
{
NVIC_SetPriority(USB0_IRQn, 1);// Make sure USB and UART IRQ priorities are same for this example
NVIC_EnableIRQ(USB0_IRQn);//  enable USB interrupts
USBD_API->hw->Connect(g_hUsb, 1);// now connect
}
}
if ((vcom_connected() != 0))
vcom_write("---USB Test\n", 15);
}


(6) I have downloaded the Kiel but I could not find examples code under MCB11U00 (see page 9 within AN11232). Can you send me source code, are they rom based solution that I can work on?

I'm open for suggestion what to do next or workaround this. 

Outcomes