diff --git a/cpu/kinetis_common/include/periph_cpu.h b/cpu/kinetis_common/include/periph_cpu.h index 0678a1b0ae4fe..dbc4cf84ab618 100644 --- a/cpu/kinetis_common/include/periph_cpu.h +++ b/cpu/kinetis_common/include/periph_cpu.h @@ -205,16 +205,28 @@ typedef enum { #endif /* ndef DOXYGEN */ /** - * @name CPU specific UART modes values - * @{ + * @brief UART transmission modes */ -/** @brief 8 data bits, no parity, 1 stop bit */ -#define UART_MODE_8N1 (0) -/** @brief 8 data bits, even parity, 1 stop bit */ -#define UART_MODE_8E1 (UART_C1_PE_MASK | UART_C1_M_MASK) -/** @brief 8 data bits, odd parity, 1 stop bit */ -#define UART_MODE_8O1 (UART_C1_PE_MASK | UART_C1_M_MASK | UART_C1_PT_MASK) -/** @} */ +typedef enum { + /** @brief 8 data bits, no parity, 1 stop bit */ + UART_MODE_8N1 = 0, + /** @brief 8 data bits, even parity, 1 stop bit */ +#if defined(UART_C1_M_MASK) + /* LPUART and UART mode bits coincide, so the same setting for UART works on + * the LPUART as well */ + UART_MODE_8E1 = (UART_C1_M_MASK | UART_C1_PE_MASK), +#elif defined(LPUART_CTRL_M_MASK) + /* For CPUs which only have the LPUART */ + UART_MODE_8E1 = (LPUART_CTRL_M_MASK | LPUART_CTRL_PE_MASK), +#endif + /** @brief 8 data bits, odd parity, 1 stop bit */ +#if defined(UART_C1_M_MASK) + UART_MODE_8O1 = (UART_C1_M_MASK | UART_C1_PE_MASK | UART_C1_PT_MASK), +#elif defined(LPUART_CTRL_M_MASK) + /* For CPUs which only have the LPUART */ + UART_MODE_8O1 = (LPUART_CTRL_M_MASK | LPUART_CTRL_PE_MASK | LPUART_CTRL_PT_MASK), +#endif +} uart_mode_t; #ifndef DOXYGEN /** @@ -336,7 +348,7 @@ typedef struct { IRQn_Type irqn; /**< IRQ number for this module */ volatile uint32_t *scgc_addr; /**< Clock enable register, in SIM module */ uint8_t scgc_bit; /**< Clock enable bit, within the register */ - uint8_t mode; /**< UART mode: data bits, parity, stop bits */ + uart_mode_t mode; /**< UART mode: data bits, parity, stop bits */ uart_type_t type; /**< Hardware module type (KINETIS_UART or KINETIS_LPUART)*/ } uart_conf_t; diff --git a/cpu/kinetis_common/periph/uart.c b/cpu/kinetis_common/periph/uart.c index 161e9de3bfa5c..1c617dce30780 100644 --- a/cpu/kinetis_common/periph/uart.c +++ b/cpu/kinetis_common/periph/uart.c @@ -162,7 +162,7 @@ static inline void uart_init_uart(uart_t uart, uint32_t baudrate) /* disable transmitter and receiver */ dev->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); - /* set defaults, 8-bit mode, no parity */ + /* Select mode */ dev->C1 = uart_config[uart].mode; /* calculate baudrate */ @@ -295,9 +295,9 @@ static inline void uart_init_lpuart(uart_t uart, uint32_t baudrate) /* Remember to select a module clock in board_init! (SIM->SOPT2[LPUART0SRC]) */ - /* set defaults, 8-bit mode, no parity */ + /* Select mode */ /* transmitter and receiver disabled */ - dev->CTRL = 0; + dev->CTRL = uart_config[uart].mode; /* calculate baud rate divisor */ uint32_t div = clk / (baudrate * LPUART_OVERSAMPLING_RATE); @@ -306,7 +306,8 @@ static inline void uart_init_lpuart(uart_t uart, uint32_t baudrate) dev->BAUD = LPUART_BAUD_OSR(LPUART_OVERSAMPLING_RATE - 1) | LPUART_BAUD_SBR(div); /* enable transmitter and receiver + RX interrupt */ - dev->CTRL = LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK | LPUART_CTRL_RIE_MASK; + dev->CTRL |= LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK | LPUART_CTRL_RIE_MASK; + /* enable receive interrupt */ NVIC_EnableIRQ(uart_config[uart].irqn); }