USB host on LPC1788 issues

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by tjoAG on Tue Jun 26 00:45:50 MST 2012

I'm trying to get the USB host up running on my custom board.
I'm using the U2 port and using the TPS2041D power switch. Not using the U1 at all.
Using D2+, D2-, PWR2, OVERCURR2 and PWERD2 signals. No LED UP signal used. The port is used only for HOST

I'm using the USB lite sample from NXP to see if I can get it up and work.

When I insert an USB disk, an interrupt is fired and I start enumerate the host.
But it fail on "Host_ProcessTD". The HOST_TDControlStatus is 5, but should be 0. (The error code is a NODEVICERESPONS or something)

I have changed the HOST BASE ADDRESS to 0x8000 4000 to match the different mem layout in the LPC1788 and the one used in the USBLite sample.

There is +5V available for the USB device.
Before the global power is enabled( LPC_USB->RhStatus = OR_RH_STATUS_LPSC) there is 3,3 V on the +5V in the USB connector.
When the global power is set, the USB_PWR2 goes low and there is +5V in the USB connector.

During enumeration there is activity on the D+ and D- lines. If the levels are OK I don't know.

Any idea's I could try? Swap D+ and D-?

Init code:


uint32_t HostBaseAddr;

LPC_SC->PCONP   |= 0x80000000;
LPC_USB->OTGClkCtrl   = 0x00000019;  // Enable USB,  AHB and OTG clk
while ((LPC_USB->OTGClkSt & 0x00000019) != 0x19); // Wait until clocks are OK

LPC_IOCON->P0_31 &= ~0x07;    // P0.31 D2+, D2- is dedicated pin.
LPC_IOCON->P0_31 |= 0x1;

LPC_IOCON->P0_12  &= ~0x07;    // USB PWR2
LPC_IOCON->P0_12  |= 0x1;

LPC_IOCON->P1_30  &= ~0x47;   // USB PWRD2
LPC_IOCON->P1_30  |= 0x1;

LPC_IOCON->P1_31  &= ~0x07;   // USB overcurrent2
LPC_IOCON->P1_31  |= 0x1;
// Host on port 2
LPC_USB->StCtrl = 0x01; // Can't be 3??? Or it never interrupts when a USB device is inserted!!!

HostBaseAddr = HOST_BASE_ADDR; // Changed to 0x8000 4000 to match the LPC1788 memory layout. Could be 0x8000 2000/0000 as well

Hcca       = (volatile  HCCA       *)(HostBaseAddr+0x000);
TDHead     = (volatile  HCTD       *)(HostBaseAddr+0x100);
TDTail     = (volatile  HCTD       *)(HostBaseAddr+0x110);
EDCtrl     = (volatile  HCED       *)(HostBaseAddr+0x120);
EDBulkIn   = (volatile  HCED       *)(HostBaseAddr+0x130);
EDBulkOut  = (volatile  HCED       *)(HostBaseAddr+0x140);
TDBuffer   = (volatile  uint8_t *)(HostBaseAddr+0x150);
FATBuffer  = (volatile  uint8_t *)(HostBaseAddr+0x1D0);
UserBuffer = (volatile  uint8_t *)(HostBaseAddr+0x1000);

/* Initialize all the TDs, EDs and HCCA to 0  */

Host_DelayMS(50);                /* Wait 50 ms before apply reset              */
LPC_USB->Control       = 0;    /* HARDWARE RESET                             */
LPC_USB->ControlHeadED = 0;    /* Initialize Control list head to Zero       */
LPC_USB->BulkHeadED    = 0;    /* Initialize Bulk list head to Zero          */
/* SOFTWARE RESET                             */
LPC_USB->FmInterval    = DEFAULT_FMINTERVAL;  /* Write Fm Interval and Largest Data Packet Counter */

                                                    /* Put HC in operational state                */
LPC_USB->RhStatus = OR_RH_STATUS_LPSC;        /* Set Global Power                           */
LPC_USB->HCCA = (uint32_t)Hcca;
LPC_USB->InterruptStatus |= LPC_USB->InterruptStatus;                   /* Clear Interrrupt Status                    */

LPC_USB->InterruptEnable  = OR_INTR_ENABLE_MIE |
                         OR_INTR_ENABLE_WDH |
                         OR_INTR_ENABLE_RHSC |

/* Enable the USB Interrupt */
NVIC_EnableIRQ(USB_IRQn);               /* enable USB interrupt */
NVIC_SetPriority (USB_IRQn, 0);         /* highest priority */