@@ -64,29 +64,13 @@ void board_init(void) {
6464 Chip_GPIO_SetPinDIROutput (LPC_GPIO , LED_PORT , LED_PIN );
6565 Chip_GPIO_SetPinDIRInput (LPC_GPIO , BUTTON_PORT , BUTTON_PIN );
6666
67- #if 0
6867 //------------- UART -------------//
69- PINSEL_CFG_Type PinCfg =
70- {
71- .Portnum = 0 ,
72- .Pinnum = 0 , // TXD is P0.0
73- .Funcnum = 2 ,
74- .OpenDrain = 0 ,
75- .Pinmode = 0
76- };
77- PINSEL_ConfigPin (& PinCfg );
78-
79- PinCfg .Portnum = 0 ;
80- PinCfg .Pinnum = 1 ; // RXD is P0.1
81- PINSEL_ConfigPin (& PinCfg );
82-
83- UART_CFG_Type UARTConfigStruct ;
84- UART_ConfigStructInit (& UARTConfigStruct );
85- UARTConfigStruct .Baud_rate = CFG_BOARD_UART_BAUDRATE ;
86-
87- UART_Init (BOARD_UART_PORT , & UARTConfigStruct );
88- UART_TxCmd (BOARD_UART_PORT , ENABLE ); // Enable UART Transmit
89- #endif
68+ // Pin muxing for UART3 (TXD3=P0.0, RXD3=P0.1) is configured in board.h pinmuxing[]
69+ Chip_UART_Init (BOARD_UART_PORT );
70+ Chip_UART_SetBaud (BOARD_UART_PORT , CFG_BOARD_UART_BAUDRATE );
71+ Chip_UART_ConfigData (BOARD_UART_PORT , (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS ));
72+ Chip_UART_SetupFIFOS (BOARD_UART_PORT , (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0 ));
73+ Chip_UART_TXEnable (BOARD_UART_PORT );
9074
9175 //------------- USB -------------//
9276 Chip_IOCON_SetPinMuxing (LPC_IOCON , pin_usb_mux , sizeof (pin_usb_mux ) / sizeof (PINMUX_GRP_T ));
@@ -125,17 +109,30 @@ uint32_t board_button_read(void) {
125109}
126110
127111int board_uart_read (uint8_t * buf , int len ) {
128- // return UART_ReceiveByte(BOARD_UART_PORT);
129- (void ) buf ;
130- (void ) len ;
131- return 0 ;
112+ int count = 0 ;
113+ while (count < len ) {
114+ if (BOARD_UART_PORT -> LSR & UART_LSR_RDR ) {
115+ buf [count ] = (uint8_t ) BOARD_UART_PORT -> RBR ;
116+ count ++ ;
117+ } else {
118+ break ;
119+ }
120+ }
121+ return count ;
132122}
133123
134124int board_uart_write (void const * buf , int len ) {
135- // UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
136- (void ) buf ;
137- (void ) len ;
138- return 0 ;
125+ const uint8_t * p = (const uint8_t * ) buf ;
126+ int count = 0 ;
127+ while (count < len ) {
128+ if (BOARD_UART_PORT -> LSR & UART_LSR_THRE ) {
129+ BOARD_UART_PORT -> THR = p [count ];
130+ count ++ ;
131+ } else {
132+ break ;
133+ }
134+ }
135+ return count ;
139136}
140137
141138#if CFG_TUSB_OS == OPT_OS_NONE
0 commit comments