LPC54605J256BD100 Won't attach USB clock

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC54605J256BD100 Won't attach USB clock

248 Views
SOOTY1
Contributor I

Hi,

my custom board will not attach the clock.  I have been trying for weeks to get this to work.  I cannot.  I cannot find any results anywhere online, which will tell me how to successfully attach the USB1 clock.  Surely there must be a logical set of instructions which will attach it properly, somewhere?


All the config tools are set correctly with the correct frequencies and selections for it to work properly, but it does not.


Several manual steps have been undertaken in main, in order to try to fix the obvious shortcomings of the gui tool.  This has not helped.  Probably the order and timing is incorrect.  As there are so many, and the order is very particular, I am not surprised if it is very incorrect.

Please, can somebody tell me where I am going wrong with the set up?  
I want to have USB working on this device.  This is beyond frustrating at this point.  Thanks.

Main -

int main(void)
{
vPortDefineHeapRegions(xHeapRegions);

BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
BOARD_InitUSB1HS_USBPLL_Only();

SEGGER_RTT_Init();

PRINTF("System Booting...\r\n");
PRINTF("Core clock = %lu Hz\r\n", CLOCK_GetFreq(kCLOCK_CoreSysClk));

/* 1. POWER DOMAINS FIRST */
POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA);
POWER_DisablePD(kPDRUNCFG_PD_VD3);
POWER_DisablePD(kPDRUNCFG_PD_VD5);
POWER_DisablePD(kPDRUNCFG_PD_USB_PLL);
POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY);
/* Power up the PHY LDO (Bit 24) which is often separate from the PHY logic */
SYSCON->PDRUNCFGCLR[0] = (1U << 24);

SDK_DelayAtLeastUs(15000, SystemCoreClock);
while (!(SYSCON->USBPLLSTAT & 0x1)); // Wait for hardware lock

/* 2. THE MANUAL CLOCK FIX */
PRINTF("Applying Manual Clock Fix...\r\n");

// IMPORTANT: Ensure AHB clock is OFF so the divider logic is 'unloaded'
SYSCON->AHBCLKCTRLCLR[2] = (1U << 18);
SYSCON->USB1CLKDIV |= (1U << 30); // Halt divider
SYSCON->USB1CLKSEL = 7U; // "Disable" (Park at None)
for (volatile int i = 0; i < 1500; i++) { __asm("NOP"); }

SYSCON->USB1CLKSEL = 2U; // Target: USBPLL (288MHz)
SYSCON->USB1CLKDIV = (1U << 30) | 5U; // Target: Div by 6 (48MHz)
for (volatile int i = 0; i < 1500; i++) { __asm("NOP"); }

SYSCON->USB1CLKDIV &= ~(1U << 30); // Release Halt

PRINTF("POST-FIX USB1CLKSEL: 0x%08lX\r\n", SYSCON->USB1CLKSEL);
PRINTF("POST-FIX USB1CLKDIV: 0x%08lX\r\n", SYSCON->USB1CLKDIV);

/* 3. HARDWARE ENABLE & RESET PULSE */
// Now that the clock is stable, turn on the AHB interface
SYSCON->AHBCLKCTRLSET[2] = (1U << 18);

//Pulse Reset to sync the controller to the 48MHz clock
SYSCON->PRESETCTRLSET[2] = (1U << 18);
for (volatile int i = 0; i < 1000; i++) { __asm("NOP"); }
SYSCON->PRESETCTRLCLR[2] = (1U << 18);

 

/* 5. FINAL DIAGNOSTICS BEFORE INIT */
PRINTF("\r\n--- PRE-INIT DIAGNOSTICS ---\r\n");
PRINTF("USB1CLKSEL : 0x%08lX\r\n", SYSCON->USB1CLKSEL);
PRINTF("USB1CLKDIV : 0x%08lX\r\n", SYSCON->USB1CLKDIV);
PRINTF("USBHSH->PORTSC1 : 0x%08lX\r\n", USBHSH->PORTSC1);
PRINTF("PDRUNCFG : 0x%08lX\r\n", SYSCON->PDRUNCFG);

