boards/mulle/include/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 */
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 (sizeof(uart_config) / sizeof(uart_config[0]))
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 (sizeof(adc_config) / sizeof(adc_config[0]))
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 (sizeof(dac_config) / sizeof(dac_config[0]))
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 (sizeof(pwm_config) / sizeof(pwm_config[0]))
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 (sizeof(spi_config) / sizeof(spi_config[0]))
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 (sizeof(i2c_config) / sizeof(i2c_config[0]))
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 
fast mode: ~400kbit/s
cc2538_uart_t * dev
pointer to the used UART device
I2C configuration options.
static const spi_clk_conf_t spi_clk_config[]
Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz)
SPI_Type * dev
SPI device to use.
uint32_t clkdiv1
Clock divider bitfield setting.
pwm_conf_chan_t chan[3]
channel configuration
8 data bits, no parity, 1 stop bit
#define ADC_AVG_MAX
Maximum hardware averaging (32 samples)
ADC_TypeDef * dev
ADC device used.
use alternate function 2
#define ADC_AVG_NONE
Disable hardware averaging.
FLL Engaged External Mode.
#define CLOCK_BUSCLOCK
Bus clock frequency, used by several hardware modules in Kinetis CPUs.
Definition: mcg.h:144
Clock configuration for Kinetis CPUs.
for 31.25-39.0625 kHz crystal
I2C_Type * i2c
Pointer to hardware module registers.
UART device configuration.
DAC line configuration data.
SPI module configuration options.
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
#define CLOCK_CORECLOCK
Core clock frequency, used by the ARM core and certain hardware modules in Kinetis CPUs...
Definition: mcg.h:137
ADC device configuration.
Use the fast internal reference clock as MCGIRCLK signal.
Kinetis UART module type.