Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014-2016 Freie Universität Berlin
3 * Copyright (C) 2014 PHYTEC Messtechnik GmbH
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
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: 48 MHz
41 * Bus: 48 MHz
42 * Flash: 24 MHz
43 */
44 .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
45 SIM_CLKDIV1_OUTDIV4(1),
46 .rtc_clc = 0, /* External load caps on the FRDM-K22F board */
47 .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
48 .clock_flags =
49 /* No OSC0_EN, use modem clock from EXTAL0 */
50 KINETIS_CLOCK_RTCOSC_EN |
51 KINETIS_CLOCK_USE_FAST_IRC |
52 0,
53 .default_mode = KINETIS_MCG_MODE_PEE,
54 /* The modem generates a 4 MHz clock signal */
55 .erc_range = KINETIS_MCG_ERC_RANGE_HIGH,
56 .osc_clc = 0, /* OSC0 is unused*/
57 .oscsel = MCG_C7_OSCSEL(0), /* Use EXTAL0 for external clock */
58 .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
59 .fll_frdiv = MCG_C1_FRDIV(0b010), /* Divide by 128 */
60 .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
61 .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1280, /* FLL freq = 40 MHz */
62 .pll_prdiv = MCG_C5_PRDIV0(0b00001), /* Divide by 2 */
63 .pll_vdiv = MCG_C6_VDIV0(0b00000), /* Multiply by 24 => PLL freq = 48 MHz */
64};
65#define CLOCK_CORECLOCK (48000000ul)
66#define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1)
73#define PIT_NUMOF (2U)
74#define PIT_CONFIG { \
75 { \
76 .prescaler_ch = 0, \
77 .count_ch = 1, \
78 }, \
79 { \
80 .prescaler_ch = 2, \
81 .count_ch = 3, \
82 }, \
83 }
84#define LPTMR_NUMOF (0U)
85#define LPTMR_CONFIG {}
86#define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
87
88#define PIT_BASECLOCK (CLOCK_BUSCLOCK)
89#define PIT_ISR_0 isr_pit1
90#define PIT_ISR_1 isr_pit3
97static const uart_conf_t uart_config[] = {
98 {
99 .dev = UART2,
100 .freq = CLOCK_BUSCLOCK,
101 .pin_rx = GPIO_PIN(PORT_D, 2),
102 .pin_tx = GPIO_PIN(PORT_D, 3),
103 .pcr_rx = PORT_PCR_MUX(3),
104 .pcr_tx = PORT_PCR_MUX(3),
105 .irqn = UART2_RX_TX_IRQn,
106 .scgc_addr = &SIM->SCGC4,
107 .scgc_bit = SIM_SCGC4_UART2_SHIFT,
108 .mode = UART_MODE_8N1,
109 .type = KINETIS_UART,
110 },
111 {
112 .dev = UART0,
113 .freq = CLOCK_CORECLOCK,
114 .pin_rx = GPIO_PIN(PORT_D, 6),
115 .pin_tx = GPIO_PIN(PORT_D, 7),
116 .pcr_rx = PORT_PCR_MUX(3),
117 .pcr_tx = PORT_PCR_MUX(3),
118 .irqn = UART0_RX_TX_IRQn,
119 .scgc_addr = &SIM->SCGC4,
120 .scgc_bit = SIM_SCGC4_UART0_SHIFT,
121 .mode = UART_MODE_8N1,
122 .type = KINETIS_UART,
123 }
124};
125
126#define UART_0_ISR (isr_uart2_rx_tx)
127#define UART_1_ISR (isr_uart0_rx_tx)
128
129#define UART_NUMOF ARRAY_SIZE(uart_config)
136static const adc_conf_t adc_config[] = {
137 [ 0] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 2), .chan = 1, .avg = ADC_AVG_MAX },
138 [ 1] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 3), .chan = 1, .avg = ADC_AVG_MAX },
139 [ 2] = { .dev = ADC0, .pin = GPIO_PIN(PORT_D, 7), .chan = 22, .avg = ADC_AVG_MAX },
140 [ 3] = { .dev = ADC0, .pin = GPIO_PIN(PORT_D, 5), .chan = 6, .avg = ADC_AVG_MAX },
141 [ 4] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 0), .chan = 10, .avg = ADC_AVG_MAX },
142 [ 5] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 1), .chan = 11, .avg = ADC_AVG_MAX }
143};
144
145#define ADC_NUMOF ARRAY_SIZE(adc_config)
146/*
147 * KW2xD ADC reference settings:
148 * 0: VREFH/VREFL external pin pair
149 * 1-3: reserved
150 */
151#define ADC_REF_SETTING 0
158static const pwm_conf_t pwm_config[] = {
159 {
160 .ftm = FTM0,
161 .chan = {
162 { .pin = GPIO_PIN(PORT_A, 4), .af = 3, .ftm_chan = 1 },
163 { .pin = GPIO_PIN(PORT_D, 4), .af = 4, .ftm_chan = 4 },
164 { .pin = GPIO_PIN(PORT_D, 6), .af = 4, .ftm_chan = 6 },
165 { .pin = GPIO_PIN(PORT_A, 1), .af = 3, .ftm_chan = 1 }
166 },
167 .chan_numof = 4,
168 .ftm_num = 0
169 }
170};
171
172#define PWM_NUMOF ARRAY_SIZE(pwm_config)
185static const uint32_t spi_clk_config[] = {
186 (
187 SPI_CTAR_PBR(0) | SPI_CTAR_BR(8) | /* -> 93750Hz */
188 SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(8) |
189 SPI_CTAR_PASC(0) | SPI_CTAR_ASC(8) |
190 SPI_CTAR_PDT(0) | SPI_CTAR_DT(8)
191 ),
192 (
193 SPI_CTAR_PBR(0) | SPI_CTAR_BR(6) | /* -> 375000Hz */
194 SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(6) |
195 SPI_CTAR_PASC(0) | SPI_CTAR_ASC(6) |
196 SPI_CTAR_PDT(0) | SPI_CTAR_DT(6)
197 ),
198 (
199 SPI_CTAR_PBR(1) | SPI_CTAR_BR(4) | /* -> 1000000Hz */
200 SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(3) |
201 SPI_CTAR_PASC(1) | SPI_CTAR_ASC(3) |
202 SPI_CTAR_PDT(1) | SPI_CTAR_DT(3)
203 ),
204 (
205 SPI_CTAR_PBR(2) | SPI_CTAR_BR(0) | /* -> 4800000Hz */
206 SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(0) |
207 SPI_CTAR_PASC(2) | SPI_CTAR_ASC(0) |
208 SPI_CTAR_PDT(2) | SPI_CTAR_DT(0)
209 ),
210 (
211 SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 8000000Hz */
212 SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
213 SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
214 SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
215 )
216};
217
218static const spi_conf_t spi_config[] = {
219 {
220 .dev = SPI0,
221 .pin_miso = GPIO_PIN(PORT_C, 7),
222 .pin_mosi = GPIO_PIN(PORT_C, 6),
223 .pin_clk = GPIO_PIN(PORT_C, 5),
224 .pin_cs = {
225 GPIO_PIN(PORT_C, 4),
230 },
231 .pcr = GPIO_AF_2,
232 .simmask = SIM_SCGC6_SPI0_MASK
233 },
234 {
235 .dev = SPI1,
236 .pin_miso = GPIO_PIN(PORT_B, 17),
237 .pin_mosi = GPIO_PIN(PORT_B, 16),
238 .pin_clk = GPIO_PIN(PORT_B, 11),
239 .pin_cs = {
240 GPIO_PIN(PORT_B, 10),
245 },
246 .pcr = GPIO_AF_2,
247 .simmask = SIM_SCGC6_SPI1_MASK
248 }
249};
250
251#define SPI_NUMOF ARRAY_SIZE(spi_config)
258static const i2c_conf_t i2c_config[] = {
259 {
260 .i2c = I2C1,
261 .scl_pin = GPIO_PIN(PORT_E, 1),
262 .sda_pin = GPIO_PIN(PORT_E, 0),
263 .freq = CLOCK_BUSCLOCK,
264 .speed = I2C_SPEED_FAST,
265 .irqn = I2C1_IRQn,
266 .scl_pcr = (PORT_PCR_MUX(6) | PORT_PCR_ODE_MASK),
267 .sda_pcr = (PORT_PCR_MUX(6) | PORT_PCR_ODE_MASK),
268 },
269};
270#define I2C_NUMOF ARRAY_SIZE(i2c_config)
271#define I2C_0_ISR (isr_i2c1)
274#ifdef __cplusplus
275}
276#endif
277
278#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
@ 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
@ 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