34# define KINETIS_HAVE_PCR
38# define KINETIS_HAVE_PINSEL
41#ifdef ADC_CFG1_MODE_MASK
42# define KINETIS_HAVE_ADC_K
45#ifdef SPI_CTAR_CPHA_MASK
46# define KINETIS_HAVE_MK_SPI
49#ifdef LPTMR_CSR_TEN_MASK
50# define KINETIS_HAVE_LPTMR
58typedef uint16_t gpio_t;
64#define GPIO_UNDEF (0xffff)
69#define GPIO_PIN(x, y) (((x + 1) << 12) | (x << 6) | y)
71#ifdef SIM_UIDH_UID_MASK
76#define CPUID_ADDR (&SIM->UIDH)
81#define CPUID_LEN (16U)
87#define CPUID_ADDR (&SIM->UIDMH)
91#define CPUID_LEN (12U)
103#define GPIO_MODE(pu, pe, od, out) (pu | (pe << 1) | (od << 5) | (out << 7))
111#define SPI_HWCS(x) (x)
116#define SPI_HWCS_NUMOF (5)
121#define SPI_CS_UNDEF (GPIO_UNDEF)
137#define PERIPH_SPI_NEEDS_TRANSFER_BYTE 1
138#define PERIPH_SPI_NEEDS_TRANSFER_REG 1
139#define PERIPH_SPI_NEEDS_TRANSFER_REGS 1
145#define PERIPH_TIMER_PROVIDES_SET
150#define TIMER_CHANNEL_NUMOF 1
156#define PM_NUM_MODES (4U)
168#define PM_BLOCK(x) pm_block(x)
172#define PM_UNBLOCK(x) pm_unblock(x)
185#define HAVE_GPIO_MODE_T
197#ifdef KINETIS_HAVE_PCR
204 GPIO_AF_ANALOG = PORT_PCR_MUX(0),
205 GPIO_AF_GPIO = PORT_PCR_MUX(1),
206 GPIO_AF_2 = PORT_PCR_MUX(2),
207 GPIO_AF_3 = PORT_PCR_MUX(3),
208 GPIO_AF_4 = PORT_PCR_MUX(4),
209 GPIO_AF_5 = PORT_PCR_MUX(5),
210 GPIO_AF_6 = PORT_PCR_MUX(6),
211 GPIO_AF_7 = PORT_PCR_MUX(7),
212#ifdef PORT_PCR_ODE_MASK
213 GPIO_PCR_OD = (PORT_PCR_ODE_MASK),
215 GPIO_PCR_PD = (PORT_PCR_PE_MASK),
216 GPIO_PCR_PU = (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK)
225#ifdef KINETIS_HAVE_PCR
226#define HAVE_GPIO_FLANK_T
228 GPIO_RISING = PORT_PCR_IRQC(0x9),
229 GPIO_FALLING = PORT_PCR_IRQC(0xa),
230 GPIO_BOTH = PORT_PCR_IRQC(0xb),
257#define HAVE_ADC_RES_T
258#ifdef KINETIS_HAVE_ADC_K
270#if defined(FTM_CnSC_MSB_MASK)
274#define PWM_CHAN_MAX (4U)
280#define HAVE_PWM_MODE_T
282 PWM_LEFT = (FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK),
283 PWM_RIGHT = (FTM_CnSC_MSB_MASK | FTM_CnSC_ELSA_MASK),
296#if defined(UART_C1_M_MASK) || DOXYGEN
300#elif defined(LPUART_CTRL_M_MASK)
305#
if defined(UART_C1_M_MASK) || DOXYGEN
307#elif defined(LPUART_CTRL_M_MASK)
309 UART_MODE_8O1 = (LPUART_CTRL_M_MASK | LPUART_CTRL_PE_MASK | LPUART_CTRL_PT_MASK),
319#ifdef KINETIS_HAVE_MK_SPI
320#define HAVE_SPI_MODE_T
322#if defined(SPI_CTAR_CPHA_MASK)
326 SPI_MODE_3 = (SPI_CTAR_CPOL_MASK | SPI_CTAR_CPHA_MASK)
327#elif defined(SPI_C1_CPHA_MASK)
331 SPI_MODE_3 = (SPI_C1_CPOL_MASK | SPI_C1_CPHA_MASK)
370#define ADC_AVG_NONE (0)
374#define ADC_AVG_MAX (ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(3))
376#if defined(DAC0_BASE) && (DAC0_BASE != This_symbol_has_been_deprecated)
382 volatile uint32_t *scgc_addr;
397#ifdef KINETIS_HAVE_LPTMR
413#ifdef FTM_CnSC_MSB_MASK
426#ifdef KINETIS_HAVE_PINSEL
427 volatile uint32_t *pinsel;
428 uint32_t pinsel_mask;
435#define HAVE_I2C_SPEED_T
448#define PERIPH_I2C_NEED_READ_REG
449#define PERIPH_I2C_NEED_READ_REGS
450#define PERIPH_I2C_NEED_WRITE_REG
451#define PERIPH_I2C_NEED_WRITE_REGS
478#ifdef KINETIS_HAVE_PCR
481#ifdef KINETIS_HAVE_PINSEL
482 volatile uint32_t *pinsel;
483 uint32_t pinsel_mask;
494#ifdef KINETIS_HAVE_LPTMR
504#define TIMER_PIT_DEV(x) (TIMER_DEV(0 + (x)))
505#ifdef KINETIS_HAVE_LPTMR
507#define TIMER_LPTMR_DEV(x) (TIMER_DEV(PIT_NUMOF + (x)))
515#define RTT_DEV (TIMER_LPTMR_DEV(0))
516#define RTT_MAX_VALUE (0x0000ffff)
517#define RTT_CLOCK_FREQUENCY (32768U)
518#define RTT_MAX_FREQUENCY (32768U)
519#define RTT_MIN_FREQUENCY (1U)
521#define RTT_FREQUENCY RTT_MAX_FREQUENCY
523#if IS_USED(MODULE_PERIPH_RTT)
527#define KINETIS_XTIMER_SOURCE_PIT 1
550#ifdef KINETIS_HAVE_PCR
554#ifdef KINETIS_HAVE_PINSEL
555 volatile uint32_t *pinsel;
556 uint32_t pinsel_mask;
566#if !defined(KINETIS_HAVE_PLL) && defined(MODULE_PERIPH_MCG) \
567 && defined(MCG_C6_PLLS_MASK) || DOXYGEN
571#define KINETIS_HAVE_PLL 1
573#define KINETIS_HAVE_PLL 0
576#ifdef MODULE_PERIPH_MCG_LITE
580typedef enum kinetis_mcg_mode {
581 KINETIS_MCG_MODE_LIRC8M = 0,
582 KINETIS_MCG_MODE_HIRC = 1,
583 KINETIS_MCG_MODE_EXT = 2,
584 KINETIS_MCG_MODE_LIRC2M = 3,
585 KINETIS_MCG_MODE_NUMOF,
589#ifdef MODULE_PERIPH_MCG
593typedef enum kinetis_mcg_mode {
594 KINETIS_MCG_MODE_FEI = 0,
595 KINETIS_MCG_MODE_FEE = 1,
596 KINETIS_MCG_MODE_FBI = 2,
597 KINETIS_MCG_MODE_FBE = 3,
598 KINETIS_MCG_MODE_BLPI = 4,
599 KINETIS_MCG_MODE_BLPE = 5,
601 KINETIS_MCG_MODE_PBE = 6,
602 KINETIS_MCG_MODE_PEE = 7,
604 KINETIS_MCG_MODE_NUMOF,
612 KINETIS_MCG_FLL_FACTOR_640 = (MCG_C4_DRST_DRS(0)),
614 KINETIS_MCG_FLL_FACTOR_732 = (MCG_C4_DRST_DRS(0) | MCG_C4_DMX32_MASK),
616 KINETIS_MCG_FLL_FACTOR_1280 = (MCG_C4_DRST_DRS(1)),
618 KINETIS_MCG_FLL_FACTOR_1464 = (MCG_C4_DRST_DRS(1) | MCG_C4_DMX32_MASK),
620 KINETIS_MCG_FLL_FACTOR_1920 = (MCG_C4_DRST_DRS(2)),
622 KINETIS_MCG_FLL_FACTOR_2197 = (MCG_C4_DRST_DRS(2) | MCG_C4_DMX32_MASK),
624 KINETIS_MCG_FLL_FACTOR_2560 = (MCG_C4_DRST_DRS(3)),
626 KINETIS_MCG_FLL_FACTOR_2929 = (MCG_C4_DRST_DRS(3) | MCG_C4_DMX32_MASK),
630#if defined(MODULE_PERIPH_MCG) || defined(MODULE_PERIPH_MCG_LITE)
636 KINETIS_MCG_ERC_RANGE_LOW = MCG_C2_RANGE0(0),
637 KINETIS_MCG_ERC_RANGE_HIGH = MCG_C2_RANGE0(1),
638 KINETIS_MCG_ERC_RANGE_VERY_HIGH = MCG_C2_RANGE0(2),
639} kinetis_mcg_erc_range_t;
656 KINETIS_CLOCK_OSC0_EN = (1 << 0),
665 KINETIS_CLOCK_RTCOSC_EN = (1 << 1),
682 KINETIS_CLOCK_USE_FAST_IRC = (1 << 2),
691 KINETIS_CLOCK_MCGIRCLK_EN = (1 << 3),
702 KINETIS_CLOCK_MCGIRCLK_STOP_EN = (1 << 4),
713 KINETIS_CLOCK_MCGPCLK_EN = (1 << 5),
714} kinetis_clock_flags_t;
761 unsigned int clock_flags;
767 kinetis_mcg_mode_t default_mode;
773 kinetis_mcg_erc_range_t erc_range;
785#ifdef MODULE_PERIPH_MCG
809#ifdef MODULE_PERIPH_MCG_LITE
839 kinetis_mcg_fll_t fll_factor_fei;
846 kinetis_mcg_fll_t fll_factor_fee;
@ GPIO_OUT
select GPIO MASK as output
@ GPIO_IN
select GPIO MASK as input
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
@ PWM_CENTER
center aligned
#define PWM_CHAN_MAX
PWM configuration structure.
gpio_t adc_conf_t
ADC configuration wrapper.
uart_type_t
UART hardware module types.
#define GPIO_MODE(x, y)
Internal macro for combining pin mode (x) and pull-up/down (y).
enum IRQn IRQn_Type
Interrupt Number Definition.
adc_res_t
Possible ADC resolution settings.
@ ADC_RES_16BIT
ADC resolution: 16 bit.
@ ADC_RES_8BIT
ADC resolution: 8 bit.
@ ADC_RES_14BIT
ADC resolution: 14 bit.
@ ADC_RES_6BIT
ADC resolution: 6 bit.
@ ADC_RES_10BIT
ADC resolution: 10 bit.
@ ADC_RES_12BIT
ADC resolution: 12 bit.
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
uart_type_t
UART hardware module types.
@ KINETIS_LPUART
Kinetis Low-power UART (LPUART) module type.
@ KINETIS_UART
Kinetis UART module type.
void gpio_init_port(gpio_t pin, uint32_t pcr)
CPU internal function for initializing PORTs.
uart_mode_t
UART transmission modes.
@ UART_MODE_8N1
8 data bits, no parity, 1 stop bit
@ UART_MODE_8E1
8 data bits, even parity, 1 stop bit
@ UART_MODE_8O1
8 data bits, odd parity, 1 stop bit
@ GPIO_PORTS_NUMOF
overall number of available ports
#define SPI_HWCS_NUMOF
Kinetis CPUs have a maximum number of 5 hardware chip select lines.
spi_mode_t
Support SPI modes.
@ SPI_MODE_0
CPOL=0, CPHA=0.
@ SPI_MODE_2
CPOL=1, CPHA=0.
@ SPI_MODE_1
CPOL=0, CPHA=1.
@ SPI_MODE_3
CPOL=1, CPHA=1.
gpio_mode_t
Available pin modes.
Layered low power mode infrastructure.
uint8_t avg
Hardware averaging configuration.
ADC_Type * dev
ADC module.
DAC line configuration data.
I2C configuration structure.
uint32_t freq
I2C module clock frequency, usually CLOCK_BUSCLOCK or CLOCK_CORECLOCK.
I2C_Type * i2c
Pointer to hardware module registers.
uint32_t sda_pcr
PORT module PCR setting for the SDA pin.
uint32_t scl_pcr
PORT module PCR setting for the SCL pin.
CPU specific timer PIT module configuration.
uint8_t prescaler_ch
Prescaler channel.
uint8_t count_ch
Counting channel, will be linked to the prescaler channel.
PWM device configuration.
SPI device configuration.
gpio_t pin_clk
CLK pin used.
gpio_t pin_mosi
MOSI pin used.
gpio_t pin_miso
MISO pin used.
uint32_t simmask
bit in the SIM register
UART device configuration.
uart_type_t type
Hardware module type (KINETIS_UART or KINETIS_LPUART)
gpio_t pin_rx
RX pin, GPIO_UNDEF disables RX.
uint8_t scgc_bit
Clock enable bit, within the register.
uart_mode_t mode
UART mode: data bits, parity, stop bits.
volatile uint32_t * scgc_addr
Clock enable register, in SIM module.
uint32_t freq
Module clock frequency, usually CLOCK_CORECLOCK or CLOCK_BUSCLOCK.
IRQn_Type irqn
IRQ number for this module.