lpcware

LPC43x0 Errata USBROM.1. workaround doesn't work. CDC Class returns STALL instead of ACK

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by hr on Wed Dec 04 03:18:20 MST 2013
Hi there,

i'm working currently with the LPC4330 and the NGX-Xplorer board. I'm also using the newest LPCOpen Version 2.02. I want to have a virtual serial port over usb and the example code in the  project
ngx_xplorer_4330_usbd_rom_cdc_vcom works fine besides the problem USBROM.1 described in the Errata sheet LPC4350/30/20/10. I have several NGX-boards and all of them have the rev. A Chips on it.
The problem is that i have to get a program running which establishes a remote file system over uart. This software like some other terminal programs (for example putty) cannot connect to the VCOM port due to the bug in the ROM lib.

The workaround for the USBROM.2 problem is already included in the example. I now have a problem with the code provided in the Errata sheet for the USBROM.1 problem. I included the code provided in the sheet in the cdc_vcom.c file and it looks like this.

ErrorCode_t CDC_ep0_override_hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event) {
USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb;
USB_CDC_CTRL_T* pCdcCtrl = (USB_CDC_CTRL_T*) data;
ErrorCode_t ret = ERR_USBD_UNHANDLED;

if(event == USB_EVT_OUT) {
if (pCtrl->SetupPacket.bmRequestType.BM.Type == REQUEST_CLASS) {
if (pCtrl->SetupPacket.bmRequestType.BM.Recipient == REQUEST_TO_INTERFACE) {
if ((pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->cif_num ) || /* IF number correct? */ (pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->dif_num)) {
pCtrl->EP0Data.pData -= pCtrl->SetupPacket.wLength;
ret = pCdcCtrl->CIC_SetRequest(pCdcCtrl, &pCtrl->SetupPacket,&pCtrl->EP0Data.pData,pCtrl->SetupPacket.wLength);
if ( ret == LPC_OK) {
USBD_API->core->StatusInStage(pCtrl); /* send Acknowledge */
}
}
else {
ret = g_defaultCdcHdlr(hUsb, data, event);
}
}
else {
ret = g_defaultCdcHdlr(hUsb, data, event);
}
}
else {
ret = g_defaultCdcHdlr(hUsb, data, event);
}
}
else {
ret = g_defaultCdcHdlr(hUsb, data, event);
}
return ret;
}


I translated the && conditions in the first if to several if statements to check what condition breaks the code. I also added the second part of the code to the cdc_vcom.c file into the vcom_init() function. The code looks like this:

ret = USBD_API->cdc->init(hUsb, &cdc_param, &g_vCOM.hCdc);
{
// Code to fix the STALL Bug in the ROM lib when requesting line breaks
// This code must be placed immediately after the call to USBD_API->cdc->init()
USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb;
/* store the default CDC handler and replace it with ours */
g_defaultCdcHdlr = pCtrl->ep0_hdlr_cb[pCtrl->num_ep0_hdlrs - 1];
pCtrl->ep0_hdlr_cb[pCtrl->num_ep0_hdlrs - 1] = CDC_ep0_override_hdlr;



The workaround function CDC_ep0_override_hdlr is called during the establishment of a connection. So the second part of the code seems to be working. The code in the CDC_ep0_override_hdlr function has now a problem with the last conditional statement.

if ((pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->cif_num ) || /* IF number correct? */ (pCtrl->SetupPacket.wIndex.WB.L == pCdcCtrl->dif_num))


I debuged it to that point. This conditional statement is not true at the important point of the USB_EVT_OUT because of differing interface numbers cif_num and dif_num. The pCtrl structure provides the correct interface numbers as declared in the app_usbd_cfg.h. But the data (pCdcCtrl) structure shows strange numbers. In the case of the control interface it shows a 1 but it should be a zero and in case of the data interface it shows 129 but it should be a one.

I also used the USBlyzer to look at the usb traffic and the host sends the "SetLine_Coding" request to the correct interface number. 0000h. So i don't understand why in the workaround function the data structure which is passed to it has this strange interface numbers in it.

Does anyone has an idea what to check ? Or does anyone already included the workaround code from the Errate sheet ?

Thank you in advance for any help.
Best regards

Attachments

Outcomes