@@ -84,13 +84,13 @@ static struct serial_global_data_s uart_data[UART_NUM];
84
84
85
85
void serial_init (serial_t * obj , PinName tx , PinName rx ) {
86
86
int is_stdio_uart = 0 ;
87
-
87
+
88
88
// determine the UART to use
89
89
UARTName uart_tx = (UARTName )pinmap_peripheral (tx , PinMap_UART_TX );
90
90
UARTName uart_rx = (UARTName )pinmap_peripheral (rx , PinMap_UART_RX );
91
91
UARTName uart = (UARTName )pinmap_merge (uart_tx , uart_rx );
92
92
MBED_ASSERT ((int )uart != NC );
93
-
93
+
94
94
obj -> uart = (LPC_UART_TypeDef * )uart ;
95
95
// enable power
96
96
switch (uart ) {
@@ -110,19 +110,19 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
110
110
obj -> uart -> IER = 0 << 0 // Rx Data available irq enable
111
111
| 0 << 1 // Tx Fifo empty irq enable
112
112
| 0 << 2 ; // Rx Line Status irq enable
113
-
113
+
114
114
// set default baud rate and format
115
115
serial_baud (obj , 9600 );
116
116
serial_format (obj , 8 , ParityNone , 1 );
117
-
117
+
118
118
// pinout the chosen uart
119
119
pinmap_pinout (tx , PinMap_UART_TX );
120
120
pinmap_pinout (rx , PinMap_UART_RX );
121
-
121
+
122
122
// set rx/tx pins in PullUp mode
123
123
pin_mode (tx , PullUp );
124
124
pin_mode (rx , PullUp );
125
-
125
+
126
126
switch (uart ) {
127
127
case UART_0 : obj -> index = 0 ; break ;
128
128
case UART_1 : obj -> index = 1 ; break ;
@@ -132,9 +132,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
132
132
uart_data [obj -> index ].sw_rts .pin = NC ;
133
133
uart_data [obj -> index ].sw_cts .pin = NC ;
134
134
serial_set_flow_control (obj , FlowControlNone , NC , NC );
135
-
135
+
136
136
is_stdio_uart = (uart == STDIO_UART ) ? (1 ) : (0 );
137
-
137
+
138
138
if (is_stdio_uart ) {
139
139
stdio_uart_inited = 1 ;
140
140
memcpy (& stdio_uart , obj , sizeof (serial_t ));
@@ -166,9 +166,9 @@ void serial_baud(serial_t *obj, int baudrate) {
166
166
case UART_3 : LPC_SC -> PCLKSEL1 &= ~(0x3 << 18 ); LPC_SC -> PCLKSEL1 |= (0x1 << 18 ); break ;
167
167
default : break ;
168
168
}
169
-
169
+
170
170
uint32_t PCLK = SystemCoreClock ;
171
-
171
+
172
172
// First we check to see if the basic divide with no DivAddVal/MulVal
173
173
// ratio gives us an integer result. If it does, we set DivAddVal = 0,
174
174
// MulVal = 1. Otherwise, we search the valid ratio value range to find
@@ -229,16 +229,16 @@ void serial_baud(serial_t *obj, int baudrate) {
229
229
}
230
230
}
231
231
}
232
-
232
+
233
233
// set LCR[DLAB] to enable writing to divider registers
234
234
obj -> uart -> LCR |= (1 << 7 );
235
-
235
+
236
236
// set divider values
237
237
obj -> uart -> DLM = (DL >> 8 ) & 0xFF ;
238
238
obj -> uart -> DLL = (DL >> 0 ) & 0xFF ;
239
239
obj -> uart -> FDR = (uint32_t ) DivAddVal << 0
240
240
| (uint32_t ) MulVal << 4 ;
241
-
241
+
242
242
// clear LCR[DLAB]
243
243
obj -> uart -> LCR &= ~(1 << 7 );
244
244
}
@@ -260,9 +260,10 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
260
260
case ParityForced1 : parity_enable = 1 ; parity_select = 2 ; break ;
261
261
case ParityForced0 : parity_enable = 1 ; parity_select = 3 ; break ;
262
262
default :
263
+ parity_enable = 0 , parity_select = 0 ;
263
264
break ;
264
265
}
265
-
266
+
266
267
obj -> uart -> LCR = data_bits << 0
267
268
| stop_bits << 2
268
269
| parity_enable << 3
@@ -310,7 +311,7 @@ static void serial_irq_set_internal(serial_t *obj, SerialIrq irq, uint32_t enabl
310
311
case UART_2 : irq_n = UART2_IRQn ; vector = (uint32_t )& uart2_irq ; break ;
311
312
case UART_3 : irq_n = UART3_IRQn ; vector = (uint32_t )& uart3_irq ; break ;
312
313
}
313
-
314
+
314
315
if (enable ) {
315
316
obj -> uart -> IER |= 1 << irq ;
316
317
NVIC_SetVector (irq_n , vector );
0 commit comments