| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HAL_LPC11Uxx.c
Go to the documentation of this file.
1 /*
2 * @brief HAL USB functions for the LPC11Uxx microcontrollers
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #if (defined(__LPC11U1X__) || defined(__LPC11U2X_3X__) || defined(__LPC1347__))
33
34 #include "../HAL.h"
35 #include "../../USBTask.h"
36
37 void HAL_USBInit(uint8_t corenum)
38 {
39 /* power UP USB Phy and USB PLL */
40 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPAD_PD);
41 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD);
42 #if defined(__LPC1347__)
43 Chip_Clock_SetUSBPllSource(SYSCTL_PLLCLKSRC_SYSOSC);
44 #else
45 Chip_Clock_SetUSBPllSource(SYSCTL_PLLCLKSRC_MAINOSC);
46 #endif
47 //while (!(LPC_SYSCTL->USBPLLCLKUEN & 0x01));
48 Chip_Clock_SetupUSBPLL(3,1);
49 while (!Chip_Clock_IsUSBPLLLocked()) {}
50 Chip_Clock_SetUSBClockSource(SYSCTL_USBCLKSRC_PLLOUT, 1);
51
52 /* Enable AHB clock to the USB block and USB RAM. */
53 LPC_SYSCTL->SYSAHBCLKCTRL |= ((0x1 << 14) | (0x1 << 27));
54
55 LPC_USB->EPBUFCFG = 0x3FC;
56
57 /* configure usb_soft connect */
58 LPC_IOCON->PIO0[6] = 0x01;
59
60 #if !defined(USB_DEVICE_ROM_DRIVER)
61 HAL_Reset();
62 #endif
63 }
64
65 void HAL_USBDeInit(uint8_t corenum, uint8_t mode)
66 {
67 NVIC_DisableIRQ(USB0_IRQn); /* disable USB interrupt */
68 LPC_SYSCTL->SYSAHBCLKCTRL &= ~((0x1 << 14) | (0x1 << 27)); /* disable USB clock */
69 }
70
71 void HAL_EnableUSBInterrupt(uint8_t corenum)
72 {
73 NVIC_EnableIRQ(USB0_IRQn);
74 }
75
76 void HAL_DisableUSBInterrupt(uint8_t corenum)
77 {
78 NVIC_DisableIRQ(USB0_IRQn);
79 }
80
81 void HAL_SetDeviceAddress(uint8_t Address)
82 {
83 #ifdef USB_CAN_BE_DEVICE
84 LPC_USB->DEVCMDSTAT &= ~0x7F;
85 LPC_USB->DEVCMDSTAT |= (USB_EN | Address);
86 #endif
87 }
88
89 void HAL_USBConnect(uint8_t corenum, uint32_t con)
90 {
91 #ifdef USB_CAN_BE_DEVICE
92 if ( con ) {
93 LPC_USB->DEVCMDSTAT |= USB_DCON;
94 }
95 else {
96 LPC_USB->DEVCMDSTAT &= ~USB_DCON;
97 }
98 #endif
99 }
100
101 #endif /*CHIP_LPC11UXX*/