Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Freie Universität Berlin
3 * 2015 PHYTEC Messtechnik GmbH
4 * 2023 Hugues Larrive
5 *
6 * This file is subject to the terms and conditions of the GNU Lesser General
7 * Public License v2.1. See the file LICENSE in the top level directory for more
8 * details.
9 */
10
22#ifndef PERIPH_CONF_H
23#define PERIPH_CONF_H
24
25#include "periph_cpu.h"
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
36static const clock_config_t clock_config = {
37 /*
38 * This configuration results in the system running from the PLL output with
39 * the following clock frequencies:
40 * Core: 60 MHz
41 * Bus: 60 MHz
42 * Flex: 20 MHz
43 * Flash: 20 MHz
44 */
45 .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
46 SIM_CLKDIV1_OUTDIV3(2) | SIM_CLKDIV1_OUTDIV4(2),
47 .rtc_clc = 0, /* External load caps on board */
48 .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
49 .clock_flags =
50 /* No OSC0_EN, use EXTAL directly without OSC0 */
51 KINETIS_CLOCK_RTCOSC_EN |
52 KINETIS_CLOCK_USE_FAST_IRC |
53 0,
54 .default_mode = KINETIS_MCG_MODE_PEE,
55 /* The board has an external RMII (Ethernet) clock which drives the ERC at 50 MHz */
56 .erc_range = KINETIS_MCG_ERC_RANGE_VERY_HIGH,
57 .osc_clc = 0, /* External load caps on board */
58 .oscsel = MCG_C7_OSCSEL(0), /* Use EXTAL for external clock */
59 .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
60 .fll_frdiv = MCG_C1_FRDIV(0b111), /* Divide by 1536 => FLL input 32252 Hz */
61 .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
62 .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1920, /* FLL freq = 62.5 MHz */
63 .pll_prdiv = MCG_C5_PRDIV0(0b10011), /* Divide by 20 */
64 .pll_vdiv = MCG_C6_VDIV0(0b00000), /* Multiply by 24 => PLL freq = 60 MHz */
65};
66#define CLOCK_CORECLOCK (60000000ul)
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 (1U)
86#define LPTMR_CONFIG { \
87 { \
88 .dev = LPTMR0, \
89 .irqn = LPTMR0_IRQn, \
90 .src = 2, \
91 .base_freq = 32768u, \
92 }, \
93}
94#define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
95
96#define PIT_BASECLOCK (CLOCK_BUSCLOCK)
97#define PIT_ISR_0 isr_pit1
98#define PIT_ISR_1 isr_pit3
99#define LPTMR_ISR_0 isr_lptmr0
106static const uart_conf_t uart_config[] = {
107 {
108 .dev = UART0,
109 .freq = CLOCK_CORECLOCK,
110 .pin_rx = GPIO_PIN(PORT_B, 16),
111 .pin_tx = GPIO_PIN(PORT_B, 17),
112 .pcr_rx = PORT_PCR_MUX(3),
113 .pcr_tx = PORT_PCR_MUX(3),
114 .irqn = UART0_RX_TX_IRQn,
115 .scgc_addr = &SIM->SCGC4,
116 .scgc_bit = SIM_SCGC4_UART0_SHIFT,
117 .mode = UART_MODE_8N1,
118 .type = KINETIS_UART,
119 },
120};
121
122#define UART_0_ISR (isr_uart0_rx_tx)
123
124#define UART_NUMOF ARRAY_SIZE(uart_config)
131static const adc_conf_t adc_config[] = {
132 [ 0] = { /* PTB2 (Arduino A0) */
133 .dev = ADC0, .pin = GPIO_PIN(PORT_B, 2),
134 .chan = 12, .avg = ADC_AVG_MAX
135 },
136 [ 1] = { /* PTB3 (Arduino A1) */
137 .dev = ADC0, .pin = GPIO_PIN(PORT_B, 3),
138 .chan = 13, .avg = ADC_AVG_MAX
139 },
140 [ 2] = { /* PTB10 (Arduino A2) */
141 .dev = ADC1, .pin = GPIO_PIN(PORT_B, 10),
142 .chan = 14, .avg = ADC_AVG_MAX
143 },
144 [ 3] = { /* PTB11 (Arduino A3) */
145 .dev = ADC1, .pin = GPIO_PIN(PORT_B, 11),
146 .chan = 15, .avg = ADC_AVG_MAX
147 },
148 [ 4] = { /* PTC11 (Arduino A4) */
149 .dev = ADC1, .pin = GPIO_PIN(PORT_C, 11),
150 .chan = 7, .avg = ADC_AVG_MAX
151 },
152 [ 5] = { /* PTC10 (Arduino A5) */
153 .dev = ADC1, .pin = GPIO_PIN(PORT_C, 10),
154 .chan = 6, .avg = ADC_AVG_MAX
155 },
156 [ 6] = { /* ADC0_DP0 */
157 .dev = ADC0, .pin = GPIO_UNDEF,
158 .chan = 0, .avg = ADC_AVG_MAX
159 },
160 [ 7] = { /* ADC0_DM0 */
161 .dev = ADC0, .pin = GPIO_UNDEF,
162 .chan = 19, .avg = ADC_AVG_MAX
163 },
164 [ 8] = { /* ADC0_DP0 - ADC0_DM0 */
165 .dev = ADC0, .pin = GPIO_UNDEF,
166 .chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
167 },
168 [ 9] = { /* ADC1_DP0 */
169 .dev = ADC1, .pin = GPIO_UNDEF,
170 .chan = 0, .avg = ADC_AVG_MAX
171 },
172 [10] = { /* ADC1_DM0 */
173 .dev = ADC1, .pin = GPIO_UNDEF,
174 .chan = 19, .avg = ADC_AVG_MAX
175 },
176 [11] = { /* ADC1_DP0 - ADC1_DM0 */
177 .dev = ADC1, .pin = GPIO_UNDEF,
178 .chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
179 },
180 [12] = { /* ADC0_DP1 */
181 .dev = ADC0, .pin = GPIO_UNDEF,
182 .chan = 1, .avg = ADC_AVG_MAX
183 },
184 [13] = { /* ADC0_DM1 */
185 .dev = ADC0, .pin = GPIO_UNDEF,
186 .chan = 20, .avg = ADC_AVG_MAX
187 },
188 [14] = { /* ADC0_DP1 - ADC0_DM1 */
189 .dev = ADC0, .pin = GPIO_UNDEF,
190 .chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
191 },
192 [15] = { /* ADC1_DP1 */
193 .dev = ADC1, .pin = GPIO_UNDEF,
194 .chan = 1, .avg = ADC_AVG_MAX
195 },
196 [16] = { /* ADC1_DM1 */
197 .dev = ADC1, .pin = GPIO_UNDEF,
198 .chan = 20, .avg = ADC_AVG_MAX
199 },
200 [17] = { /* ADC1_DP1 - ADC1_DM1 */
201 .dev = ADC1, .pin = GPIO_UNDEF,
202 .chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
203 },
204 /* internal: temperature sensor */
205 /* The temperature sensor has a very high output impedance, it must
206 * not be sampled using hardware averaging, or the sampled values
207 * will be garbage */
208 [18] = {
209 .dev = ADC0, .pin = GPIO_UNDEF,
210 .chan = 26, .avg = ADC_AVG_NONE
211 },
212 /* internal: band gap */
213 /* Note: the band gap buffer uses a bit of current and is turned off
214 * by default, set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading
215 * or the input will be floating */
216 [19] = {
217 .dev = ADC0, .pin = GPIO_UNDEF,
218 .chan = 27, .avg = ADC_AVG_MAX
219 },
220};
221
222#define ADC_NUMOF ARRAY_SIZE(adc_config)
223/*
224 * K64F ADC reference settings:
225 * 0: VREFH/VREFL external pin pair
226 * 1: VREF_OUT internal 1.2 V reference (VREF module must be enabled)
227 * 2-3: reserved
228 */
229#define ADC_REF_SETTING 0
236static const pwm_conf_t pwm_config[] = {
237 {
238 .ftm = FTM0,
239 .chan = {
240 { .pin = GPIO_PIN(PORT_A, 4), .af = 3, .ftm_chan = 6 },
241 { .pin = GPIO_PIN(PORT_A, 2), .af = 3, .ftm_chan = 7 },
242 { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 },
243 { .pin = GPIO_PIN(PORT_C, 3), .af = 4, .ftm_chan = 2 }
244 },
245 .chan_numof = 4,
246 .ftm_num = 0
247 }
248};
249
250#define PWM_NUMOF ARRAY_SIZE(pwm_config)
263static const uint32_t spi_clk_config[] = {
264 (
265 SPI_CTAR_PBR(2) | SPI_CTAR_BR(6) | /* -> 93750Hz */
266 SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(5) |
267 SPI_CTAR_PASC(2) | SPI_CTAR_ASC(5) |
268 SPI_CTAR_PDT(2) | SPI_CTAR_DT(5)
269 ),
270 (
271 SPI_CTAR_PBR(2) | SPI_CTAR_BR(4) | /* -> 375000Hz */
272 SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(3) |
273 SPI_CTAR_PASC(2) | SPI_CTAR_ASC(3) |
274 SPI_CTAR_PDT(2) | SPI_CTAR_DT(3)
275 ),
276 (
277 SPI_CTAR_PBR(2) | SPI_CTAR_BR(2) | /* -> 1000000Hz */
278 SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(4) |
279 SPI_CTAR_PASC(0) | SPI_CTAR_ASC(4) |
280 SPI_CTAR_PDT(0) | SPI_CTAR_DT(4)
281 ),
282 (
283 SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 5000000Hz */
284 SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
285 SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
286 SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
287 ),
288 (
289 SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | /* -> 7500000Hz */
290 SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(1) |
291 SPI_CTAR_PASC(0) | SPI_CTAR_ASC(1) |
292 SPI_CTAR_PDT(0) | SPI_CTAR_DT(1)
293 )
294};
295
296static const spi_conf_t spi_config[] = {
297 {
298 .dev = SPI0,
299 .pin_miso = GPIO_PIN(PORT_D, 3),
300 .pin_mosi = GPIO_PIN(PORT_D, 2),
301 .pin_clk = GPIO_PIN(PORT_D, 1),
302 .pin_cs = {
303 GPIO_PIN(PORT_D, 0),
308 },
309 .pcr = GPIO_AF_2,
310 .simmask = SIM_SCGC6_SPI0_MASK
311 }
312};
313
314#define SPI_NUMOF ARRAY_SIZE(spi_config)
321static const i2c_conf_t i2c_config[] = {
322 {
323 .i2c = I2C0,
324 .scl_pin = GPIO_PIN(PORT_E, 24),
325 .sda_pin = GPIO_PIN(PORT_E, 25),
326 .freq = CLOCK_BUSCLOCK,
327 .speed = I2C_SPEED_FAST,
328 .irqn = I2C0_IRQn,
329 .scl_pcr = (PORT_PCR_MUX(5) | PORT_PCR_ODE_MASK),
330 .sda_pcr = (PORT_PCR_MUX(5) | PORT_PCR_ODE_MASK),
331 },
332};
333#define I2C_NUMOF ARRAY_SIZE(i2c_config)
334#define I2C_0_ISR (isr_i2c0)
335#define I2C_1_ISR (isr_i2c1)
338#ifdef __cplusplus
339}
340#endif
341
342#endif /* PERIPH_CONF_H */
#define CLOCK_CORECLOCK
Clock configuration.
Definition periph_cpu.h:31
@ PORT_B
port B
Definition periph_cpu.h:48
@ PORT_C
port C
Definition periph_cpu.h:49
@ PORT_E
port E
Definition periph_cpu.h:51
@ PORT_A
port A
Definition periph_cpu.h:47
@ PORT_D
port D
Definition periph_cpu.h:50
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition periph_cpu.h:46
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:279
#define SPI_CS_UNDEF
Define value for unused CS line.
Definition periph_cpu.h:363
#define UART0
UART0 register bank.
#define CLOCK_BUSCLOCK
Bus clock frequency, used by several hardware modules in Kinetis CPUs.
Definition mcg.h:147
#define ADC_AVG_NONE
Disable hardware averaging.
Definition periph_cpu.h:370
@ KINETIS_UART
Kinetis UART module type.
Definition periph_cpu.h:538
@ UART_MODE_8N1
8 data bits, no parity, 1 stop bit
Definition periph_cpu.h:294
#define ADC_AVG_MAX
Maximum hardware averaging (32 samples)
Definition periph_cpu.h:374
ADC device configuration.
Definition periph_cpu.h:379
ADC_TypeDef * dev
ADC device used.
Definition periph_cpu.h:380
I2C configuration structure.
Definition periph_cpu.h:299
I2C_Type * i2c
Pointer to hardware module registers.
Definition periph_cpu.h:459
gpio_t pin
GPIO pin mapped to this channel.
Definition periph_cpu.h:470
PWM device configuration.
pwm_chan_t chan[TIMER_CHANNEL_NUMOF]
channel mapping set to {GPIO_UNDEF, 0} if not used
Definition periph_cpu.h:483
SPI device configuration.
Definition periph_cpu.h:337
SPI_t * dev
pointer to the used SPI device
Definition periph_cpu.h:338
UART device configuration.
Definition periph_cpu.h:218
USART_t * dev
pointer to the used UART device
Definition periph_cpu.h:219