periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universität Berlin
3  * Copyright (C) 2015 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 
20 #ifndef PERIPH_CONF_H
21 #define PERIPH_CONF_H
22 
23 #include "periph_cpu.h"
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
34 static const clock_config_t clock_config = {
35  /*
36  * This configuration results in the system running from the PLL output with
37  * the following clock frequencies:
38  * Core: 60 MHz
39  * Bus: 60 MHz
40  * Flex: 20 MHz
41  * Flash: 20 MHz
42  */
43  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
44  SIM_CLKDIV1_OUTDIV3(2) | SIM_CLKDIV1_OUTDIV4(2),
45  .rtc_clc = 0, /* External load caps on board */
46  .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
47  .clock_flags =
48  /* No OSC0_EN, use EXTAL directly without OSC0 */
49  KINETIS_CLOCK_RTCOSC_EN |
50  KINETIS_CLOCK_USE_FAST_IRC |
51  0,
52  .default_mode = KINETIS_MCG_MODE_PEE,
53  /* The board has an external RMII (Ethernet) clock which drives the ERC at 50 MHz */
54  .erc_range = KINETIS_MCG_ERC_RANGE_VERY_HIGH,
55  .osc_clc = 0, /* External load caps on board */
56  .oscsel = MCG_C7_OSCSEL(0), /* Use EXTAL for external clock */
57  .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
58  .fll_frdiv = MCG_C1_FRDIV(0b111), /* Divide by 1536 => FLL input 32252 Hz */
59  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
60  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1920, /* FLL freq = 62.5 MHz */
61  .pll_prdiv = MCG_C5_PRDIV0(0b10011), /* Divide by 20 */
62  .pll_vdiv = MCG_C6_VDIV0(0b00000), /* Multiply by 24 => PLL freq = 60 MHz */
63 };
64 #define CLOCK_CORECLOCK (60000000ul)
65 #define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1)
66 
72 #define PIT_NUMOF (2U)
73 #define PIT_CONFIG { \
74  { \
75  .prescaler_ch = 0, \
76  .count_ch = 1, \
77  }, \
78  { \
79  .prescaler_ch = 2, \
80  .count_ch = 3, \
81  }, \
82  }
83 #define LPTMR_NUMOF (1U)
84 #define LPTMR_CONFIG { \
85  { \
86  .dev = LPTMR0, \
87  .irqn = LPTMR0_IRQn, \
88  .src = 2, \
89  .base_freq = 32768u, \
90  }, \
91 }
92 #define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
93 
94 #define PIT_BASECLOCK (CLOCK_BUSCLOCK)
95 #define PIT_ISR_0 isr_pit1
96 #define PIT_ISR_1 isr_pit3
97 #define LPTMR_ISR_0 isr_lptmr0
98 
104 static const uart_conf_t uart_config[] = {
105  {
106  .dev = UART0,
107  .freq = CLOCK_CORECLOCK,
108  .pin_rx = GPIO_PIN(PORT_B, 16),
109  .pin_tx = GPIO_PIN(PORT_B, 17),
110  .pcr_rx = PORT_PCR_MUX(3),
111  .pcr_tx = PORT_PCR_MUX(3),
112  .irqn = UART0_RX_TX_IRQn,
113  .scgc_addr = &SIM->SCGC4,
114  .scgc_bit = SIM_SCGC4_UART0_SHIFT,
115  .mode = UART_MODE_8N1,
116  .type = KINETIS_UART,
117  },
118 };
119 
120 #define UART_0_ISR (isr_uart0_rx_tx)
121 
122 #define UART_NUMOF ARRAY_SIZE(uart_config)
123 
129 static const adc_conf_t adc_config[] = {
130  [ 0] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 2), .chan = 12, .avg = ADC_AVG_MAX }, /* PTB2 (Arduino A0) */
131  [ 1] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 3), .chan = 13, .avg = ADC_AVG_MAX }, /* PTB3 (Arduino A1) */
132  [ 2] = { .dev = ADC1, .pin = GPIO_PIN(PORT_B, 10), .chan = 14, .avg = ADC_AVG_MAX }, /* PTB10 (Arduino A2) */
133  [ 3] = { .dev = ADC1, .pin = GPIO_PIN(PORT_B, 11), .chan = 15, .avg = ADC_AVG_MAX }, /* PTB11 (Arduino A3) */
134  [ 4] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 11), .chan = 7, .avg = ADC_AVG_MAX }, /* PTC11 (Arduino A4) */
135  [ 5] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 10), .chan = 6, .avg = ADC_AVG_MAX }, /* PTC10 (Arduino A5) */
136  [ 6] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC0_DP0 */
137  [ 7] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC0_DM0 */
138  [ 8] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC0_DP0 - ADC0_DM0 */
139  [ 9] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC1_DP0 */
140  [10] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC1_DM0 */
141  [11] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC1_DP0 - ADC1_DM0 */
142  [12] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 1, .avg = ADC_AVG_MAX }, /* ADC0_DP1 */
143  [13] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 20, .avg = ADC_AVG_MAX }, /* ADC0_DM1 */
144  [14] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC0_DP1 - ADC0_DM1 */
145  [15] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 1, .avg = ADC_AVG_MAX }, /* ADC1_DP1 */
146  [16] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 20, .avg = ADC_AVG_MAX }, /* ADC1_DM1 */
147  [17] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC1_DP1 - ADC1_DM1 */
148  /* internal: temperature sensor */
149  /* The temperature sensor has a very high output impedance, it must not be
150  * sampled using hardware averaging, or the sampled values will be garbage */
151  [18] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 26, .avg = ADC_AVG_NONE },
152  /* internal: band gap */
153  /* Note: the band gap buffer uses a bit of current and is turned off by default,
154  * Set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading or the input will be floating */
155  [19] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 27, .avg = ADC_AVG_MAX },
156 };
157 
158 #define ADC_NUMOF ARRAY_SIZE(adc_config)
159 /*
160  * K64F ADC reference settings:
161  * 0: VREFH/VREFL external pin pair
162  * 1: VREF_OUT internal 1.2 V reference (VREF module must be enabled)
163  * 2-3: reserved
164  */
165 #define ADC_REF_SETTING 0
166 
172 static const pwm_conf_t pwm_config[] = {
173  {
174  .ftm = FTM0,
175  .chan = {
176  { .pin = GPIO_PIN(PORT_A, 4), .af = 3, .ftm_chan = 6 },
177  { .pin = GPIO_PIN(PORT_A, 2), .af = 3, .ftm_chan = 7 },
178  { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 },
179  { .pin = GPIO_PIN(PORT_C, 3), .af = 4, .ftm_chan = 2 }
180  },
181  .chan_numof = 4,
182  .ftm_num = 0
183  }
184 };
185 
186 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
187 
200 static const uint32_t spi_clk_config[] = {
201  (
202  SPI_CTAR_PBR(2) | SPI_CTAR_BR(6) | /* -> 93750Hz */
203  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(5) |
204  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(5) |
205  SPI_CTAR_PDT(2) | SPI_CTAR_DT(5)
206  ),
207  (
208  SPI_CTAR_PBR(2) | SPI_CTAR_BR(4) | /* -> 375000Hz */
209  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(3) |
210  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(3) |
211  SPI_CTAR_PDT(2) | SPI_CTAR_DT(3)
212  ),
213  (
214  SPI_CTAR_PBR(2) | SPI_CTAR_BR(2) | /* -> 1000000Hz */
215  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(4) |
216  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(4) |
217  SPI_CTAR_PDT(0) | SPI_CTAR_DT(4)
218  ),
219  (
220  SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 5000000Hz */
221  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
222  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
223  SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
224  ),
225  (
226  SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | /* -> 7500000Hz */
227  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(1) |
228  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(1) |
229  SPI_CTAR_PDT(0) | SPI_CTAR_DT(1)
230  )
231 };
232 
233 static const spi_conf_t spi_config[] = {
234  {
235  .dev = SPI0,
236  .pin_miso = GPIO_PIN(PORT_D, 3),
237  .pin_mosi = GPIO_PIN(PORT_D, 2),
238  .pin_clk = GPIO_PIN(PORT_D, 1),
239  .pin_cs = {
240  GPIO_PIN(PORT_D, 0),
241  GPIO_UNDEF,
242  GPIO_UNDEF,
243  GPIO_UNDEF,
244  GPIO_UNDEF
245  },
246  .pcr = GPIO_AF_2,
247  .simmask = SIM_SCGC6_SPI0_MASK
248  }
249 };
250 
251 #define SPI_NUMOF ARRAY_SIZE(spi_config)
252 
259 static const i2c_conf_t i2c_config[] = {
260  {
261  .i2c = I2C0,
262  .scl_pin = GPIO_PIN(PORT_E, 24),
263  .sda_pin = GPIO_PIN(PORT_E, 25),
264  .freq = CLOCK_BUSCLOCK,
265  .speed = I2C_SPEED_FAST,
266  .irqn = I2C0_IRQn,
267  .scl_pcr = (PORT_PCR_MUX(5) | PORT_PCR_ODE_MASK),
268  .sda_pcr = (PORT_PCR_MUX(5) | PORT_PCR_ODE_MASK),
269  },
270 };
271 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
272 #define I2C_0_ISR (isr_i2c0)
273 #define I2C_1_ISR (isr_i2c1)
274 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif /* PERIPH_CONF_H */
281 
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
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