Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Eistec AB
3 * 2016 Freie Universität Berlin
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser General
6 * Public License v2.1. See the file LICENSE in the top level directory for more
7 * details.
8 */
9
10#pragma once
11
22
23#include "periph_cpu.h"
24
25#ifdef __cplusplus
26extern "C"
27{
28#endif
29
34/* The crystal on the Mulle is designed for 12.5 pF load capacitance. According
35 * to the data sheet, the K60 will have a 5 pF parasitic capacitance on the
36 * XTAL32/EXTAL32 connection. The board traces might give some minor parasitic
37 * capacitance as well. */
38/* Use the equation
39 * CL = (C1 * C2) / (C1 + C2) + Cstray
40 * with C1 == C2:
41 * C1 = 2 * (CL - Cstray)
42 */
43/* enable 14pF load capacitor which will yield a crystal load capacitance of 12 pF */
44#define RTC_LOAD_CAP_BITS (RTC_CR_SC8P_MASK | RTC_CR_SC4P_MASK | RTC_CR_SC2P_MASK)
45
46static const clock_config_t clock_config = {
47 /*
48 * This configuration results in the system running from the FLL output with
49 * the following clock frequencies:
50 * Core: 48 MHz
51 * Bus: 48 MHz
52 * Flex: 24 MHz
53 * Flash: 24 MHz
54 */
55 /* The board has a 16 MHz crystal, though it is not used in this configuration */
56 /* This configuration uses the RTC crystal to provide the base clock, it
57 * should have better accuracy than the internal slow clock, and lower power
58 * consumption than using the 16 MHz crystal and the OSC0 module */
59 .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
60 SIM_CLKDIV1_OUTDIV3(1) | SIM_CLKDIV1_OUTDIV4(1),
61 .rtc_clc = RTC_LOAD_CAP_BITS,
62 .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
63 .clock_flags =
64 /* no OSC0_EN, the RTC module provides the clock input signal for the FLL */
65 KINETIS_CLOCK_RTCOSC_EN |
66 KINETIS_CLOCK_USE_FAST_IRC |
67 0,
68 .default_mode = KINETIS_MCG_MODE_FEE,
69 .erc_range = KINETIS_MCG_ERC_RANGE_LOW, /* Input clock is 32768 Hz */
70 /* 16 pF capacitors yield ca 10 pF load capacitance as required by the
71 * onboard xtal, not used when OSC0 is disabled */
72 .osc_clc = OSC_CR_SC16P_MASK,
73 .oscsel = MCG_C7_OSCSEL(1), /* Use RTC for external clock */
74 .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
75 .fll_frdiv = MCG_C1_FRDIV(0b000), /* Divide by 1 => FLL input 32768 Hz */
76 .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
77 .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
78 /* PLL is unavailable when using a 32768 Hz source clock, so the
79 * configuration below can only be used if the above config is modified to
80 * use the 16 MHz crystal instead of the RTC. */
81 .pll_prdiv = MCG_C5_PRDIV0(0b00111), /* Divide by 8 */
82 .pll_vdiv = MCG_C6_VDIV0(0b01100), /* Multiply by 36 => PLL freq = 72 MHz */
83};
84#define CLOCK_CORECLOCK (48000000ul)
85#define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1)
87
92#define PIT_NUMOF (2U)
93#define PIT_CONFIG { \
94 { \
95 .prescaler_ch = 0, \
96 .count_ch = 1, \
97 }, \
98 { \
99 .prescaler_ch = 2, \
100 .count_ch = 3, \
101 }, \
102 }
103#define LPTMR_NUMOF (1U)
104#define LPTMR_CONFIG { \
105 { \
106 .dev = LPTMR0, \
107 .irqn = LPTMR0_IRQn, \
108 .src = 2, \
109 .base_freq = 32768u, \
110 } \
111 }
112#define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
113
114#define PIT_BASECLOCK (CLOCK_BUSCLOCK)
115#define PIT_ISR_0 isr_pit1
116#define PIT_ISR_1 isr_pit3
117#define LPTMR_ISR_0 isr_lptmr0
118
120
125static const uart_conf_t uart_config[] = {
126 {
127 .dev = UART0,
128 .freq = CLOCK_CORECLOCK,
129 .pin_rx = GPIO_PIN(PORT_A, 15),
130 .pin_tx = GPIO_PIN(PORT_A, 14),
131 .pcr_rx = PORT_PCR_MUX(3),
132 .pcr_tx = PORT_PCR_MUX(3),
133 .irqn = UART0_RX_TX_IRQn,
134 .scgc_addr = &SIM->SCGC4,
135 .scgc_bit = SIM_SCGC4_UART0_SHIFT,
136 .mode = UART_MODE_8N1,
137 .type = KINETIS_UART,
138 },
139 {
140 .dev = UART1,
141 .freq = CLOCK_CORECLOCK,
142 .pin_rx = GPIO_PIN(PORT_C, 3),
143 .pin_tx = GPIO_PIN(PORT_C, 4),
144 .pcr_rx = PORT_PCR_MUX(3),
145 .pcr_tx = PORT_PCR_MUX(3),
146 .irqn = UART1_RX_TX_IRQn,
147 .scgc_addr = &SIM->SCGC4,
148 .scgc_bit = SIM_SCGC4_UART1_SHIFT,
149 .mode = UART_MODE_8N1,
150 .type = KINETIS_UART,
151 },
152};
153
154#define UART_0_ISR (isr_uart0_rx_tx)
155#define UART_1_ISR (isr_uart1_rx_tx)
156
157#define UART_NUMOF ARRAY_SIZE(uart_config)
159
164static const adc_conf_t adc_config[] = {
165 /* internal: temperature sensor */
166 /* The temperature sensor has a very high output impedance, it must not be
167 * sampled using hardware averaging, or the sampled values will be garbage */
168 [ 0] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 26, .avg = ADC_AVG_NONE },
169 /* internal: band gap */
170 [ 1] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 27, .avg = ADC_AVG_MAX },
171 /* internal: V_REFSH */
172 [ 2] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 29, .avg = ADC_AVG_MAX },
173 /* internal: V_REFSL */
174 [ 3] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 30, .avg = ADC_AVG_MAX },
175 /* internal: DAC0 module output level */
176 [ 4] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 23, .avg = ADC_AVG_MAX },
177 /* internal: VREF module output level */
178 [ 5] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 18, .avg = ADC_AVG_MAX },
179 /* on board connection to Mulle Vbat/2 on PGA1_DP pin */
180 [ 6] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 0, .avg = ADC_AVG_MAX },
181 /* on board connection to Mulle Vchr/2 on PGA1_DM pin */
182 [ 7] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 19, .avg = ADC_AVG_MAX },
183 /* expansion port PGA0_DP pin */
184 [ 8] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 0, .avg = ADC_AVG_MAX },
185 /* expansion port PGA0_DM pin */
186 [ 9] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 19, .avg = ADC_AVG_MAX },
187 /* expansion port PTA17 */
188 [10] = { .dev = ADC1, .pin = GPIO_PIN(PORT_A, 17), .chan = 17, .avg = ADC_AVG_MAX },
189 /* expansion port PTB0 */
190 [11] = { .dev = ADC1, .pin = GPIO_PIN(PORT_B, 0), .chan = 8, .avg = ADC_AVG_MAX },
191 /* expansion port PTC0 */
192 [12] = { .dev = ADC0, .pin = GPIO_PIN(PORT_C, 0), .chan = 14, .avg = ADC_AVG_MAX },
193 /* expansion port PTC8 */
194 [13] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 8), .chan = 4, .avg = ADC_AVG_MAX },
195 /* expansion port PTC9 */
196 [14] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 9), .chan = 5, .avg = ADC_AVG_MAX },
197 /* expansion port PTC10 */
198 [15] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 10), .chan = 6, .avg = ADC_AVG_MAX },
199 /* expansion port PTC11 */
200 [16] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 11), .chan = 7, .avg = ADC_AVG_MAX },
201};
202
203#define ADC_NUMOF ARRAY_SIZE(adc_config)
204/*
205 * K60D ADC reference settings:
206 * 0: VREFH/VREFL external pin pair
207 * 1: VREF_OUT internal 1.2 V reference (VREF module must be enabled)
208 * 2-3: reserved
209 */
210#define ADC_REF_SETTING 0
212
217static const dac_conf_t dac_config[] = {
218 {
219 .dev = DAC0,
220 .scgc_addr = &SIM->SCGC2,
221 .scgc_bit = SIM_SCGC2_DAC0_SHIFT
222 }
223};
224
225#define DAC_NUMOF ARRAY_SIZE(dac_config)
227
232static const pwm_conf_t pwm_config[] = {
233 {
234 .ftm = FTM0,
235 .chan = {
236 { .pin = GPIO_PIN(PORT_C, 1), .af = 4, .ftm_chan = 0 },
237 { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 },
238 { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
239 { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
240 },
241 .chan_numof = 2,
242 .ftm_num = 0
243 },
244 {
245 .ftm = FTM1,
246 .chan = {
247 { .pin = GPIO_PIN(PORT_A, 12), .af = 3, .ftm_chan = 0 },
248 { .pin = GPIO_PIN(PORT_A, 13), .af = 3, .ftm_chan = 1 },
249 { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
250 { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
251 },
252 .chan_numof = 2,
253 .ftm_num = 1
254 }
255};
256
257#define PWM_NUMOF ARRAY_SIZE(pwm_config)
259
270static const uint32_t spi_clk_config[] = {
271 (
272 SPI_CTAR_PBR(0) | SPI_CTAR_BR(8) | /* -> 93728Hz */
273 SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(8) |
274 SPI_CTAR_PASC(0) | SPI_CTAR_ASC(8) |
275 SPI_CTAR_PDT(0) | SPI_CTAR_DT(8)
276 ),
277 (
278 SPI_CTAR_PBR(0) | SPI_CTAR_BR(6) | /* -> 374912Hz */
279 SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(6) |
280 SPI_CTAR_PASC(0) | SPI_CTAR_ASC(6) |
281 SPI_CTAR_PDT(0) | SPI_CTAR_DT(6)
282 ),
283 (
284 SPI_CTAR_PBR(1) | SPI_CTAR_BR(4) | /* -> 999765Hz */
285 SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(3) |
286 SPI_CTAR_PASC(1) | SPI_CTAR_ASC(3) |
287 SPI_CTAR_PDT(1) | SPI_CTAR_DT(3)
288 ),
289 (
290 SPI_CTAR_PBR(2) | SPI_CTAR_BR(0) | /* -> 4798873Hz */
291 SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(0) |
292 SPI_CTAR_PASC(2) | SPI_CTAR_ASC(0) |
293 SPI_CTAR_PDT(2) | SPI_CTAR_DT(0)
294 ),
295 (
296 SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 7998122Hz */
297 SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
298 SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
299 SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
300 )
301};
302
303static const spi_conf_t spi_config[] = {
304 {
305 .dev = SPI0,
306 .pin_miso = GPIO_PIN(PORT_D, 3),
307 .pin_mosi = GPIO_PIN(PORT_D, 2),
308 .pin_clk = GPIO_PIN(PORT_D, 1),
309 .pin_cs = {
310 GPIO_PIN(PORT_D, 0),
311 GPIO_PIN(PORT_D, 4),
312 GPIO_PIN(PORT_D, 5),
313 GPIO_PIN(PORT_D, 6),
315 },
316 .pcr = GPIO_AF_2,
317 .simmask = SIM_SCGC6_SPI0_MASK
318 },
319 {
320 .dev = SPI1,
321 .pin_miso = GPIO_PIN(PORT_E, 3),
322 .pin_mosi = GPIO_PIN(PORT_E, 1),
323 .pin_clk = GPIO_PIN(PORT_E, 2),
324 .pin_cs = {
325 GPIO_PIN(PORT_E, 4),
330 },
331 .pcr = GPIO_AF_2,
332 .simmask = SIM_SCGC6_SPI1_MASK
333 }
334};
335
336#define SPI_NUMOF ARRAY_SIZE(spi_config)
338
343static const i2c_conf_t i2c_config[] = {
344 {
345 .i2c = I2C0,
346 .scl_pin = GPIO_PIN(PORT_B, 2),
347 .sda_pin = GPIO_PIN(PORT_B, 1),
348 .freq = CLOCK_BUSCLOCK,
349 .speed = I2C_SPEED_FAST,
350 .irqn = I2C0_IRQn,
351 .scl_pcr = (PORT_PCR_MUX(2) | PORT_PCR_ODE_MASK),
352 .sda_pcr = (PORT_PCR_MUX(2) | PORT_PCR_ODE_MASK),
353 },
354};
355#define I2C_NUMOF ARRAY_SIZE(i2c_config)
356#define I2C_0_ISR (isr_i2c0)
357#define I2C_1_ISR (isr_i2c1)
359
360#ifdef __cplusplus
361}
362#endif
363
#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_E
port E
Definition periph_cpu.h:50
@ PORT_A
port A
Definition periph_cpu.h:46
@ PORT_D
port D
Definition periph_cpu.h:49
#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.
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:278
static const spi_clk_conf_t spi_clk_config[]
Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz)
Definition periph_cpu.h:281
#define SPI_CS_UNDEF
Define value for unused CS line.
Definition periph_cpu.h:362
#define UART0
UART0 register bank.
#define UART1
UART1 register bank.
#define CLOCK_BUSCLOCK
Bus clock frequency, used by several hardware modules in Kinetis CPUs.
Definition mcg.h:146
#define ADC_AVG_NONE
Disable hardware averaging.
Definition periph_cpu.h:369
@ 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
#define ADC_AVG_MAX
Maximum hardware averaging (32 samples)
Definition periph_cpu.h:373
ADC device configuration.
Definition periph_cpu.h:377
DAC line configuration data.
Definition periph_cpu.h:300
I2C configuration structure.
Definition periph_cpu.h:298
PWM device configuration.
SPI device configuration.
Definition periph_cpu.h:336
UART device configuration.
Definition periph_cpu.h:217