periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017 Inria
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #include "periph_cpu.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
28 static const clock_config_t clock_config = {
29  /*
30  * This configuration results in the system running from the FLL output with
31  * the following clock frequencies:
32  * Core: 48 MHz
33  * Bus: 48 MHz
34  * Flex: 24 MHz
35  * Flash: 24 MHz
36  */
37  /* The board has a 16 MHz crystal, though it is not used in this configuration */
38  /* This configuration uses the RTC crystal to provide the base clock, it
39  * should have better accuracy than the internal slow clock, and lower power
40  * consumption than using the 16 MHz crystal and the OSC0 module */
41  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
42  SIM_CLKDIV1_OUTDIV3(1) | SIM_CLKDIV1_OUTDIV4(1),
43  /* RTC crystal has to be soldered by the user, we can't know the load cap requirements */
44  .rtc_clc = 0,
45  .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
46  .clock_flags =
47  KINETIS_CLOCK_RTCOSC_EN |
48  KINETIS_CLOCK_USE_FAST_IRC |
49  0,
50  .default_mode = KINETIS_MCG_MODE_FEE,
51  .erc_range = KINETIS_MCG_ERC_RANGE_LOW, /* Input clock is 32768 Hz */
52  /* 16 pF capacitors yield ca 10 pF load capacitance as required by the
53  * onboard xtal, not used when OSC0 is disabled */
54  .osc_clc = OSC_CR_SC16P_MASK,
55  .oscsel = MCG_C7_OSCSEL(1), /* Use RTC oscillator as external clock */
56  .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
57  .fll_frdiv = MCG_C1_FRDIV(0b000), /* Divide by 1 => FLL input 32768 Hz */
58  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
59  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
60  /* PLL is unavailable when using a 32768 Hz source clock, so the
61  * configuration below can only be used if the above config is modified to
62  * use the 16 MHz crystal instead of the RTC. */
63  .pll_prdiv = MCG_C5_PRDIV0(0b00111), /* Divide by 8 */
64  .pll_vdiv = MCG_C6_VDIV0(0b01100), /* Multiply by 36 => PLL freq = 72 MHz */
65 };
66 #define CLOCK_CORECLOCK (48000000ul)
67 #define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1)
74 #define PIT_NUMOF (2U)
75 #define PIT_CONFIG { \
76  { \
77  .prescaler_ch = 0, \
78  .count_ch = 1, \
79  }, \
80  { \
81  .prescaler_ch = 2, \
82  .count_ch = 3, \
83  }, \
84  }
85 #define LPTMR_NUMOF (0U)
86 #define LPTMR_CONFIG { \
87  }
88 #define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
89 
90 #define PIT_BASECLOCK (CLOCK_BUSCLOCK)
91 #define PIT_ISR_0 isr_pit1
92 #define PIT_ISR_1 isr_pit3
99 static const uart_conf_t uart_config[] = {
100  {
101  .dev = UART0,
102  .freq = CLOCK_CORECLOCK,
103  .pin_rx = GPIO_PIN(PORT_B, 16), /* TEENSY PIN 0 */
104  .pin_tx = GPIO_PIN(PORT_B, 17), /* TEENSY PIN 1 */
105  .pcr_rx = PORT_PCR_MUX(3),
106  .pcr_tx = PORT_PCR_MUX(3),
107  .irqn = UART0_RX_TX_IRQn,
108  .scgc_addr = &SIM->SCGC4,
109  .scgc_bit = SIM_SCGC4_UART0_SHIFT,
110  .mode = UART_MODE_8N1,
111  .type = KINETIS_UART,
112  },
113  {
114  .dev = UART1,
115  .freq = CLOCK_CORECLOCK,
116  .pin_rx = GPIO_PIN(PORT_C, 3), /* TEENSY PIN 9 */
117  .pin_tx = GPIO_PIN(PORT_C, 4), /* TEENSY PIN 10 */
118  .pcr_rx = PORT_PCR_MUX(3),
119  .pcr_tx = PORT_PCR_MUX(3),
120  .irqn = UART1_RX_TX_IRQn,
121  .scgc_addr = &SIM->SCGC4,
122  .scgc_bit = SIM_SCGC4_UART1_SHIFT,
123  .mode = UART_MODE_8N1,
124  .type = KINETIS_UART,
125  },
126 };
127 
128 #define UART_0_ISR (isr_uart0_rx_tx)
129 #define UART_1_ISR (isr_uart1_rx_tx)
130 
131 #define UART_NUMOF ARRAY_SIZE(uart_config)
138 static const pwm_conf_t pwm_config[] = {
139  {
140  .ftm = FTM0,
141  .chan = {
142  { .pin = GPIO_PIN(PORT_C, 1), .af = 4, .ftm_chan = 0 }, /* TEENSY PIN 22 */
143  { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 }, /* TEENSY PIN 23 */
144  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
145  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
146  },
147  .chan_numof = 2,
148  .ftm_num = 0
149  },
150  {
151  .ftm = FTM1,
152  .chan = {
153  { .pin = GPIO_PIN(PORT_A, 12), .af = 3, .ftm_chan = 0 }, /* TEENSY PIN 3 */
154  { .pin = GPIO_PIN(PORT_A, 13), .af = 3, .ftm_chan = 1 }, /* TEENSY PIN 4 */
155  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
156  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
157  },
158  .chan_numof = 2,
159  .ftm_num = 1
160  }
161 };
162 
163 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
166 #ifdef __cplusplus
167 }
168 #endif
169 
@ PORT_B
port B
Definition: periph_cpu.h:44
@ PORT_C
port C
Definition: periph_cpu.h:45
@ PORT_A
port A
Definition: periph_cpu.h:43
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:42
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:35
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:218
#define UART0
UART0 register bank.
#define UART1
UART1 register bank.
#define CLOCK_CORECLOCK
System core clock in Hz.
Definition: periph_conf.h:34
@ KINETIS_UART
Kinetis UART module type.
Definition: periph_cpu.h:537
@ UART_MODE_8N1
8 data bits, no parity, 1 stop bit
Definition: periph_cpu.h:293
gpio_t pin
GPIO pin mapped to this channel.
Definition: periph_cpu.h:469
PWM device configuration.
pwm_chan_t chan[TIMER_CHANNEL_NUMOF]
channel mapping set to {GPIO_UNDEF, 0} if not used
Definition: periph_cpu.h:482
UART device configuration.
Definition: periph_cpu.h:214
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:215