Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kinetis: Add support for LPUART module in parallel with UART module #7362

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/frdm-k22f/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static const uart_conf_t uart_config[] = {
.scgc_addr = &SIM->SCGC4,
.scgc_bit = SIM_SCGC4_UART1_SHIFT,
.mode = UART_MODE_8N1,
.type = KINETIS_UART,
},
};

Expand Down
3 changes: 2 additions & 1 deletion boards/frdm-k64f/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static const uart_conf_t uart_config[] = {
.irqn = UART0_RX_TX_IRQn,
.scgc_addr = &SIM->SCGC4,
.scgc_bit = SIM_SCGC4_UART0_SHIFT,
.mode = UART_MODE_8N1
.mode = UART_MODE_8N1,
.type = KINETIS_UART,
},
};

Expand Down
6 changes: 4 additions & 2 deletions boards/mulle/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ static const uart_conf_t uart_config[] = {
.irqn = UART0_RX_TX_IRQn,
.scgc_addr = &SIM->SCGC4,
.scgc_bit = SIM_SCGC4_UART0_SHIFT,
.mode = UART_MODE_8N1
.mode = UART_MODE_8N1,
.type = KINETIS_UART,
},
{
.dev = UART1,
Expand All @@ -129,7 +130,8 @@ static const uart_conf_t uart_config[] = {
.irqn = UART1_RX_TX_IRQn,
.scgc_addr = &SIM->SCGC4,
.scgc_bit = SIM_SCGC4_UART1_SHIFT,
.mode = UART_MODE_8N1
.mode = UART_MODE_8N1,
.type = KINETIS_UART,
},
};

Expand Down
6 changes: 4 additions & 2 deletions boards/pba-d-01-kw2x/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ static const uart_conf_t uart_config[] = {
.irqn = UART2_RX_TX_IRQn,
.scgc_addr = &SIM->SCGC4,
.scgc_bit = SIM_SCGC4_UART2_SHIFT,
.mode = UART_MODE_8N1
.mode = UART_MODE_8N1,
.type = KINETIS_UART,
},
{
.dev = UART0,
Expand All @@ -115,7 +116,8 @@ static const uart_conf_t uart_config[] = {
.irqn = UART0_RX_TX_IRQn,
.scgc_addr = &SIM->SCGC4,
.scgc_bit = SIM_SCGC4_UART0_SHIFT,
.mode = UART_MODE_8N1
.mode = UART_MODE_8N1,
.type = KINETIS_UART,
}
};

Expand Down
43 changes: 32 additions & 11 deletions cpu/kinetis_common/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,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
/**
Expand Down Expand Up @@ -309,11 +321,19 @@ enum {
#define TIMER_LPTMR_DEV(x) (TIMER_DEV(PIT_NUMOF + (x)))
/** @} */

/**
* @brief UART hardware module types
*/
typedef enum {
KINETIS_UART, /**< Kinetis UART module type */
KINETIS_LPUART, /**< Kinetis Low-power UART (LPUART) module type */
} uart_type_t;

/**
* @brief UART module configuration options
*/
typedef struct {
UART_Type *dev; /**< Pointer to module hardware registers */
void *dev; /**< Pointer to module hardware registers */
uint32_t freq; /**< Module clock frequency, usually CLOCK_CORECLOCK or CLOCK_BUSCLOCK */
gpio_t pin_rx; /**< RX pin, GPIO_UNDEF disables RX */
gpio_t pin_tx; /**< TX pin */
Expand All @@ -322,7 +342,8 @@ 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;

#if !defined(KINETIS_HAVE_PLL)
Expand Down
Loading