int main(void) {
#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate();
// Set up and initialize all required blocks and
// functions related to the board hardware
Board_Init();
// Set the LED to the state of "On"
Board_LED_Set(0, true);
#endif
#endif
uint32_t sarasa = 0;
while(sarasa < 10000)
sarasa++;
SystemCoreClockUpdate();
USBD_API_INIT_PARAM_T usb_param;
USB_CORE_DESCS_T desc;
ErrorCode_t ret = LPC_OK;
USB_CORE_CTRL_T *pCtrl;
Chip_SCU_PinMuxSet(0x9, 5, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC2));/* P9_5 USB1_VBUS_EN, USB1 VBus function */
Chip_SCU_PinMuxSet(0x2, 5, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2));/* P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION */
Chip_SCU_PinMuxSet(0x6, 3, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1));/* P6_3 USB0_PWR_EN, USB0 VBus function */
Chip_USB1_Init(); //USB_init_pin_clk();
/* Init USB API structure */
g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;
/* initialize call back structures */
memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
usb_param.usb_reg_base = LPC_USB_BASE;
usb_param.max_num_ep = 4;
usb_param.mem_base = USB_STACK_MEM_BASE;
usb_param.mem_size = USB_STACK_MEM_SIZE;
/* Set the USB descriptors */
desc.device_desc = (uint8_t *) USB_DeviceDescriptor;
desc.string_desc = (uint8_t *) USB_StringDescriptor;
#ifdef USE_USB0
desc.high_speed_desc = USB_HsConfigDescriptor;
desc.full_speed_desc = USB_FsConfigDescriptor;
desc.device_qualifier = (uint8_t *) USB_DeviceQualifier;
#else
/* Note, to pass USBCV test full-speed only devices should have both
* descriptor arrays point to same location and device_qualifier set
* to 0.
*/
desc.high_speed_desc = USB_FsConfigDescriptor;
desc.full_speed_desc = USB_FsConfigDescriptor;
desc.device_qualifier = 0;
#endif
ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
if (ret == LPC_OK) {
/*WORKAROUND for artf45032 ROM driver BUG:
Due to a race condition there is the chance that a second NAK event will
occur before the default endpoint0 handler has completed its preparation
of the DMA engine for the first NAK event. This can cause certain fields
in the DMA descriptors to be in an invalid state when the USB controller
reads them, thereby causing a hang.
*/
pCtrl = (USB_CORE_CTRL_T *) g_hUsb;/* convert the handle to control structure */
g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0];/* retrieve the default EP0_OUT handler */
pCtrl->ep_event_hdlr[0] = EP0_patch;/* set our patch routine as EP0_OUT handler */
/* Init UCOM - USB to UART bridge interface */
ret = UCOM_init(g_hUsb, &desc, &usb_param);
if (ret == LPC_OK) {
/* Make sure USB and UART IRQ priorities are same for this example */
NVIC_SetPriority(LPC_USB_IRQ, 1);
/* enable USB interrupts */
NVIC_EnableIRQ(LPC_USB_IRQ);
/* now connect */
USBD_API->hw->Connect(g_hUsb, 1);
}
}
// TODO: insert code here
/* Setup GPIOs for USB demos */
Chip_SCU_PinMuxSet(0x9, 5, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC2));/* P9_5 USB1_VBUS_EN, USB1 VBus function */
Chip_SCU_PinMuxSet(0x2, 5, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2));/* P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION */
Chip_SCU_PinMuxSet(0x6, 3, (SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1));/* P6_3 USB0_PWR_EN, USB0 VBus function */
Chip_SCU_PinMuxSet(0xE, 7, (SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN));
Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 7, 7);
// Force the counter to be placed into memory
volatile static uint32_t i = 0 ;
// Enter an infinite loop, just incrementing a counter
while(1) {
i++ ;
if(i == 500000)
{
Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 7, 7);
i = 0;
}
}
return 0 ;
} |