![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
USB Host Lite downloaded from NXP web site. Untested! Compiled, dropped on MBED, booted up, and get the console message that it is initializing the stack. I however do not have the ability to connect a USB Memory device to test it.
Uart/usbhost_uart.c@0:0826fcc5d020, 2010-01-13 (annotated)
- Committer:
- mshoemaker
- Date:
- Wed Jan 13 01:29:30 2010 +0000
- Revision:
- 0:0826fcc5d020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mshoemaker | 0:0826fcc5d020 | 1 | /* |
mshoemaker | 0:0826fcc5d020 | 2 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 3 | * NXP USB Host Stack |
mshoemaker | 0:0826fcc5d020 | 4 | * |
mshoemaker | 0:0826fcc5d020 | 5 | * (c) Copyright 2008, NXP SemiConductors |
mshoemaker | 0:0826fcc5d020 | 6 | * (c) Copyright 2008, OnChip Technologies LLC |
mshoemaker | 0:0826fcc5d020 | 7 | * All Rights Reserved |
mshoemaker | 0:0826fcc5d020 | 8 | * |
mshoemaker | 0:0826fcc5d020 | 9 | * www.nxp.com |
mshoemaker | 0:0826fcc5d020 | 10 | * www.onchiptech.com |
mshoemaker | 0:0826fcc5d020 | 11 | * |
mshoemaker | 0:0826fcc5d020 | 12 | * File : usbhost_uart.c |
mshoemaker | 0:0826fcc5d020 | 13 | * Programmer(s) : Prasad.K.R.S.V |
mshoemaker | 0:0826fcc5d020 | 14 | * Version : |
mshoemaker | 0:0826fcc5d020 | 15 | * |
mshoemaker | 0:0826fcc5d020 | 16 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 17 | */ |
mshoemaker | 0:0826fcc5d020 | 18 | |
mshoemaker | 0:0826fcc5d020 | 19 | /* |
mshoemaker | 0:0826fcc5d020 | 20 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 21 | * INCLUDE HEADER FILES |
mshoemaker | 0:0826fcc5d020 | 22 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 23 | */ |
mshoemaker | 0:0826fcc5d020 | 24 | |
mshoemaker | 0:0826fcc5d020 | 25 | #include "usbhost_uart.h" |
mshoemaker | 0:0826fcc5d020 | 26 | |
mshoemaker | 0:0826fcc5d020 | 27 | /* |
mshoemaker | 0:0826fcc5d020 | 28 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 29 | * INITIALIZE UART |
mshoemaker | 0:0826fcc5d020 | 30 | * |
mshoemaker | 0:0826fcc5d020 | 31 | * Description: This function initializes UART port, setup pin select, clock, parity, stopbits, FIFO etc |
mshoemaker | 0:0826fcc5d020 | 32 | * |
mshoemaker | 0:0826fcc5d020 | 33 | * Arguments : baud_rate UART baud rate (115200) |
mshoemaker | 0:0826fcc5d020 | 34 | * |
mshoemaker | 0:0826fcc5d020 | 35 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 36 | * |
mshoemaker | 0:0826fcc5d020 | 37 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 38 | */ |
mshoemaker | 0:0826fcc5d020 | 39 | |
mshoemaker | 0:0826fcc5d020 | 40 | void UART_Init(USB_INT32U baudrate) |
mshoemaker | 0:0826fcc5d020 | 41 | { |
mshoemaker | 0:0826fcc5d020 | 42 | USB_INT32U Fdiv; |
mshoemaker | 0:0826fcc5d020 | 43 | USB_INT32U pclkdiv, pclk; |
mshoemaker | 0:0826fcc5d020 | 44 | uint32_t SystemFrequency = SystemCoreClock; |
mshoemaker | 0:0826fcc5d020 | 45 | |
mshoemaker | 0:0826fcc5d020 | 46 | LPC_PINCON->PINSEL0 |= 0x00000050; /* RxD0 and TxD0 */ |
mshoemaker | 0:0826fcc5d020 | 47 | |
mshoemaker | 0:0826fcc5d020 | 48 | LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ |
mshoemaker | 0:0826fcc5d020 | 49 | /* Bit 6~7 is for UART0 clock divider. */ |
mshoemaker | 0:0826fcc5d020 | 50 | pclkdiv = (LPC_SC->PCLKSEL0 >> 6) & 0x03; |
mshoemaker | 0:0826fcc5d020 | 51 | switch ( pclkdiv ) |
mshoemaker | 0:0826fcc5d020 | 52 | { |
mshoemaker | 0:0826fcc5d020 | 53 | case 0x00: |
mshoemaker | 0:0826fcc5d020 | 54 | default: |
mshoemaker | 0:0826fcc5d020 | 55 | pclk = SystemFrequency/4; |
mshoemaker | 0:0826fcc5d020 | 56 | break; |
mshoemaker | 0:0826fcc5d020 | 57 | case 0x01: |
mshoemaker | 0:0826fcc5d020 | 58 | pclk = SystemFrequency; |
mshoemaker | 0:0826fcc5d020 | 59 | break; |
mshoemaker | 0:0826fcc5d020 | 60 | case 0x02: |
mshoemaker | 0:0826fcc5d020 | 61 | pclk = SystemFrequency/2; |
mshoemaker | 0:0826fcc5d020 | 62 | break; |
mshoemaker | 0:0826fcc5d020 | 63 | case 0x03: |
mshoemaker | 0:0826fcc5d020 | 64 | pclk = SystemFrequency/8; |
mshoemaker | 0:0826fcc5d020 | 65 | break; |
mshoemaker | 0:0826fcc5d020 | 66 | } |
mshoemaker | 0:0826fcc5d020 | 67 | Fdiv = ( pclk / 16 ) / baudrate ; /*baud rate */ |
mshoemaker | 0:0826fcc5d020 | 68 | |
mshoemaker | 0:0826fcc5d020 | 69 | LPC_UART0->DLM = Fdiv / 256; |
mshoemaker | 0:0826fcc5d020 | 70 | LPC_UART0->DLL = Fdiv % 256; |
mshoemaker | 0:0826fcc5d020 | 71 | LPC_UART0->LCR = 0x03; /* DLAB = 0 */ |
mshoemaker | 0:0826fcc5d020 | 72 | LPC_UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ |
mshoemaker | 0:0826fcc5d020 | 73 | } |
mshoemaker | 0:0826fcc5d020 | 74 | |
mshoemaker | 0:0826fcc5d020 | 75 | /* |
mshoemaker | 0:0826fcc5d020 | 76 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 77 | * PRINT CHARECTER |
mshoemaker | 0:0826fcc5d020 | 78 | * |
mshoemaker | 0:0826fcc5d020 | 79 | * Description: This function is used to print a single charecter through UART1. |
mshoemaker | 0:0826fcc5d020 | 80 | * |
mshoemaker | 0:0826fcc5d020 | 81 | * Arguments : ch charecter to be printed |
mshoemaker | 0:0826fcc5d020 | 82 | * |
mshoemaker | 0:0826fcc5d020 | 83 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 84 | * |
mshoemaker | 0:0826fcc5d020 | 85 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 86 | */ |
mshoemaker | 0:0826fcc5d020 | 87 | |
mshoemaker | 0:0826fcc5d020 | 88 | void UART_PrintChar (USB_INT08U ch) |
mshoemaker | 0:0826fcc5d020 | 89 | { |
mshoemaker | 0:0826fcc5d020 | 90 | |
mshoemaker | 0:0826fcc5d020 | 91 | while (!(LPC_UART0->LSR & 0x20)); |
mshoemaker | 0:0826fcc5d020 | 92 | LPC_UART0->THR = ch; |
mshoemaker | 0:0826fcc5d020 | 93 | } |
mshoemaker | 0:0826fcc5d020 | 94 | |
mshoemaker | 0:0826fcc5d020 | 95 | /* |
mshoemaker | 0:0826fcc5d020 | 96 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 97 | * PRINT STRING |
mshoemaker | 0:0826fcc5d020 | 98 | * |
mshoemaker | 0:0826fcc5d020 | 99 | * Description: This function is used to print a string |
mshoemaker | 0:0826fcc5d020 | 100 | * |
mshoemaker | 0:0826fcc5d020 | 101 | * Arguments : str Pointer to the string |
mshoemaker | 0:0826fcc5d020 | 102 | * |
mshoemaker | 0:0826fcc5d020 | 103 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 104 | * |
mshoemaker | 0:0826fcc5d020 | 105 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 106 | */ |
mshoemaker | 0:0826fcc5d020 | 107 | |
mshoemaker | 0:0826fcc5d020 | 108 | void UART_PrintStr (const USB_INT08U * str) |
mshoemaker | 0:0826fcc5d020 | 109 | { |
mshoemaker | 0:0826fcc5d020 | 110 | |
mshoemaker | 0:0826fcc5d020 | 111 | while ((*str) != 0) { |
mshoemaker | 0:0826fcc5d020 | 112 | if (*str == '\n') { |
mshoemaker | 0:0826fcc5d020 | 113 | UART_PrintChar(*str++); |
mshoemaker | 0:0826fcc5d020 | 114 | UART_PrintChar('\r'); |
mshoemaker | 0:0826fcc5d020 | 115 | } else { |
mshoemaker | 0:0826fcc5d020 | 116 | UART_PrintChar(*str++); |
mshoemaker | 0:0826fcc5d020 | 117 | } |
mshoemaker | 0:0826fcc5d020 | 118 | } |
mshoemaker | 0:0826fcc5d020 | 119 | } |
mshoemaker | 0:0826fcc5d020 | 120 | |
mshoemaker | 0:0826fcc5d020 | 121 | /* |
mshoemaker | 0:0826fcc5d020 | 122 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 123 | * PRINT FORMATTED STRING |
mshoemaker | 0:0826fcc5d020 | 124 | * |
mshoemaker | 0:0826fcc5d020 | 125 | * Description: This function is used to print formatted string. This function takes variable length arguments |
mshoemaker | 0:0826fcc5d020 | 126 | * |
mshoemaker | 0:0826fcc5d020 | 127 | * Arguments : variable length arguments |
mshoemaker | 0:0826fcc5d020 | 128 | * |
mshoemaker | 0:0826fcc5d020 | 129 | * Returns : None |
mshoemaker | 0:0826fcc5d020 | 130 | * |
mshoemaker | 0:0826fcc5d020 | 131 | ************************************************************************************************************** |
mshoemaker | 0:0826fcc5d020 | 132 | */ |
mshoemaker | 0:0826fcc5d020 | 133 | |
mshoemaker | 0:0826fcc5d020 | 134 | void UART_Printf (const USB_INT08U *format, ...) |
mshoemaker | 0:0826fcc5d020 | 135 | { |
mshoemaker | 0:0826fcc5d020 | 136 | static USB_INT08U buffer[40 + 1]; |
mshoemaker | 0:0826fcc5d020 | 137 | va_list vArgs; |
mshoemaker | 0:0826fcc5d020 | 138 | |
mshoemaker | 0:0826fcc5d020 | 139 | |
mshoemaker | 0:0826fcc5d020 | 140 | va_start(vArgs, format); |
mshoemaker | 0:0826fcc5d020 | 141 | vsprintf((char *)buffer, (char const *)format, vArgs); |
mshoemaker | 0:0826fcc5d020 | 142 | va_end(vArgs); |
mshoemaker | 0:0826fcc5d020 | 143 | UART_PrintStr((USB_INT08U*) buffer); |
mshoemaker | 0:0826fcc5d020 | 144 | } |