/* --- 1. FORCE PHY CONFIG --- */
// 16: Host Mode, 17: Clock Valid, 21: Force VBUS, 23: Force 48MHz Lock
USBHSH->PORTMODE |= (1U << 16) | (1U << 17) | (1U << 21) | (1U << 23);

/* --- 2. FINAL HARDWARE RESET PULSE --- */
SYSCON->PRESETCTRLSET[2] = (1U << 18);
for (volatile int i = 0; i < 5000; i++) { __asm("NOP"); }
SYSCON->PRESETCTRLCLR[2] = (1U << 18);

/* --- 3. STABILIZATION DELAY --- */
SDK_DelayAtLeastUs(10000, SystemCoreClock);

/* --- 4. PRE-INIT DIAGNOSTICS --- */
PRINTF("\r\n--- FINAL HW CHECK ---\r\n");
PRINTF("USBHSH->USBSTS: 0x%08lX\r\n", USBHSH->USBSTS);
PRINTF("USBHSH->USBCMD: 0x%08lX\r\n", USBHSH->USBCMD);
PRINTF("USBHSH->PORTMODE: 0x%08lX\r\n", USBHSH->PORTMODE);

/* 2. Re-sync the clock tree variables */
SystemCoreClockUpdate();

/* 3. Manually toggle the USB1 Clock Gate */
// SYSCON->AHBCLKCTRLSET[2] = (1U << 18); // Ensure AHB is on


status_t clkStatus = CLOCK_EnableUsbhs0HostClock(kCLOCK_UsbSrcUsbPll, 48000000U);
PRINTF("Clock enable returned: %d\r\n", clkStatus);

PRINTF("USB PLL freq = %lu Hz\r\n", CLOCK_GetFreq(kCLOCK_UsbPll));
PRINTF("USB1CLK freq = %lu Hz\r\n", CLOCK_GetFreq(kCLOCK_UsbClk));

/* 6. STACK INIT */
usb_status_t status = USB_HostInit(CONTROLLER_ID, &g_HostHandle, USB_HostEvent);
if (status != kStatus_USB_Success) {
PRINTF("USB_HostInit failed with status %d\r\n", status);
}




0 Kudos
Reply
3 Replies

1 View
SOOTY1
Contributor I

In case anybody wants an example of USB Host HID Keypad, you can try this for the LPC54605J256BD100. I had it working like this:  Using RTT you'll have to take out if you don't have a SEGGER probe.

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_device_registers.h"
#include "fsl_power.h"

#include "SEGGER_RTT.h"
#include "FreeRTOS.h"
#include "task.h"

#include "usb_host_config.h"
#include "usb_host.h"
#include "usb.h"
#include "usb_host_hid.h"
#include "host_hid_generic.h"
#include "usb_host_ip3516hs.h"
#include "usb_host_hub.h"
#include "usb_host_interface_0_hid_keyboard.h"

#define PRINTF(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define CONTROLLER_ID kUSB_ControllerIp3516Hs0

static usb_host_handle g_HostHandle;
static usb_host_interface_handle g_HidKeyboardInterface = NULL;
static usb_host_class_handle g_HidKeyboardClassHandle = NULL;
static usb_device_handle g_HidKeyboardDeviceHandle = NULL;
static volatile bool g_KeyboardReady = false;
static uint8_t g_KeyboardReport[8];

