periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2016 Freie Universität Berlin
3  * Copyright (C) 2014 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 
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 PLL output with
39  * the following clock frequencies:
40  * Core: 48 MHz
41  * Bus: 48 MHz
42  * Flash: 24 MHz
43  */
44  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
45  SIM_CLKDIV1_OUTDIV4(1),
46  .rtc_clc = 0, /* External load caps on the FRDM-K22F board */
47  .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
48  .clock_flags =
49  /* No OSC0_EN, use modem clock from EXTAL0 */
50  KINETIS_CLOCK_RTCOSC_EN |
51  KINETIS_CLOCK_USE_FAST_IRC |
52  0,
53  .default_mode = KINETIS_MCG_MODE_PEE,
54  /* The modem generates a 4 MHz clock signal */
55  .erc_range = KINETIS_MCG_ERC_RANGE_HIGH,
56  .osc_clc = 0, /* OSC0 is unused*/
57  .oscsel = MCG_C7_OSCSEL(0), /* Use EXTAL0 for external clock */
58  .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
59  .fll_frdiv = MCG_C1_FRDIV(0b010), /* Divide by 128 */
60  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
61  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1280, /* FLL freq = 40 MHz */
62  .pll_prdiv = MCG_C5_PRDIV0(0b00001), /* Divide by 2 */
63  .pll_vdiv = MCG_C6_VDIV0(0b00000), /* Multiply by 24 => PLL freq = 48 MHz */
64 };
65 #define CLOCK_CORECLOCK (48000000ul)
66 #define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 1)
67 
73 #define PIT_NUMOF (2U)
74 #define PIT_CONFIG { \
75  { \
76  .prescaler_ch = 0, \
77  .count_ch = 1, \
78  }, \
79  { \
80  .prescaler_ch = 2, \
81  .count_ch = 3, \
82  }, \
83  }
84 #define LPTMR_NUMOF (0U)
85 #define LPTMR_CONFIG {}
86 #define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
87 
88 #define PIT_BASECLOCK (CLOCK_BUSCLOCK)
89 #define PIT_ISR_0 isr_pit1
90 #define PIT_ISR_1 isr_pit3
91 #define LPTMR_ISR_0 isr_lptmr0
92 
98 static const uart_conf_t uart_config[] = {
99  {
100  .dev = UART2,
101  .freq = CLOCK_BUSCLOCK,
102  .pin_rx = GPIO_PIN(PORT_D, 2),
103  .pin_tx = GPIO_PIN(PORT_D, 3),
104  .pcr_rx = PORT_PCR_MUX(3),
105  .pcr_tx = PORT_PCR_MUX(3),
106  .irqn = UART2_RX_TX_IRQn,
107  .scgc_addr = &SIM->SCGC4,
108  .scgc_bit = SIM_SCGC4_UART2_SHIFT,
109  .mode = UART_MODE_8N1,
110  .type = KINETIS_UART,
111  },
112  {
113  .dev = UART0,
114  .freq = CLOCK_CORECLOCK,
115  .pin_rx = GPIO_PIN(PORT_D, 6),
116  .pin_tx = GPIO_PIN(PORT_D, 7),
117  .pcr_rx = PORT_PCR_MUX(3),
118  .pcr_tx = PORT_PCR_MUX(3),
119  .irqn = UART0_RX_TX_IRQn,
120  .scgc_addr = &SIM->SCGC4,
121  .scgc_bit = SIM_SCGC4_UART0_SHIFT,
122  .mode = UART_MODE_8N1,
123  .type = KINETIS_UART,
124  }
125 };
126 
127 #define UART_0_ISR (isr_uart2_rx_tx)
128 #define UART_1_ISR (isr_uart0_rx_tx)
129 
130 #define UART_NUMOF ARRAY_SIZE(uart_config)
131 
137 static const adc_conf_t adc_config[] = {
138  [ 0] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 2), .chan = 1, .avg = ADC_AVG_MAX },
139  [ 1] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 3), .chan = 1, .avg = ADC_AVG_MAX },
140  [ 2] = { .dev = ADC0, .pin = GPIO_PIN(PORT_D, 7), .chan = 22, .avg = ADC_AVG_MAX },
141  [ 3] = { .dev = ADC0, .pin = GPIO_PIN(PORT_D, 5), .chan = 6, .avg = ADC_AVG_MAX },
142  [ 4] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 0), .chan = 10, .avg = ADC_AVG_MAX },
143  [ 5] = { .dev = ADC0, .pin = GPIO_PIN(PORT_E, 1), .chan = 11, .avg = ADC_AVG_MAX }
144 };
145 
146 #define ADC_NUMOF ARRAY_SIZE(adc_config)
147 /*
148  * KW2xD ADC reference settings:
149  * 0: VREFH/VREFL external pin pair
150  * 1-3: reserved
151  */
152 #define ADC_REF_SETTING 0
153 
159 static const pwm_conf_t pwm_config[] = {
160  {
161  .ftm = FTM0,
162  .chan = {
163  { .pin = GPIO_PIN(PORT_A, 4), .af = 3, .ftm_chan = 1 },
164  { .pin = GPIO_PIN(PORT_D, 4), .af = 4, .ftm_chan = 4 },
165  { .pin = GPIO_PIN(PORT_D, 6), .af = 4, .ftm_chan = 6 },
166  { .pin = GPIO_PIN(PORT_A, 1), .af = 3, .ftm_chan = 1 }
167  },
168  .chan_numof = 4,
169  .ftm_num = 0
170  }
171 };
172 
173 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
174 
187 static const uint32_t spi_clk_config[] = {
188  (
189  SPI_CTAR_PBR(0) | SPI_CTAR_BR(8) | /* -> 93750Hz */
190  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(8) |
191  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(8) |
192  SPI_CTAR_PDT(0) | SPI_CTAR_DT(8)
193  ),
194  (
195  SPI_CTAR_PBR(0) | SPI_CTAR_BR(6) | /* -> 375000Hz */
196  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(6) |
197  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(6) |
198  SPI_CTAR_PDT(0) | SPI_CTAR_DT(6)
199  ),
200  (
201  SPI_CTAR_PBR(1) | SPI_CTAR_BR(4) | /* -> 1000000Hz */
202  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(3) |
203  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(3) |
204  SPI_CTAR_PDT(1) | SPI_CTAR_DT(3)
205  ),
206  (
207  SPI_CTAR_PBR(2) | SPI_CTAR_BR(0) | /* -> 4800000Hz */
208  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(0) |
209  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(0) |
210  SPI_CTAR_PDT(2) | SPI_CTAR_DT(0)
211  ),
212  (
213  SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | /* -> 8000000Hz */
214  SPI_CTAR_PCSSCK(1) | SPI_CTAR_CSSCK(0) |
215  SPI_CTAR_PASC(1) | SPI_CTAR_ASC(0) |
216  SPI_CTAR_PDT(1) | SPI_CTAR_DT(0)
217  )
218 };
219 
220 static const spi_conf_t spi_config[] = {
221  {
222  .dev = SPI0,
223  .pin_miso = GPIO_PIN(PORT_C, 7),
224  .pin_mosi = GPIO_PIN(PORT_C, 6),
225  .pin_clk = GPIO_PIN(PORT_C, 5),
226  .pin_cs = {
227  GPIO_PIN(PORT_C, 4),
228  GPIO_UNDEF,
229  GPIO_UNDEF,
230  GPIO_UNDEF,
231  GPIO_UNDEF
232  },
233  .pcr = GPIO_AF_2,
234  .simmask = SIM_SCGC6_SPI0_MASK
235  },
236  {
237  .dev = SPI1,
238  .pin_miso = GPIO_PIN(PORT_B, 17),
239  .pin_mosi = GPIO_PIN(PORT_B, 16),
240  .pin_clk = GPIO_PIN(PORT_B, 11),
241  .pin_cs = {
242  GPIO_PIN(PORT_B, 10),
243  GPIO_UNDEF,
244  GPIO_UNDEF,
245  GPIO_UNDEF,
246  GPIO_UNDEF
247  },
248  .pcr = GPIO_AF_2,
249  .simmask = SIM_SCGC6_SPI1_MASK
250  }
251 };
252 
253 #define SPI_NUMOF ARRAY_SIZE(spi_config)
254 
261 static const i2c_conf_t i2c_config[] = {
262  {
263  .i2c = I2C1,
264  .scl_pin = GPIO_PIN(PORT_E, 1),
265  .sda_pin = GPIO_PIN(PORT_E, 0),
266  .freq = CLOCK_BUSCLOCK,
267  .speed = I2C_SPEED_FAST,
268  .irqn = I2C1_IRQn,
269  .scl_pcr = (PORT_PCR_MUX(6) | PORT_PCR_ODE_MASK),
270  .sda_pcr = (PORT_PCR_MUX(6) | PORT_PCR_ODE_MASK),
271  },
272 };
273 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
274 #define I2C_0_ISR (isr_i2c1)
275 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* PERIPH_CONF_H */
282 
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
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