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