static const char *keycode_to_ascii(uint8_t keycode, uint8_t modifiers)
{
(void)modifiers;
static char buf[20];

switch (keycode)
{
case 98: return "0";
case 89: return "1";
case 90: return "2";
case 91: return "3";
case 92: return "4";
case 93: return "5";
case 94: return "6";
case 95: return "7";
case 96: return "8";
case 97: return "9";
case 99: return ".";
case 85: return "*";
case 86: return "-";
case 87: return "+";
case 88: return "[ENTER]";
case 76: return "/";
case 83: return "[NUMLOCK]";
case 42: return "[BACKSPACE]";
case 79: return "[RIGHT]";
case 80: return "[LEFT]";
case 81: return "[DOWN]";
case 82: return "[UP]";
case 75: return "[HOME]";
case 78: return "[PGUP]";
case 77: return "[END]";
case 74: return "[INS]";
case 73: return "[DEL]";
default:
snprintf(buf, sizeof(buf), "[0x%02X]", keycode);
return buf;
}
}

static void USB_HostHidKeyboardRecvCallback(void *param,
uint8_t *buffer,
uint32_t length,
usb_status_t status)
{
(void)param;

if (status == kStatus_USB_Success && buffer != NULL && length > 0)
{
uint8_t modifiers = buffer[0];
uint8_t key = 0;

for (int i = 2; i < 8; i++)
{
if (buffer[i] != 0)
{
key = buffer[i];
break;
}
}

if (key != 0)
{
PRINTF("Key: 0x%02X -> %s", key, keycode_to_ascii(key, modifiers));
if (modifiers)
{
PRINTF(" (Mod:0x%02X)", modifiers);
}
PRINTF("\r\n");
}
else
{
PRINTF("Key released\r\n");
}
}
else if (status != kStatus_USB_Success)
{
PRINTF("HID receive error: %d\r\n", status);
}

if (g_HidKeyboardClassHandle != NULL)
{
USB_HostHidRecv(g_HidKeyboardClassHandle,
g_KeyboardReport,
sizeof(g_KeyboardReport),
USB_HostHidKeyboardRecvCallback,
NULL);
}
}

static void hid_set_interface_callback(void *param,
uint8_t *data,
uint32_t dataLength,
usb_status_t status)
{
(void)param;
(void)data;
(void)dataLength;

if (status != kStatus_USB_Success)
{
PRINTF("SetInterface failed: %d\r\n", status);
return;
}

PRINTF("Interface bound OK\r\n");

USB_HostHidSetProtocol(g_HidKeyboardClassHandle,
USB_HOST_HID_REQUEST_PROTOCOL_BOOT,
NULL,
NULL);

USB_HostHidRecv(g_HidKeyboardClassHandle,
g_KeyboardReport,
sizeof(g_KeyboardReport),
USB_HostHidKeyboardRecvCallback,
NULL);
}

static void USB_StartKeyboardIfReady(void)
{
usb_status_t status;

if (!g_KeyboardReady || g_HidKeyboardDeviceHandle == NULL)
{
return;
}

g_KeyboardReady = false;

status = USB_HostHidInit(g_HidKeyboardDeviceHandle, &g_HidKeyboardClassHandle);
PRINTF("HidInit = %d\r\n", status);

if (status != kStatus_USB_Success)
{
return;
}

status = USB_HostHidSetInterface(g_HidKeyboardClassHandle,
g_HidKeyboardInterface,
0,
hid_set_interface_callback,
NULL);
PRINTF("SetInterface submit = %d\r\n", status);
}

