From 2bc9c4299b4121bbe3b603e26c842003a7f10744 Mon Sep 17 00:00:00 2001 From: Toyomasa Watarai Date: Fri, 3 Apr 2015 18:03:31 +0900 Subject: [PATCH] [LPC824] Add UART channel dupilication check - Add check_duplication() function to detect UART duplication which is reported https://github.com/mbedmicro/mbed/issues/942 - Confirmed to pass MBED_A9 test case (Serial Echo at 115200) - Add a variable initialize code to prevent GCC warning --- .../hal/TARGET_NXP/TARGET_LPC82X/serial_api.c | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/serial_api.c index e3dc97e200..a6fa658d04 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/serial_api.c @@ -90,10 +90,39 @@ static uart_irq_handler irq_handler; int stdio_uart_inited = 0; serial_t stdio_uart; +static int check_duplication(serial_t *obj, PinName tx, PinName rx) +{ + if (uart_used == 0) + return 0; + + const SWM_Map *swm; + uint32_t assigned_tx, assigned_rx; + int ch; + for (ch=0; chPINASSIGN[swm->n] & (0xFF << swm->offset); + assigned_tx = assigned_tx >> swm->offset; + // read assigned RX in the UART channel of switch matrix + swm = &SWM_UART_RX[ch]; + assigned_rx = LPC_SWM->PINASSIGN[swm->n] & (0xFF << swm->offset); + assigned_rx = assigned_rx >> swm->offset; + if ((assigned_tx == (uint32_t)(tx >> PIN_SHIFT)) && (assigned_rx == (uint32_t)(rx >> PIN_SHIFT))) { + obj->index = ch; + obj->uart = (LPC_USART0_Type *)(LPC_USART0_BASE + (0x4000 * ch)); + return 1; + } + } + return 0; +} + void serial_init(serial_t *obj, PinName tx, PinName rx) { int is_stdio_uart = 0; + if (check_duplication(obj, tx, rx) == 1) + return; + int uart_n = get_available_uart(); if (uart_n == -1) { error("No available UART"); @@ -192,7 +221,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b stop_bits -= 1; data_bits -= 7; - int paritysel; + int paritysel = 0; switch (parity) { case ParityNone: paritysel = 0; break; case ParityEven: paritysel = 2; break;