tinyusb  0.4
Click here to lend your support to tinyusb donation and make a donation at pledgie.com
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
hal_lpc175x_6x.c
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
39 #include "common/common.h"
40 #include "hal.h"
41 
42 #if TUSB_CFG_MCU == MCU_LPC175X_6X
43 
44 #ifdef __CC_ARM
45 #pragma diag_suppress 66 // Suppress Keil warnings #66-D: enumeration value is out of "int" range
46 #endif
47 
48 //--------------------------------------------------------------------+
49 // IMPLEMENTATION
50 //--------------------------------------------------------------------+
52 {
53  enum {
54  USBCLK_DEVCIE = 0x12, // AHB + Device
55  USBCLK_HOST = 0x19, // AHB + Host + OTG (!)
56 
57  PCONP_PCUSB = BIT_(31)
58  };
59 
60  LPC_SC->PCONP |= PCONP_PCUSB; // enable USB Peripherals
61 
62  //------------- user manual 11.13 usb device controller initialization -------------//
63  PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 0, .Pinnum = 29, .Funcnum = 1} ); // P0.29 as D+
64  PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 0, .Pinnum = 30, .Funcnum = 1} ); // P0.30 as D-
65 
66 #if MODE_HOST_SUPPORTED
67  PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 1, .Pinnum = 22, .Funcnum = 2} ); // P1.22 as USB_PWRD
68  PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 1, .Pinnum = 19, .Funcnum = 2} ); // P1.19 as USB_PPWR
69 
70  LPC_USB->USBClkCtrl = USBCLK_HOST;
71  while ((LPC_USB->USBClkSt & USBCLK_HOST) != USBCLK_HOST);
72  LPC_USB->OTGStCtrl = 0x3;
73 #endif
74 
75 #if MODE_DEVICE_SUPPORTED
76  LPC_PINCON->PINSEL4 = bit_set_range(LPC_PINCON->PINSEL4, 18, 19, BIN8(01)); // P2_9 as USB Connect
77 
78  // P1_30 as VBUS, ignore if it is already in VBUS mode
79  if ( !(!BIT_TEST_(LPC_PINCON->PINSEL3, 28) && BIT_TEST_(LPC_PINCON->PINSEL3, 29)) )
80  {
81  // some board like lpcxpresso1769 does not connect VBUS signal to pin P1_30, this allow those board to overwrite
82  // by always pulling P1_30 to high
83  PINSEL_ConfigPin( &(PINSEL_CFG_Type) {
84  .Portnum = 1, .Pinnum = 30,
85  .Funcnum = 2, .Pinmode = PINSEL_PINMODE_PULLDOWN} );
86  }
87 
88  LPC_USB->USBClkCtrl = USBCLK_DEVCIE;
89  while ((LPC_USB->USBClkSt & USBCLK_DEVCIE) != USBCLK_DEVCIE);
90 #endif
91 
92  return TUSB_ERROR_NONE;
93 }
94 
95 void USB_IRQHandler(void)
96 {
97  tusb_isr(0);
98 }
99 
100 #endif
#define BIT_(n)
n-th Bit
Definition: binary.h:54
#define BIT_TEST_(x, n)
check if n-th bit of x is 1
Definition: binary.h:57
tusb_error_t
Error Code returned.
Definition: tusb_errors.h:100
void tusb_isr(uint8_t coreid)
USB interrupt handler.
Definition: tusb.c:71
tusb_error_t hal_init(void)
Initialize USB controller hardware.