usb_status_t USB_HostEvent(usb_device_handle deviceHandle,
usb_host_configuration_handle configurationHandle,
uint32_t eventCode)
{
usb_host_configuration_t *config;
uint8_t interfaceIndex;

switch (eventCode)
{
case kUSB_HostEventAttach:
g_HidKeyboardDeviceHandle = deviceHandle;
PRINTF("USB Device Attached\r\n");
break;

case kUSB_HostEventEnumerationDone:
if (g_HidKeyboardDeviceHandle != deviceHandle)
{
break;
}

config = (usb_host_configuration_t *)configurationHandle;

for (interfaceIndex = 0; interfaceIndex < config->interfaceCount; interfaceIndex++)
{
usb_host_interface_t *interface = &config->interfaceList[interfaceIndex];
usb_descriptor_interface_t *desc = (usb_descriptor_interface_t *)interface->interfaceDesc;

if (desc == NULL)
{
continue;
}

if (desc->bInterfaceClass == USB_HOST_HID_CLASS_CODE)
{
g_HidKeyboardInterface = interface;
g_HidKeyboardDeviceHandle = deviceHandle;
g_KeyboardReady = true;

PRINTF("HID keyboard detected\r\n");

USB_StartKeyboardIfReady();
return kStatus_USB_Success;
}
}
break;

case kUSB_HostEventDetach:
if (g_HidKeyboardDeviceHandle == deviceHandle)
{
PRINTF("USB keyboard detached\r\n");
g_HidKeyboardDeviceHandle = NULL;
g_HidKeyboardInterface = NULL;
g_HidKeyboardClassHandle = NULL;
g_KeyboardReady = false;
}
break;

default:
break;
}

return kStatus_USB_Success;
}

void USB_HostClockInit(void)
{
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
CLOCK_EnableUsbhs0HostClock(kCLOCK_UsbSrcUsbPll, 48000000U);
USBHSH->PORTMODE &= ~(1UL << 16);
USBHSH->PORTMODE |= (1UL << 17);
USBHSH->PORTMODE &= ~(1UL << 8);

for (volatile uint32_t d = 0; d < 500000; d++)
{
__NOP();
}

#if ((defined FSL_FEATURE_USBHSH_USB_RAM) && (FSL_FEATURE_USBHSH_USB_RAM > 0U))
for (int i = 0; i < (FSL_FEATURE_USBHSH_USB_RAM >> 2); i++)
{
((uint32_t *)FSL_FEATURE_USBHSH_USB_RAM_BASE_ADDRESS)[i] = 0U;
}
#endif
#endif
}

void USB_HostIsrEnable(void)
{
IRQn_Type irqNumber = USB1_IRQn;
NVIC_SetPriority(irqNumber, USB_HOST_INTERRUPT_PRIORITY);
EnableIRQ(irqNumber);
}

usb_status_t USB_HostApplicationInit(void)
{
usb_status_t status = kStatus_USB_Success;

USB_HostClockInit();
PRINTF("Clock Init done\r\n");

#if ((defined FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT))
SYSMPU_Enable(SYSMPU, 0);
#endif

status = USB_HostInit(CONTROLLER_ID, &g_HostHandle, USB_HostEvent);
if (status != kStatus_USB_Success)
{
PRINTF("USB_HostInit FAILED (status=%d)\r\n", status);
return status;
}

PRINTF("USB_HostInit SUCCESS\r\n");
USB_HostIsrEnable();
PRINTF("USB host ISR enabled\r\n");

return status;
}

void USB_HostTaskFn(void *param)
{
#if ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS > 0U))
USB_HostIp3516HsTaskFunction(param);
#endif
}

static void USB_HostTask(void *param)
{
while (1)
{
USB_HostTaskFn(param);
vTaskDelay(pdMS_TO_TICKS(1));
}
}

static void USB_HostApplicationTask(void *param)
{
while (1)
{
USB_HostHidGenericTask(param);
vTaskDelay(pdMS_TO_TICKS(1));
}
}

void BOARD_InitHardware(void)
{
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitPeripherals();
POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY);
POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY);
}

extern "C" void USB1_IRQHandler(void)
{
if (g_HostHandle != NULL)
{
USB_HostIp3516HsIsrFunction(g_HostHandle);
}
}

int main(void)
{
SEGGER_RTT_Init();
BOARD_InitHardware();

USB_HostApplicationInit();

xTaskCreate(USB_HostTask, "USB_Host", 2048, g_HostHandle, 3, NULL);
xTaskCreate(USB_HostApplicationTask, "HID_Generic", 2048, g_HostHandle, 2, NULL);

PRINTF("Starting scheduler...\r\n");
vTaskStartScheduler();

while (1)
{
}
}

