Skip to content

Commit

Permalink
kinetis: Set LPUART clock source during uart_lpuart_init
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Nohlgård committed Mar 2, 2018
1 parent 2e701bd commit 82e960b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cpu/kinetis/include/cpu_conf_kinetis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion cpu/kinetis/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 82e960b

Please sign in to comment.