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