0 Kudos
Reply

135 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @SOOTY1 

Please test the SDK demo on your board.
There is a guide available on how to switch the USB demo from USB0 to USB1.
 
 
BR
Alice
 
0 Kudos
Reply

132 Views
SOOTY1
Contributor I

Thanks Alice.  I have managed to piece together usb host init, from the files in the xx628 host hid generic example.

thanks very much, regards

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2366263%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELPC54605J256BD100%20Won't%20attach%20USB%20clock%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2366263%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3CBR%20%2F%3E%3CBR%20%2F%3Emy%20custom%20board%20will%20not%20attach%20the%20clock.%26nbsp%3B%20I%20have%20been%20trying%20for%20weeks%20to%20get%20this%20to%20work.%26nbsp%3B%20I%20cannot.%26nbsp%3B%20I%20cannot%20find%20any%20results%20anywhere%20online%2C%20which%20will%20tell%20me%20how%20to%20successfully%20attach%20the%20USB1%20clock.%26nbsp%3B%20Surely%20there%20must%20be%20a%20logical%20set%20of%20instructions%20which%20will%20attach%20it%20properly%2C%20somewhere%3F%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAll%20the%20config%20tools%20are%20set%20correctly%20with%20the%20correct%20frequencies%20and%20selections%20for%20it%20to%20work%20properly%2C%20but%20it%20does%20not.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ESeveral%20manual%20steps%20have%20been%20undertaken%20in%20main%2C%20in%20order%20to%20try%20to%20fix%20the%20obvious%20shortcomings%20of%20the%20gui%20tool.%26nbsp%3B%20This%20has%20not%20helped.%26nbsp%3B%20Probably%20the%20order%20and%20timing%20is%20incorrect.%26nbsp%3B%20As%20there%20are%20so%20many%2C%20and%20the%20order%20is%20very%20particular%2C%20I%20am%20not%20surprised%20if%20it%20is%20very%20incorrect.%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%2C%20can%20somebody%20tell%20me%20where%20I%20am%20going%20wrong%20with%20the%20set%20up%3F%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3EI%20want%20to%20have%20USB%20working%20on%20this%20device.%26nbsp%3B%20This%20is%20beyond%20frustrating%20at%20this%20point.%26nbsp%3B%20Thanks.%3CBR%20%2F%3E%3CBR%20%2F%3EMain%20-%3C%2FP%3E%3CP%3Eint%20main(void)%3CBR%20%2F%3E%7B%3CBR%20%2F%3EvPortDefineHeapRegions(xHeapRegions)%3B%3C%2FP%3E%3CP%3EBOARD_InitBootPins()%3B%3CBR%20%2F%3EBOARD_InitBootClocks()%3B%3CBR%20%2F%3EBOARD_InitBootPeripherals()%3B%3CBR%20%2F%3EBOARD_InitUSB1HS_USBPLL_Only()%3B%3C%2FP%3E%3CP%3ESEGGER_RTT_Init()%3B%3C%2FP%3E%3CP%3EPRINTF(%22System%20Booting...%5Cr%5Cn%22)%3B%3CBR%20%2F%3EPRINTF(%22Core%20clock%20%3D%20%25lu%20Hz%5Cr%5Cn%22%2C%20CLOCK_GetFreq(kCLOCK_CoreSysClk))%3B%3C%2FP%3E%3CP%3E%2F*%201.%20POWER%20DOMAINS%20FIRST%20*%2F%3CBR%20%2F%3EPOWER_DisablePD(kPDRUNCFG_PD_VD2_ANA)%3B%3CBR%20%2F%3EPOWER_DisablePD(kPDRUNCFG_PD_VD3)%3B%3CBR%20%2F%3EPOWER_DisablePD(kPDRUNCFG_PD_VD5)%3B%3CBR%20%2F%3EPOWER_DisablePD(kPDRUNCFG_PD_USB_PLL)%3B%3CBR%20%2F%3EPOWER_DisablePD(kPDRUNCFG_PD_USB1_PHY)%3B%3CBR%20%2F%3E%2F*%20Power%20up%20the%20PHY%20LDO%20(Bit%2024)%20which%20is%20often%20separate%20from%20the%20PHY%20logic%20*%2F%3CBR%20%2F%3ESYSCON-%26gt%3BPDRUNCFGCLR%5B0%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2024)%3B%3C%2FP%3E%3CP%3ESDK_DelayAtLeastUs(15000%2C%20SystemCoreClock)%3B%3CBR%20%2F%3Ewhile%20(!(SYSCON-%26gt%3BUSBPLLSTAT%20%26amp%3B%200x1))%3B%20%2F%2F%20Wait%20for%20hardware%20lock%3C%2FP%3E%3CP%3E%2F*%202.%20THE%20MANUAL%20CLOCK%20FIX%20*%2F%3CBR%20%2F%3EPRINTF(%22Applying%20Manual%20Clock%20Fix...%5Cr%5Cn%22)%3B%3C%2FP%3E%3CP%3E%2F%2F%20IMPORTANT%3A%20Ensure%20AHB%20clock%20is%20OFF%20so%20the%20divider%20logic%20is%20'unloaded'%3CBR%20%2F%3ESYSCON-%26gt%3BAHBCLKCTRLCLR%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%3CBR%20%2F%3ESYSCON-%26gt%3BUSB1CLKDIV%20%7C%3D%20(1U%20%26lt%3B%26lt%3B%2030)%3B%20%2F%2F%20Halt%20divider%3CBR%20%2F%3ESYSCON-%26gt%3BUSB1CLKSEL%20%3D%207U%3B%20%2F%2F%20%22Disable%22%20(Park%20at%20None)%3CBR%20%2F%3Efor%20(volatile%20int%20i%20%3D%200%3B%20i%20%26lt%3B%201500%3B%20i%2B%2B)%20%7B%20__asm(%22NOP%22)%3B%20%7D%3C%2FP%3E%3CP%3ESYSCON-%26gt%3BUSB1CLKSEL%20%3D%202U%3B%20%2F%2F%20Target%3A%20USBPLL%20(288MHz)%3CBR%20%2F%3ESYSCON-%26gt%3BUSB1CLKDIV%20%3D%20(1U%20%26lt%3B%26lt%3B%2030)%20%7C%205U%3B%20%2F%2F%20Target%3A%20Div%20by%206%20(48MHz)%3CBR%20%2F%3Efor%20(volatile%20int%20i%20%3D%200%3B%20i%20%26lt%3B%201500%3B%20i%2B%2B)%20%7B%20__asm(%22NOP%22)%3B%20%7D%3C%2FP%3E%3CP%3ESYSCON-%26gt%3BUSB1CLKDIV%20%26amp%3B%3D%20~(1U%20%26lt%3B%26lt%3B%2030)%3B%20%2F%2F%20Release%20Halt%3C%2FP%3E%3CP%3EPRINTF(%22POST-FIX%20USB1CLKSEL%3A%200x%2508lX%5Cr%5Cn%22%2C%20SYSCON-%26gt%3BUSB1CLKSEL)%3B%3CBR%20%2F%3EPRINTF(%22POST-FIX%20USB1CLKDIV%3A%200x%2508lX%5Cr%5Cn%22%2C%20SYSCON-%26gt%3BUSB1CLKDIV)%3B%3C%2FP%3E%3CP%3E%2F*%203.%20HARDWARE%20ENABLE%20%26amp%3B%20RESET%20PULSE%20*%2F%3CBR%20%2F%3E%2F%2F%20Now%20that%20the%20clock%20is%20stable%2C%20turn%20on%20the%20AHB%20interface%3CBR%20%2F%3ESYSCON-%26gt%3BAHBCLKCTRLSET%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%3C%2FP%3E%3CP%3E%2F%2FPulse%20Reset%20to%20sync%20the%20controller%20to%20the%2048MHz%20clock%3CBR%20%2F%3ESYSCON-%26gt%3BPRESETCTRLSET%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%3CBR%20%2F%3Efor%20(volatile%20int%20i%20%3D%200%3B%20i%20%26lt%3B%201000%3B%20i%2B%2B)%20%7B%20__asm(%22NOP%22)%3B%20%7D%3CBR%20%2F%3ESYSCON-%26gt%3BPRESETCTRLCLR%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%2F*%205.%20FINAL%20DIAGNOSTICS%20BEFORE%20INIT%20*%2F%3CBR%20%2F%3EPRINTF(%22%5Cr%5Cn---%20PRE-INIT%20DIAGNOSTICS%20---%5Cr%5Cn%22)%3B%3CBR%20%2F%3EPRINTF(%22USB1CLKSEL%20%3A%200x%2508lX%5Cr%5Cn%22%2C%20SYSCON-%26gt%3BUSB1CLKSEL)%3B%3CBR%20%2F%3EPRINTF(%22USB1CLKDIV%20%3A%200x%2508lX%5Cr%5Cn%22%2C%20SYSCON-%26gt%3BUSB1CLKDIV)%3B%3CBR%20%2F%3EPRINTF(%22USBHSH-%26gt%3BPORTSC1%20%3A%200x%2508lX%5Cr%5Cn%22%2C%20USBHSH-%26gt%3BPORTSC1)%3B%3CBR%20%2F%3EPRINTF(%22PDRUNCFG%20%3A%200x%2508lX%5Cr%5Cn%22%2C%20SYSCON-%26gt%3BPDRUNCFG)%3B%3C%2FP%3E%3CP%3E%2F*%20---%201.%20FORCE%20PHY%20CONFIG%20---%20*%2F%3CBR%20%2F%3E%2F%2F%2016%3A%20Host%20Mode%2C%2017%3A%20Clock%20Valid%2C%2021%3A%20Force%20VBUS%2C%2023%3A%20Force%2048MHz%20Lock%3CBR%20%2F%3EUSBHSH-%26gt%3BPORTMODE%20%7C%3D%20(1U%20%26lt%3B%26lt%3B%2016)%20%7C%20(1U%20%26lt%3B%26lt%3B%2017)%20%7C%20(1U%20%26lt%3B%26lt%3B%2021)%20%7C%20(1U%20%26lt%3B%26lt%3B%2023)%3B%3C%2FP%3E%3CP%3E%2F*%20---%202.%20FINAL%20HARDWARE%20RESET%20PULSE%20---%20*%2F%3CBR%20%2F%3ESYSCON-%26gt%3BPRESETCTRLSET%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%3CBR%20%2F%3Efor%20(volatile%20int%20i%20%3D%200%3B%20i%20%26lt%3B%205000%3B%20i%2B%2B)%20%7B%20__asm(%22NOP%22)%3B%20%7D%3CBR%20%2F%3ESYSCON-%26gt%3BPRESETCTRLCLR%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%3C%2FP%3E%3CP%3E%2F*%20---%203.%20STABILIZATION%20DELAY%20---%20*%2F%3CBR%20%2F%3ESDK_DelayAtLeastUs(10000%2C%20SystemCoreClock)%3B%3C%2FP%3E%3CP%3E%2F*%20---%204.%20PRE-INIT%20DIAGNOSTICS%20---%20*%2F%3CBR%20%2F%3EPRINTF(%22%5Cr%5Cn---%20FINAL%20HW%20CHECK%20---%5Cr%5Cn%22)%3B%3CBR%20%2F%3EPRINTF(%22USBHSH-%26gt%3BUSBSTS%3A%200x%2508lX%5Cr%5Cn%22%2C%20USBHSH-%26gt%3BUSBSTS)%3B%3CBR%20%2F%3EPRINTF(%22USBHSH-%26gt%3BUSBCMD%3A%200x%2508lX%5Cr%5Cn%22%2C%20USBHSH-%26gt%3BUSBCMD)%3B%3CBR%20%2F%3EPRINTF(%22USBHSH-%26gt%3BPORTMODE%3A%200x%2508lX%5Cr%5Cn%22%2C%20USBHSH-%26gt%3BPORTMODE)%3B%3C%2FP%3E%3CP%3E%2F*%202.%20Re-sync%20the%20clock%20tree%20variables%20*%2F%3CBR%20%2F%3ESystemCoreClockUpdate()%3B%3C%2FP%3E%3CP%3E%2F*%203.%20Manually%20toggle%20the%20USB1%20Clock%20Gate%20*%2F%3CBR%20%2F%3E%2F%2F%20SYSCON-%26gt%3BAHBCLKCTRLSET%5B2%5D%20%3D%20(1U%20%26lt%3B%26lt%3B%2018)%3B%20%2F%2F%20Ensure%20AHB%20is%20on%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Estatus_t%20clkStatus%20%3D%20CLOCK_EnableUsbhs0HostClock(kCLOCK_UsbSrcUsbPll%2C%2048000000U)%3B%3CBR%20%2F%3EPRINTF(%22Clock%20enable%20returned%3A%20%25d%5Cr%5Cn%22%2C%20clkStatus)%3B%3C%2FP%3E%3CP%3EPRINTF(%22USB%20PLL%20freq%20%3D%20%25lu%20Hz%5Cr%5Cn%22%2C%20CLOCK_GetFreq(kCLOCK_UsbPll))%3B%3CBR%20%2F%3EPRINTF(%22USB1CLK%20freq%20%3D%20%25lu%20Hz%5Cr%5Cn%22%2C%20CLOCK_GetFreq(kCLOCK_UsbClk))%3B%3C%2FP%3E%3CP%3E%2F*%206.%20STACK%20INIT%20*%2F%3CBR%20%2F%3Eusb_status_t%20status%20%3D%20USB_HostInit(CONTROLLER_ID%2C%20%26amp%3Bg_HostHandle%2C%20USB_HostEvent)%3B%3CBR%20%2F%3Eif%20(status%20!%3D%20kStatus_USB_Success)%20%7B%3CBR%20%2F%3EPRINTF(%22USB_HostInit%20failed%20with%20status%20%25d%5Cr%5Cn%22%2C%20status)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2366944%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20LPC54605J256BD100%20Won't%20attach%20USB%20clock%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2366944%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThanks%20Alice.%26nbsp%3B%20I%20have%20managed%20to%20piece%20together%20usb%20host%20init%2C%20from%20the%20files%20in%20the%20xx628%20host%20hid%20generic%20example.%3C%2FP%3E%3CP%3Ethanks%20very%20much%2C%20regards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2366871%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20LPC54605J256BD100%20Won't%20attach%20USB%20clock%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2366871%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F262626%22%20target%3D%22_blank%22%3E%40SOOTY1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3EPlease%20test%20the%20SDK%20demo%20on%20your%20board.%3C%2FDIV%3E%0A%3CDIV%3EThere%20is%20a%20guide%20available%20on%20how%20to%20switch%20the%20USB%20demo%20from%20USB0%20to%20USB1.%3C%2FDIV%3E%0A%3CDIV%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FLPC-Microcontrollers-Knowledge%2FLPC-ALL-Summary-of-Switching-USB-demo-from-USB0-to-USB1%2Fta-p%2F1428522%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FLPC-Microcontrollers-Knowledge%2FLPC-ALL-Summary-of-Switching-USB-demo-from-USB0-to-USB1%2Fta-p%2F1428522%3C%2FA%3E%26nbsp%3B%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EBR%3C%2FDIV%3E%0A%3CDIV%3EAlice%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E