Forums

LPC1788 USB Host on Port 2

Started by mike_schwarzer September 20, 2011
Hi Guys,

I would like to use the LPC1788 USB Host on Port 2.
My LPC1788 is running at 120MHz, so i think i have to
use PLL1 (Alternate PLL) to get the USB Clock.

Has someone done so allready, and wold be so nice to
make his code public (At least for me :-)).

I try it following way:
// Turn on USB
PCONP_bit.PCUSB = 1;

// Disable USB interrupts
USBINTS_bit.EN_USB_INTS = 0;

// Init USB engine clk freq - 48MHz
// Set PLL settings f 192 MHz
PLL1CFG_bit.PSEL = PLL1_MUL; //PLL Divisor (_ConfigHW)
PLL1CFG_bit.MSEL = PLL1_DIV; //PLL Multiplikator (_ConfigHW)
PLL1CON_bit.PLLE = 1; //PLL Enable
PLL1FEED = 0xAA;
PLL1FEED = 0x55;
while(!PLL1STAT_bit.PLOCK); //Wait for PLL Lock
PLL1CON = 0x03; //PLL Enable
PLL1FEED = 0xAA;
PLL1FEED = 0x55;

USBCLKSEL_bit.USBSEL = 2; // PLL1 ist USB Clock
USBCLKSEL_bit.USBDIV = 4; // 192MHz
OTGCLKCTRL = 0x11; //Enable USB Host clock
while((OTGCLKST & 0x01) == 0);

//------------------------------
// USB 1: Host
//
IOCON_P1_30 = IOCON(1, IO_MODE_UP, IO_HYS_ENABLE,0, 0, 0, 0); // USB2: VBus
IOCON_P0_12 = IOCON(1, IO_MODE_NONE, IO_HYS_DISABLE, 0, 0, 0, 0); // USB2: PPWR
IOCON_P1_31 = IOCON(1, IO_MODE_NONE, IO_HYS_DISABLE, 0, 0, 0, 0); // USB2: On
IOCON_P0_31 = IOCON(1, IO_MODE_NONE, IO_HYS_ENABLE, 0, 0, 0, 0); // USB2.D+

//---- Assign Core Buffer
LibHost_InitED(&g_tHost.tCtrl);
LibHost_InitED(&g_tHost.tBlkRx);
LibHost_InitED(&g_tHost.tBlkTx);
LibHost_InitTD(&g_tHost.tHead);
LibHost_InitTD(&g_tHost.tTail);
LibHost_InitHCCA(&g_tHost.tHCCA);

Delay_uS(50000);
HCCONTROL = 0; //HARDWARE RESET
HCCONTROLHEADED = 0; //Initialize Control list head to Zero
HCBULKHEADED = 0; //Initialize Bulk list head to Zero

//---- SOFTWARE RESET
HCCOMMANDSTATUS = OR_CMD_STATUS_HCR;
HCFMINTERVAL = DEFAULT_FMINTERVAL; //Write Fm Interval and Largest Data Packet Counter

