From 6d80d25b7660cf899829cefc640b6871e7adad02 Mon Sep 17 00:00:00 2001 From: utzig Date: Thu, 7 Aug 2014 02:42:07 +0000 Subject: [KINETIS] Fix K20 serial driver git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7149 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/KINETIS/K20x/serial_lld.c | 40 ++++++---------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) (limited to 'os') diff --git a/os/hal/ports/KINETIS/K20x/serial_lld.c b/os/hal/ports/KINETIS/K20x/serial_lld.c index 921613315..9c038896e 100644 --- a/os/hal/ports/KINETIS/K20x/serial_lld.c +++ b/os/hal/ports/KINETIS/K20x/serial_lld.c @@ -105,9 +105,6 @@ static void serve_interrupt(SerialDriver *sdp) { u->D = b; } } - - while (u->S1) - (void)u->D; } /** @@ -160,41 +157,18 @@ static void notify3(io_queue_t *qp) */ static void configure_uart(UART_TypeDef *uart, const SerialConfig *config) { - uint16_t sbr, brfa; - uint32_t clock; + uint32_t divisor = (KINETIS_SYSCLK_FREQUENCY * 2 + 1) / config->sc_speed; /* Disable UART while configuring */ uart->C2 &= ~(UARTx_C2_RE | UARTx_C2_TE); uart->C1 = 0; - //while (uart->S1 & UARTx_S1_RDRF) { - // (void)uart->D; - //} - - clock = KINETIS_SYSCLK_FREQUENCY / 4; - - sbr = (uint16_t) clock / (config->sc_speed * 16); - brfa = (uint16_t) (2 * clock * config->sc_speed) - (sbr * 32); - - //uart->BDH = UARTx_BDH_SBR(sbr >> 8) | (uart->BDH & ~UARTx_BDH_SBR_MASK); - uart->BDH = 0; - uart->BDL = sbr; - uart->C4 = UARTx_C4_BRFA(brfa) | (uart->C4 & ~UARTx_C4_BRFA_MASK); - - uart->TWFIFO = 1; - uart->RWFIFO = 1; - - //uart->C2 |= UARTx_C2_RE | UARTx_C2_RIE | UARTx_C2_TE; - uart->C2 |= UARTx_C2_RE | UARTx_C2_TE; - uart->C3 = 0; - while (!(uart->S1 & UARTx_S1_TDRE)); - uart->D = '1'; - while (!(uart->S1 & UARTx_S1_TDRE)); - uart->D = '2'; - while (!(uart->S1 & UARTx_S1_TDRE)); - uart->D = '3'; + uart->BDH = UARTx_BDH_SBR(divisor >> 13) | (uart->BDH & ~UARTx_BDH_SBR_MASK); + uart->BDL = divisor >> 5; + uart->C4 = UARTx_C4_BRFA(divisor) | (uart->C4 & ~UARTx_C4_BRFA_MASK); - //uart->C3 = UARTx_C3_ORIE | UARTx_C3_NEIE | UARTx_C3_FEIE | UARTx_C3_PEIE; + uart->C2 |= UARTx_C2_RE | UARTx_C2_RIE | UARTx_C2_TE; + uart->C3 = UARTx_C3_ORIE | UARTx_C3_NEIE | UARTx_C3_FEIE | UARTx_C3_PEIE; } /*===========================================================================*/ @@ -286,7 +260,7 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) { if (sdp == &SD1) { SIM->SCGC4 |= SIM_SCGC4_UART0; configure_uart(sdp->uart, config); - //nvicEnableVector(UART0Status_IRQn, KINETIS_SERIAL_UART0_PRIORITY); + nvicEnableVector(UART0Status_IRQn, KINETIS_SERIAL_UART0_PRIORITY); } #endif /* KINETIS_SERIAL_USE_UART0 */ -- cgit v1.2.3