lpcware

LPC1833 missing USB handshake

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by lpcware_user on Thu Mar 20 03:51:01 MST 2014
hi there,

we are using a LPC1833 with USB0. The firmware is running well, but after some hours data gets lost for an OUT endpoint.

The code looks like this:

The SetConfig callback will configure the needed endpoints and sets internal states. OUT buffer is primed the
very first time:


......
// prime OUT transfer very first time to start the FSM
DataOUTBuff[0].State = DATA_OUT_STATE_PRIMED;
OUTPrimeIdx = 0;
OUTProcIdx = 0;
DcdDataTransfer ( 0, USB_PHYEP_DATA_OUT, (u8_t*)&DataOUTBuff[0].Data[0], 512);
......



The main processing loop sceleton will use two OUT buffers alternating. When data is received the ISR will
set the primed buffer state to DATA_OUT_STATE_RCVD so the loop will see that data is present.


void  USBOUTDATA_Process ( void)
{
static u32_t  *usb_buff = NULL;


switch ( DataOUTBuff[OUTProcIdx].State)
{
case DATA_OUT_STATE_IDLE:
// wait until device is configured, this state is only for startup.
// USBDATA_Init() will start the FSM
break;


case DATA_OUT_STATE_PRIMED:
// wait for data packet from host. When data received the ISR callback
// will set the state to DATA_OUT_STATE_RCVD.
break;


case DATA_OUT_STATE_RCVD:
// data received on buffer X.
// before we will start processing this buffer, prime the other buffer for new transfer
OUTPrimeIdx = OUTProcIdx ^ 1;
DataOUTBuff[OUTPrimeIdx].State = DATA_OUT_STATE_PRIMED;
DcdDataTransfer ( 0, USB_PHYEP_DATA_OUT, (u8_t*)&DataOUTBuff[OUTPrimeIdx].Data[0], 512);

// set this buffer to processing
DataOUTBuff[OUTProcIdx].State = DATA_OUT_STATE_PROC;
usb_buff = &DataOUTBuff[OUTProcIdx].Data[0];  // initialize data pointer

// fall through
// break;


case DATA_OUT_STATE_PROC:
// process data buffer
......
if ( data_finished)
{
// go to other buffer
OUTProcIdx ^= 1;
return;
}

break;
}
}



The firmware is running fine for about one to eight hours. Under unknown circumstances an OUT packet
gets lost by the USB device controller. I have added a screenshot from an USB protocol analyzer. For a
short period of time the USB endpoint is not working correctly. The packet in the blue marked transaction
gets lost cause of a missing IRQ. I can force this behavior by disabling the endpoint. I have spent some
days to find the bug but i am now out of ideas. I hope this is not a silicon errata. At this time a test is
running using two different endpoints. EP 2 for OUT and EP 3 for IN. In the past i used EP 2 for both
directions (IN and OUT).

Regards
lpcware_user

Outcomes