//---- Put HC in operational state
HCCONTROL = (HCCONTROL & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
HCRHSTATUS = OR_RH_STATUS_LPSC; //Set Global Power

HCHCCA = (Int32U)&g_tHost.tHCCA;
HCINTERRUPTSTATUS |= HCINTERRUPTSTATUS; //Clear Interrrupt Status

//---- Enable interrupts
HCINTERRUPTENABLE_bit.WDH = 1;
HCINTERRUPTENABLE_bit.MIE = 1;
HCINTERRUPTENABLE_bit.RHSC = 1; //Root Hub Status Change

SysNVIC_IntEnable (NVIC_USB);
SysNVIC_SetPriority (NVIC_USB, IRQPRIORITY_USB);
But something is going wrong.
Mostly i get massiv 'NEED_CLOCK' Interrupt's
But i get never a Root Hub Status Change, ...

Anyone out how can give me some help.

mfg
Mike

An Engineer's Guide to the LPC2100 Series

Have you looked at this link:
http://ics.nxp.com/support/software/usb.host.msc/

There are two issues you need to be careful when U2
is configured as host:

(1) you need to turn on OTG clock in OTGClkCtrl register
in order to set PORT_FUNC(0x01) in OTGStCtrl register
settting. (You didn't do that right below.)

(2) There are two RHPortStatus registers,
HcRhPortStatus[1] is for host 1
HcRhPortStatus[2] is for host 2.

Tom

--- In l..., "mike_schwarzer" wrote:
>
> Hi Guys,
>
> I would like to use the LPC1788 USB Host on Port 2.
> My LPC1788 is running at 120MHz, so i think i have to
> use PLL1 (Alternate PLL) to get the USB Clock.
>
> Has someone done so allready, and wold be so nice to
> make his code public (At least for me :-)).
>
> I try it following way:
> // Turn on USB
> PCONP_bit.PCUSB = 1;
>
> // Disable USB interrupts
> USBINTS_bit.EN_USB_INTS = 0;
>
> // Init USB engine clk freq - 48MHz
> // Set PLL settings f 192 MHz
> PLL1CFG_bit.PSEL = PLL1_MUL; //PLL Divisor (_ConfigHW)
> PLL1CFG_bit.MSEL = PLL1_DIV; //PLL Multiplikator (_ConfigHW)
> PLL1CON_bit.PLLE = 1; //PLL Enable
> PLL1FEED = 0xAA;
> PLL1FEED = 0x55;
> while(!PLL1STAT_bit.PLOCK); //Wait for PLL Lock
> PLL1CON = 0x03; //PLL Enable
> PLL1FEED = 0xAA;
> PLL1FEED = 0x55;
>
> USBCLKSEL_bit.USBSEL = 2; // PLL1 ist USB Clock
> USBCLKSEL_bit.USBDIV = 4; // 192MHz
> OTGCLKCTRL = 0x11; //Enable USB Host clock
> while((OTGCLKST & 0x01) == 0);
>
> //------------------------------
> // USB 1: Host
> //
> IOCON_P1_30 = IOCON(1, IO_MODE_UP, IO_HYS_ENABLE,0, 0, 0, 0); // USB2: VBus
> IOCON_P0_12 = IOCON(1, IO_MODE_NONE, IO_HYS_DISABLE, 0, 0, 0, 0); // USB2: PPWR
> IOCON_P1_31 = IOCON(1, IO_MODE_NONE, IO_HYS_DISABLE, 0, 0, 0, 0); // USB2: On
> IOCON_P0_31 = IOCON(1, IO_MODE_NONE, IO_HYS_ENABLE, 0, 0, 0, 0); // USB2.D+
>
> //---- Assign Core Buffer
> LibHost_InitED(&g_tHost.tCtrl);
> LibHost_InitED(&g_tHost.tBlkRx);
> LibHost_InitED(&g_tHost.tBlkTx);
> LibHost_InitTD(&g_tHost.tHead);
> LibHost_InitTD(&g_tHost.tTail);
> LibHost_InitHCCA(&g_tHost.tHCCA);
>
> Delay_uS(50000);
> HCCONTROL = 0; //HARDWARE RESET
> HCCONTROLHEADED = 0; //Initialize Control list head to Zero
> HCBULKHEADED = 0; //Initialize Bulk list head to Zero
>
> //---- SOFTWARE RESET
> HCCOMMANDSTATUS = OR_CMD_STATUS_HCR;
> HCFMINTERVAL = DEFAULT_FMINTERVAL; //Write Fm Interval and Largest Data Packet Counter
>
> //---- Put HC in operational state
> HCCONTROL = (HCCONTROL & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
> HCRHSTATUS = OR_RH_STATUS_LPSC; //Set Global Power
>
> HCHCCA = (Int32U)&g_tHost.tHCCA;
> HCINTERRUPTSTATUS |= HCINTERRUPTSTATUS; //Clear Interrrupt Status
>
> //---- Enable interrupts
> HCINTERRUPTENABLE_bit.WDH = 1;
> HCINTERRUPTENABLE_bit.MIE = 1;
> HCINTERRUPTENABLE_bit.RHSC = 1; //Root Hub Status Change
>
> SysNVIC_IntEnable (NVIC_USB);
> SysNVIC_SetPriority (NVIC_USB, IRQPRIORITY_USB);
>
>
> But something is going wrong.
> Mostly i get massiv 'NEED_CLOCK' Interrupt's
> But i get never a Root Hub Status Change, ...
>
> Anyone out how can give me some help.
>
> mfg
> Mike
>