@@ -90,10 +90,39 @@ static uart_irq_handler irq_handler;
90
90
int stdio_uart_inited = 0 ;
91
91
serial_t stdio_uart ;
92
92
93
+ static int check_duplication (serial_t * obj , PinName tx , PinName rx )
94
+ {
95
+ if (uart_used == 0 )
96
+ return 0 ;
97
+
98
+ const SWM_Map * swm ;
99
+ uint32_t assigned_tx , assigned_rx ;
100
+ int ch ;
101
+ for (ch = 0 ; ch < UART_NUM ; ch ++ ) {
102
+ // read assigned TX in the UART channel of switch matrix
103
+ swm = & SWM_UART_TX [ch ];
104
+ assigned_tx = LPC_SWM -> PINASSIGN [swm -> n ] & (0xFF << swm -> offset );
105
+ assigned_tx = assigned_tx >> swm -> offset ;
106
+ // read assigned RX in the UART channel of switch matrix
107
+ swm = & SWM_UART_RX [ch ];
108
+ assigned_rx = LPC_SWM -> PINASSIGN [swm -> n ] & (0xFF << swm -> offset );
109
+ assigned_rx = assigned_rx >> swm -> offset ;
110
+ if ((assigned_tx == (uint32_t )(tx >> PIN_SHIFT )) && (assigned_rx == (uint32_t )(rx >> PIN_SHIFT ))) {
111
+ obj -> index = ch ;
112
+ obj -> uart = (LPC_USART0_Type * )(LPC_USART0_BASE + (0x4000 * ch ));
113
+ return 1 ;
114
+ }
115
+ }
116
+ return 0 ;
117
+ }
118
+
93
119
void serial_init (serial_t * obj , PinName tx , PinName rx )
94
120
{
95
121
int is_stdio_uart = 0 ;
96
122
123
+ if (check_duplication (obj , tx , rx ) == 1 )
124
+ return ;
125
+
97
126
int uart_n = get_available_uart ();
98
127
if (uart_n == -1 ) {
99
128
error ("No available UART" );
@@ -192,7 +221,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
192
221
stop_bits -= 1 ;
193
222
data_bits -= 7 ;
194
223
195
- int paritysel ;
224
+ int paritysel = 0 ;
196
225
switch (parity ) {
197
226
case ParityNone : paritysel = 0 ; break ;
198
227
case ParityEven : paritysel = 2 ; break ;
0 commit comments