From 82e960b6426f2287345e75cdfbe885d2c014f669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Fri, 23 Feb 2018 17:13:53 +0100 Subject: [PATCH] kinetis: Set LPUART clock source during uart_lpuart_init --- cpu/kinetis/include/cpu_conf_kinetis.h | 5 +++++ cpu/kinetis/periph/uart.c | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cpu/kinetis/include/cpu_conf_kinetis.h b/cpu/kinetis/include/cpu_conf_kinetis.h index 0a7aee7262..49c41f9318 100644 --- a/cpu/kinetis/include/cpu_conf_kinetis.h +++ b/cpu/kinetis/include/cpu_conf_kinetis.h @@ -72,6 +72,11 @@ extern "C" #if !defined(OSC0) && defined(OSC) #define OSC0 OSC #endif +#if !defined(SIM_SOPT2_LPUART0SRC_MASK) && defined(SIM_SOPT2_LPUARTSRC_MASK) +#define SIM_SOPT2_LPUART0SRC_MASK SIM_SOPT2_LPUARTSRC_MASK +#define SIM_SOPT2_LPUART0SRC_SHIFT SIM_SOPT2_LPUARTSRC_SHIFT +#define SIM_SOPT2_LPUART0SRC SIM_SOPT2_LPUARTSRC +#endif #if !defined(SIM_SCGC5_LPTMR_SHIFT) && defined(SIM_SCGC5_LPTIMER_SHIFT) #define SIM_SCGC5_LPTMR_SHIFT SIM_SCGC5_LPTIMER_SHIFT #endif diff --git a/cpu/kinetis/periph/uart.c b/cpu/kinetis/periph/uart.c index 64bca7cbef..50d8529819 100644 --- a/cpu/kinetis/periph/uart.c +++ b/cpu/kinetis/periph/uart.c @@ -63,6 +63,15 @@ #define LPUART_OVERSAMPLING_RATE (16) #endif +/* Default LPUART clock setting to avoid compilation failures, define this in + * periph_conf.h to set board specific configuration if using the LPUART. */ +#ifndef LPUART_0_SRC +#define LPUART_0_SRC 0 +#endif +#ifndef LPUART_1_SRC +#define LPUART_1_SRC 0 +#endif + /** * @brief Runtime configuration space, holds pointers to callback functions for RX */ @@ -296,7 +305,19 @@ static inline void uart_init_lpuart(uart_t uart, uint32_t baudrate) LPUART_Type *dev = uart_config[uart].dev; uint32_t clk = uart_config[uart].freq; - /* Remember to select a module clock in board_init! (SIM->SOPT2[LPUART0SRC]) */ + /* Set LPUART clock source */ +#ifdef SIM_SOPT2_LPUART0SRC + if (dev == LPUART0) { + SIM->SOPT2 = (SIM->SOPT2 & ~SIM_SOPT2_LPUART0SRC_MASK) | + SIM_SOPT2_LPUART0SRC(LPUART_0_SRC); + } +#endif +#ifdef SIM_SOPT2_LPUART1SRC + if (dev == LPUART1) { + SIM->SOPT2 = (SIM->SOPT2 & ~SIM_SOPT2_LPUART1SRC_MASK) | + SIM_SOPT2_LPUART1SRC(LPUART_1_SRC); + } +#endif /* Select mode */ /* transmitter and receiver disabled */