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 static const clock_config_t clock_config = {
37  /*
38  * This configuration results in the system running from the FLL output with
39  * the following clock frequencies:
40  * Core: 48 MHz
41  * Bus: 48 MHz
42  * Flex: 24 MHz
43  * Flash: 24 MHz
44  */
45  /* The board has a 16 MHz crystal, though it is not used in this configuration */
46  /* This configuration uses the RTC crystal to provide the base clock, it
47  * should have better accuracy than the internal slow clock, and lower power
48  * consumption than using the 16 MHz crystal and the OSC0 module */
49  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
50  SIM_CLKDIV1_OUTDIV3(2) | SIM_CLKDIV1_OUTDIV4(2),
51  .default_mode = KINETIS_MCG_MODE_FEE,
52  .erc_range = KINETIS_MCG_ERC_RANGE_LOW, /* Input clock is 32768 Hz */
53  .fcrdiv = 0, /* Fast IRC divide by 1 => 4 MHz */
54  .oscsel = 1, /* Use RTC for external clock */
55  /* 16 pF capacitors yield ca 10 pF load capacitance as required by the
56  * onboard xtal, not used when OSC0 is disabled */
57  .clc = 0b0001,
58  .fll_frdiv = 0b000, /* Divide by 1 => FLL input 32768 Hz */
59  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
60  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
61  /* PLL is unavailable when using a 32768 Hz source clock, so the
62  * configuration below can only be used if the above config is modified to
63  * use the 16 MHz crystal instead of the RTC. */
64  .pll_prdiv = 0b00111, /* Divide by 8 */
65  .pll_vdiv = 0b01100, /* Multiply by 36 => PLL freq = 72 MHz */
66  .enable_oscillator = false, /* the RTC module provides the clock input signal */
67  .select_fast_irc = true, /* Only used for FBI mode */
68  .enable_mcgirclk = false,
69 };
70 #define CLOCK_CORECLOCK (48000000ul)
71 #define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1)
72 
78 #define PIT_NUMOF (2U)
79 #define PIT_CONFIG { \
80  { \
81  .prescaler_ch = 0, \
82  .count_ch = 1, \
83  }, \
84  { \
85  .prescaler_ch = 2, \
86  .count_ch = 3, \
87  }, \
88  }
89 #define LPTMR_NUMOF (1U)
90 #define LPTMR_CONFIG { \
91  { \
92  .dev = LPTMR0, \
93  .irqn = LPTMR0_IRQn, \
94  } \
95  }
96 #define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
97 
98 #define PIT_BASECLOCK (CLOCK_BUSCLOCK)
99 #define PIT_ISR_0 isr_pit1
100 #define PIT_ISR_1 isr_pit3
101 #define LPTMR_ISR_0 isr_lptmr0
102 
109 static const uart_conf_t uart_config[] = {
110  {
111  .dev = UART0,
112  .freq = CLOCK_CORECLOCK,
113  .pin_rx = GPIO_PIN(PORT_A, 14),
114  .pin_tx = GPIO_PIN(PORT_A, 15),
115  .pcr_rx = PORT_PCR_MUX(3),
116  .pcr_tx = PORT_PCR_MUX(3),
117  .irqn = UART0_RX_TX_IRQn,
118  .scgc_addr = &SIM->SCGC4,
119  .scgc_bit = SIM_SCGC4_UART0_SHIFT,
120  .mode = UART_MODE_8N1,
121  .type = KINETIS_UART,
122  },
123  {
124  .dev = UART1,
125  .freq = CLOCK_CORECLOCK,
126  .pin_rx = GPIO_PIN(PORT_C, 3),
127  .pin_tx = GPIO_PIN(PORT_C, 4),
128  .pcr_rx = PORT_PCR_MUX(3),
129  .pcr_tx = PORT_PCR_MUX(3),
130  .irqn = UART1_RX_TX_IRQn,
131  .scgc_addr = &SIM->SCGC4,
132  .scgc_bit = SIM_SCGC4_UART1_SHIFT,
133  .mode = UART_MODE_8N1,
134  .type = KINETIS_UART,
135  },
136 };
137 
138 #define UART_0_ISR (isr_uart0_rx_tx)
139 #define UART_1_ISR (isr_uart1_rx_tx)
140 
141 #define UART_NUMOF (sizeof(uart_config) / sizeof(uart_config[0]))
142 
148 static const adc_conf_t adc_config[] = {
149  /* internal: temperature sensor */
150  [ 0] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 26 },
151  /* internal: band gap */
152  [ 1] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 27 },
153  /* internal: V_REFSH */
154  [ 2] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 29 },
155  /* internal: V_REFSL */
156  [ 3] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 30 },
157  /* internal: DAC0 module output level */
158  [ 4] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 23 },
159  /* internal: VREF module output level */
160  [ 5] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 18 },
161  /* on board connection to Mulle Vbat/2 on PGA1_DP pin */
162  [ 6] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 0 },
163  /* on board connection to Mulle Vchr/2 on PGA1_DM pin */
164  [ 7] = { .dev = ADC1, .pin = GPIO_UNDEF, .chan = 19 },
165  /* expansion port PGA0_DP pin */
166  [ 8] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 0 },
167  /* expansion port PGA0_DM pin */
168  [ 9] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 19 },
169  /* expansion port PTA17 */
170  [10] = { .dev = ADC1, .pin = GPIO_PIN(PORT_A, 17), .chan = 17 },
171  /* expansion port PTB0 */
172  [11] = { .dev = ADC1, .pin = GPIO_PIN(PORT_B, 0), .chan = 8 },
173  /* expansion port PTC0 */
174  [12] = { .dev = ADC0, .pin = GPIO_PIN(PORT_C, 0), .chan = 14 },
175  /* expansion port PTC8 */
176  [13] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 8), .chan = 4 },
177  /* expansion port PTC9 */
178  [14] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 9), .chan = 5 },
179  /* expansion port PTC10 */
180  [15] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 10), .chan = 6 },
181  /* expansion port PTC11 */
182  [16] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 11), .chan = 7 }
183 };
184 
185 #define ADC_NUMOF (sizeof(adc_config) / sizeof(adc_config[0]))
186 
192 static const dac_conf_t dac_config[] = {
193  {
194  .dev = DAC0,
195  .scgc_addr = &SIM->SCGC2,
196  .scgc_bit = SIM_SCGC2_DAC0_SHIFT
197  }
198 };
199 
200 #define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0]))
201 
207 static const pwm_conf_t pwm_config[] = {
208  {
209  .ftm = FTM0,
210  .chan = {
211  { .pin = GPIO_PIN(PORT_C, 1), .af = 4, .ftm_chan = 0 },
212  { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 },
213  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
214  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
215  },
216  .chan_numof = 2,
217  .ftm_num = 0
218  },
219  {
220  .ftm = FTM1,
221  .chan = {
222  { .pin = GPIO_PIN(PORT_A, 12), .af = 3, .ftm_chan = 0 },
223  { .pin = GPIO_PIN(PORT_A, 13), .af = 3, .ftm_chan = 1 },
224  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
225  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
226  },
227  .chan_numof = 2,
228  .ftm_num = 1
229  }
230 };
231 
232 #define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0]))
233 
245 static const uint32_t spi_clk_config[] = {
246  (
247  SPI_CTAR_PBR(0) | SPI_CTAR_BR(8) | /* -> 93728Hz */
248  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(8) |
249  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(8) |
250  SPI_CTAR_PDT(0) | SPI_CTAR_DT(8)
251  ),
252  (
253  SPI_CTAR_PBR(0) | SPI_CTAR_BR(6) | /* -> 374912Hz */
254  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(6) |
255  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(6) |
256  SPI_CTAR_PDT(0) | SPI_CTAR_DT(6)
257  ),
258  (
259  SPI_CTAR_PBR(1) | SPI_CTAR_BR(4) | /* -> 999765Hz */
260  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(3) |
261  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(3) |
262  SPI_CTAR_PDT(1) | SPI_CTAR_DT(3)
263  ),
264  (
265  SPI_CTAR_PBR(2) | SPI_CTAR_BR(0) | /* -> 4798873Hz */
266  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(0) |
267  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(0) |
268  SPI_CTAR_PDT(2) | SPI_CTAR_DT(0)
269  ),
270  (
271  SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 7998122Hz */
272  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
273  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
274  SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
275  )
276 };
277 
278 static const spi_conf_t spi_config[] = {
279  {
280  .dev = SPI0,
281  .pin_miso = GPIO_PIN(PORT_D, 3),
282  .pin_mosi = GPIO_PIN(PORT_D, 2),
283  .pin_clk = GPIO_PIN(PORT_D, 1),
284  .pin_cs = {
285  GPIO_PIN(PORT_D, 0),
286  GPIO_PIN(PORT_D, 4),
287  GPIO_PIN(PORT_D, 5),
288  GPIO_PIN(PORT_D, 6),
289  GPIO_UNDEF
290  },
291  .pcr = GPIO_AF_2,
292  .simmask = SIM_SCGC6_SPI0_MASK
293  },
294  {
295  .dev = SPI1,
296  .pin_miso = GPIO_PIN(PORT_E, 3),
297  .pin_mosi = GPIO_PIN(PORT_E, 1),
298  .pin_clk = GPIO_PIN(PORT_E, 2),
299  .pin_cs = {
300  GPIO_PIN(PORT_E, 4),
301  GPIO_UNDEF,
302  GPIO_UNDEF,
303  GPIO_UNDEF,
304  GPIO_UNDEF
305  },
306  .pcr = GPIO_AF_2,
307  .simmask = SIM_SCGC6_SPI1_MASK
308  }
309 };
310 
311 #define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
312 
320 #define I2C_NUMOF (1U)
321 #define I2C_0_EN 1
322 #define I2C_1_EN 0
323 
324 /* I2C 0 device configuration */
325 #define I2C_0_DEV I2C0
326 #define I2C_0_CLKEN() (BITBAND_REG32(SIM->SCGC4, SIM_SCGC4_I2C0_SHIFT) = 1)
327 #define I2C_0_CLKDIS() (BITBAND_REG32(SIM->SCGC4, SIM_SCGC4_I2C0_SHIFT) = 0)
328 #define I2C_0_IRQ I2C0_IRQn
329 #define I2C_0_IRQ_HANDLER isr_i2c0
330 /* I2C 0 pin configuration */
331 #define I2C_0_PORT PORTB
332 #define I2C_0_PORT_CLKEN() (BITBAND_REG32(SIM->SCGC5, SIM_SCGC5_PORTB_SHIFT) = 1)
333 #define I2C_0_PIN_AF 2
334 #define I2C_0_SDA_PIN 1
335 #define I2C_0_SCL_PIN 2
336 #define I2C_0_PORT_CFG (PORT_PCR_MUX(I2C_0_PIN_AF) | PORT_PCR_ODE_MASK)
337 
343 /* Low (10 kHz): MUL = 2, SCL divider = 2560, total: 5120 */
344 #define KINETIS_I2C_F_ICR_LOW (0x3D)
345 #define KINETIS_I2C_F_MULT_LOW (1)
346 /* Normal (100 kHz): MUL = 2, SCL divider = 240, total: 480 */
347 #define KINETIS_I2C_F_ICR_NORMAL (0x1F)
348 #define KINETIS_I2C_F_MULT_NORMAL (1)
349 /* Fast (400 kHz): MUL = 1, SCL divider = 128, total: 128 */
350 #define KINETIS_I2C_F_ICR_FAST (0x17)
351 #define KINETIS_I2C_F_MULT_FAST (0)
352 /* Fast plus (1000 kHz): MUL = 1, SCL divider = 48, total: 48 */
353 #define KINETIS_I2C_F_ICR_FAST_PLUS (0x10)
354 #define KINETIS_I2C_F_MULT_FAST_PLUS (0)
355 
361 /* RIOT RTC implementation uses RTT for underlying timekeeper */
362 #define RTC_NUMOF (1U)
363 
369 #define RTT_NUMOF (1U)
370 #define RTT_IRQ RTC_IRQn
371 #define RTT_IRQ_PRIO 10
372 #define RTT_ISR isr_rtc
373 #define RTT_DEV RTC
374 #define RTT_UNLOCK() (BITBAND_REG32(SIM->SCGC6, SIM_SCGC6_RTC_SHIFT) = 1)
375 #define RTT_MAX_VALUE (0xffffffff)
376 #define RTT_FREQUENCY (1) /* in Hz */
377 
381 /* The crystal on the Mulle is designed for 12.5 pF load capacitance. According
382  * to the data sheet, the K60 will have a 5 pF parasitic capacitance on the
383  * XTAL32/EXTAL32 connection. The board traces might give some minor parasitic
384  * capacitance as well. */
385 /* Use the equation
386  * CL = (C1 * C2) / (C1 + C2) + Cstray
387  * with C1 == C2:
388  * C1 = 2 * (CL - Cstray)
389  */
390 /* enable 14pF load capacitor which will yield a crystal load capacitance of 12 pF */
391 #define RTC_LOAD_CAP_BITS (RTC_CR_SC8P_MASK | RTC_CR_SC4P_MASK | RTC_CR_SC2P_MASK)
392 
395 #ifdef __cplusplus
396 }
397 #endif
398 
399 #endif /* PERIPH_CONF_H */
400 
void * dev
UART, USART or LEUART device used.
FTM_Type * ftm
used FTM
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
cc2538_uart_t *const UART0
UART0 Instance.
PWM device configuration.
uint32_t clkdiv1
Clock divider bitfield setting, see reference manual for SIM_CLKDIV1.
8 data bits, no parity, 1 stop bit
ADC_TypeDef * dev
ADC device used.
use alternate function 2
FLL Engaged External Mode.
Clock configuration for Kinetis CPUs.
for 31.25-39.0625 kHz crystal
UART device configuration.
DAC line configuration data.
#define GPIO_UNDEF
Define custom value to speficy undefined or unused GPIOs.
SPI module configuration options.
#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.
cc2538_uart_t *const UART1
UART1 Instance.
Kinetis UART module type.
cc2538_ssi_t * dev
SSI device.