periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Eistec AB
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
19 #ifndef PERIPH_CONF_H
20 #define PERIPH_CONF_H
21 
22 #include "periph_cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
33 static const clock_config_t clock_config = {
34  /*
35  * This configuration results in the system running from the FLL output with
36  * the following clock frequencies:
37  * Core: 60 MHz
38  * Bus: 30 MHz
39  * Flex: 20 MHz
40  * Flash: 20 MHz
41  */
42  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(1) |
43  SIM_CLKDIV1_OUTDIV3(2) | SIM_CLKDIV1_OUTDIV4(2),
44  .rtc_clc = 0, /* External load caps on the FRDM-K22F board */
45  .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
46  .clock_flags =
47  KINETIS_CLOCK_OSC0_EN |
48  KINETIS_CLOCK_RTCOSC_EN |
49  KINETIS_CLOCK_USE_FAST_IRC |
50  0,
51  .default_mode = KINETIS_MCG_MODE_FEE,
52  /* The crystal connected to OSC0 is 8 MHz */
53  .erc_range = KINETIS_MCG_ERC_RANGE_HIGH,
54  .osc_clc = 0, /* External load caps on the FRDM-K22F board */
55  .oscsel = MCG_C7_OSCSEL(0), /* Use OSC0 for external clock */
56  .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
57  .fll_frdiv = MCG_C1_FRDIV(0b011), /* Divide by 256 */
58  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
59  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1920, /* FLL freq = 60 MHz */
60  .pll_prdiv = MCG_C5_PRDIV0(0b00011), /* Divide by 4 */
61  .pll_vdiv = MCG_C6_VDIV0(0b00110), /* Multiply by 30 => PLL freq = 60 MHz */
62 };
63 #define CLOCK_CORECLOCK (60000000ul)
64 #define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 2)
65 
71 #define PIT_NUMOF (2U)
72 #define PIT_CONFIG { \
73  { \
74  .prescaler_ch = 0, \
75  .count_ch = 1, \
76  }, \
77  { \
78  .prescaler_ch = 2, \
79  .count_ch = 3, \
80  }, \
81 }
82 #define LPTMR_NUMOF (1U)
83 #define LPTMR_CONFIG { \
84  { \
85  .dev = LPTMR0, \
86  .irqn = LPTMR0_IRQn, \
87  .src = 2, \
88  .base_freq = 32768u, \
89  }, \
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
96 #define LPTMR_ISR_0 isr_lptmr0
97 
103 static const uart_conf_t uart_config[] = {
104  {
105  .dev = UART1,
106  .freq = CLOCK_CORECLOCK,
107  .pin_rx = GPIO_PIN(PORT_E, 1),
108  .pin_tx = GPIO_PIN(PORT_E, 0),
109  .pcr_rx = PORT_PCR_MUX(3),
110  .pcr_tx = PORT_PCR_MUX(3),
111  .irqn = UART1_RX_TX_IRQn,
112  .scgc_addr = &SIM->SCGC4,
113  .scgc_bit = SIM_SCGC4_UART1_SHIFT,
114  .mode = UART_MODE_8N1,
115  .type = KINETIS_UART,
116  },
117  {
118  .dev = UART0,
119  .freq = CLOCK_CORECLOCK,
120  .pin_rx = GPIO_PIN(PORT_D, 6),
121  .pin_tx = GPIO_PIN(PORT_D, 7),
122  .pcr_rx = PORT_PCR_MUX(3),
123  .pcr_tx = PORT_PCR_MUX(3),
124  .irqn = UART0_RX_TX_IRQn,
125  .scgc_addr = &SIM->SCGC4,
126  .scgc_bit = SIM_SCGC4_UART0_SHIFT,
127  .mode = UART_MODE_8N1,
128  .type = KINETIS_UART,
129  },
130 };
131 
132 #define UART_0_ISR (isr_uart1_rx_tx)
133 #define UART_1_ISR (isr_uart0_rx_tx)
134 
135 #define UART_NUMOF ARRAY_SIZE(uart_config)
136 
142 static const adc_conf_t adc_config[] = {
143  /* dev, pin, channel */
144  [ 0] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC0_DP0 */
145  [ 1] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC0_DM0 */
146  [ 2] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC1_DP0 */
147  [ 3] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC1_DM0 */
148  [ 4] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 0), .chan = 8, .avg = ADC_AVG_MAX }, /* PTB0 (Arduino A0) */
149  [ 5] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 1), .chan = 9, .avg = ADC_AVG_MAX }, /* PTB1 (Arduino A1) */
150  [ 6] = { .dev = ADC0, .pin = GPIO_PIN(PORT_C, 1), .chan = 15, .avg = ADC_AVG_MAX }, /* PTC1 (Arduino A2) */
151  [ 7] = { .dev = ADC0, .pin = GPIO_PIN(PORT_C, 2), .chan = 4, .avg = ADC_AVG_MAX }, /* PTC2 (Arduino A3) */
152  /* internal: temperature sensor */
153  /* The temperature sensor has a very high output impedance, it must not be
154  * sampled using hardware averaging, or the sampled values will be garbage */
155  [ 8] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 26, .avg = ADC_AVG_NONE },
156  /* internal: band gap */
157  /* Note: the band gap buffer uses a bit of current and is turned off by default,
158  * Set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading or the input will be floating */
159  [ 9] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 27, .avg = ADC_AVG_MAX },
160 };
161 
162 #define ADC_NUMOF ARRAY_SIZE(adc_config)
163 /*
164  * K22F ADC reference settings:
165  * 0: VREFH/VREFL external pin pair
166  * 1: VREF_OUT internal 1.2 V reference (VREF module must be enabled)
167  * 2-3: reserved
168  */
169 #define ADC_REF_SETTING 0
170 
176 static const pwm_conf_t pwm_config[] = {
177  {
178  .ftm = FTM0,
179  .chan = {
180  { .pin = GPIO_PIN(PORT_A, 1), .af = 3, .ftm_chan = 6 },
181  { .pin = GPIO_PIN(PORT_A, 2), .af = 3, .ftm_chan = 7 },
182  { .pin = GPIO_PIN(PORT_D, 5), .af = 4, .ftm_chan = 5 },
183  },
184  .chan_numof = 3,
185  .ftm_num = 0
186  }
187 };
188 
189 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
190 
203 static const uint32_t spi_clk_config[] = {
204  (
205  SPI_CTAR_PBR(0) | SPI_CTAR_BR(8) | /* -> 93750Hz */
206  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(8) |
207  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(8) |
208  SPI_CTAR_PDT(0) | SPI_CTAR_DT(8)
209  ),
210  (
211  SPI_CTAR_PBR(0) | SPI_CTAR_BR(6) | /* -> 375000Hz */
212  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(6) |
213  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(6) |
214  SPI_CTAR_PDT(0) | SPI_CTAR_DT(6)
215  ),
216  (
217  SPI_CTAR_PBR(1) | SPI_CTAR_BR(4) | /* -> 1000000Hz */
218  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(3) |
219  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(3) |
220  SPI_CTAR_PDT(1) | SPI_CTAR_DT(3)
221  ),
222  (
223  SPI_CTAR_PBR(2) | SPI_CTAR_BR(0) | /* -> 4800000Hz */
224  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(0) |
225  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(0) |
226  SPI_CTAR_PDT(2) | SPI_CTAR_DT(0)
227  ),
228  (
229  SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 8000000Hz */
230  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
231  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
232  SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
233  )
234 };
235 
236 static const spi_conf_t spi_config[] = {
237  {
238  .dev = SPI0,
239  .pin_miso = GPIO_PIN(PORT_D, 3),
240  .pin_mosi = GPIO_PIN(PORT_D, 2),
241  .pin_clk = GPIO_PIN(PORT_D, 1),
242  .pin_cs = {
243  GPIO_PIN(PORT_C, 4),
244  GPIO_PIN(PORT_D, 4),
245  GPIO_UNDEF,
246  GPIO_UNDEF,
247  GPIO_UNDEF
248  },
249  .pcr = GPIO_AF_2,
250  .simmask = SIM_SCGC6_SPI0_MASK
251  }
252 };
253 
254 #define SPI_NUMOF ARRAY_SIZE(spi_config)
255 
262 static const i2c_conf_t i2c_config[] = {
263  {
264  .i2c = I2C0,
265  .scl_pin = GPIO_PIN(PORT_B, 2),
266  .sda_pin = GPIO_PIN(PORT_B, 3),
267  .freq = CLOCK_BUSCLOCK,
268  .speed = I2C_SPEED_FAST,
269  .irqn = I2C0_IRQn,
270  .scl_pcr = (PORT_PCR_MUX(2) | PORT_PCR_ODE_MASK),
271  .sda_pcr = (PORT_PCR_MUX(2) | PORT_PCR_ODE_MASK),
272  },
273 };
274 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
275 #define I2C_0_ISR (isr_i2c0)
276 #define I2C_1_ISR (isr_i2c1)
277 
279 #ifdef __cplusplus
280 }
281 #endif
282 
283 #endif /* PERIPH_CONF_H */
284 
PORT_E
@ PORT_E
port E
Definition: periph_cpu.h:40
pwm_conf_chan_t::pin
gpio_t pin
GPIO pin.
Definition: periph_cpu_common.h:308
PORT_C
@ PORT_C
port C
Definition: periph_cpu.h:38
CLOCK_CORECLOCK
#define CLOCK_CORECLOCK
GCLK reference speed.
Definition: periph_conf.h:32
spi_clk_config
static const spi_clk_conf_t spi_clk_config[]
Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz)
Definition: periph_cpu.h:260
adc_conf_t::dev
ADC_TypeDef * dev
ADC device used.
Definition: periph_cpu.h:75
PORT_A
@ PORT_A
port A
Definition: periph_cpu.h:36
PORT_D
@ PORT_D
port D
Definition: periph_cpu.h:39
KINETIS_UART
@ KINETIS_UART
Kinetis UART module type.
Definition: periph_cpu.h:507
UART_MODE_8N1
@ UART_MODE_8N1
8 data bits, no parity, 1 stop bit
Definition: periph_cpu.h:286
UART0
#define UART0
UART0 register bank.
Definition: cc26xx_cc13xx_uart.h:134
i2c_conf_t::i2c
I2C_Type * i2c
Pointer to hardware module registers.
Definition: periph_cpu.h:451
pwm_conf_t
PWM device configuration.
Definition: periph_cpu_common.h:153
GPIO_UNDEF
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
Definition: periph_cpu_common.h:52
uart_conf_t
UART device configuration.
Definition: periph_cpu.h:166
ADC_AVG_NONE
#define ADC_AVG_NONE
Disable hardware averaging.
Definition: periph_cpu.h:362
uart_conf_t::dev
cc2538_uart_t * dev
pointer to the used UART device
Definition: periph_cpu.h:167
adc_conf_t
ADC device configuration.
Definition: periph_cpu.h:74
GPIO_PIN
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:35
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
I2C_SPEED_FAST
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: i2c.h:178
PORT_B
@ PORT_B
port B
Definition: periph_cpu.h:37
spi_conf_t::dev
SPI_Type * dev
SPI device to use.
Definition: periph_cpu.h:465
pwm_conf_t::chan
const pwm_conf_chan_t * chan
channel configuration
Definition: periph_cpu_common.h:318
UART1
#define UART1
UART1 register bank.
Definition: cc26xx_cc13xx_uart.h:138
spi_conf_t
SPI configuration structure type.
Definition: periph_cpu.h:273
ADC_AVG_MAX
#define ADC_AVG_MAX
Maximum hardware averaging (32 samples)
Definition: periph_cpu.h:366