Skip to content

Commit

Permalink
kinetis: Add support for LPUART module in parallel with UART module
Browse files Browse the repository at this point in the history
A dispatcher function is implemented for directing writes to the correct
function. The dispatcher is bypassed completely if the CPU only contain
one kind of UART module.

There are at least two different UART hardware modules deployed in
different Kinetis CPU families (or possibly three or more when counting
variations of the UART module). The UART module is an older 8 bit module
with advanced functionality, while the LPUART is a 32 bit module with
focus on low power consumption.

 - The older families in the K series all have UART modules.
 - The K22F family have both UART and LPUART modules in the same CPU.
 - Older L series (e.g. KL25Z) have two variations of the UART module
 - Newer L series (e.g. KL43Z) have LPUART modules, and sometimes
   UART as well.
 - Newer W series (KW41Z) have only LPUART
  • Loading branch information
Joakim Nohlgård committed Jul 22, 2017
1 parent 5d04def commit 318abd9
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 48 deletions.
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 @@ -93,6 +93,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 @@ -89,7 +89,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 @@ -105,7 +105,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 @@ -117,7 +118,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 @@ -91,7 +91,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 @@ -103,7 +104,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
11 changes: 10 additions & 1 deletion cpu/kinetis_common/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,19 @@ enum {
#define TIMER_LPTMR_DEV(x) (TIMER_DEV(PIT_NUMOF + (x)))
/** @} */

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

/**
* @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 @@ -321,6 +329,7 @@ typedef struct {
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 */
uint8_t type; /**< Hardware module type (KINETIS_UART or KINETIS_LPUART)*/
} uart_conf_t;

/**
Expand Down
Loading

0 comments on commit 318abd9

Please sign in to comment.