periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Inria
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef PERIPH_CONF_H
20 #define PERIPH_CONF_H
21 
22 #include "periph_cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
32 static const clock_config_t clock_config = {
33  /*
34  * This configuration results in the system running from the FLL output with
35  * the following clock frequencies:
36  * Core: 48 MHz
37  * Bus: 48 MHz
38  * Flex: 24 MHz
39  * Flash: 24 MHz
40  */
41  /* The board has a 16 MHz crystal, though it is not used in this configuration */
42  /* This configuration uses the RTC crystal to provide the base clock, it
43  * should have better accuracy than the internal slow clock, and lower power
44  * consumption than using the 16 MHz crystal and the OSC0 module */
45  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) |
46  SIM_CLKDIV1_OUTDIV3(1) | SIM_CLKDIV1_OUTDIV4(1),
47  /* RTC crystal has to be soldered by the user, we can't know the load cap requirements */
48  .rtc_clc = 0,
49  .osc32ksel = SIM_SOPT1_OSC32KSEL(2),
50  .clock_flags =
51  KINETIS_CLOCK_RTCOSC_EN |
52  KINETIS_CLOCK_USE_FAST_IRC |
53  0,
54  .default_mode = KINETIS_MCG_MODE_FEE,
55  .erc_range = KINETIS_MCG_ERC_RANGE_LOW, /* Input clock is 32768 Hz */
56  /* 16 pF capacitors yield ca 10 pF load capacitance as required by the
57  * onboard xtal, not used when OSC0 is disabled */
58  .osc_clc = OSC_CR_SC16P_MASK,
59  .oscsel = MCG_C7_OSCSEL(1), /* Use RTC oscillator as external clock */
60  .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
61  .fll_frdiv = MCG_C1_FRDIV(0b000), /* Divide by 1 => FLL input 32768 Hz */
62  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
63  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1464, /* FLL freq = 48 MHz */
64  /* PLL is unavailable when using a 32768 Hz source clock, so the
65  * configuration below can only be used if the above config is modified to
66  * use the 16 MHz crystal instead of the RTC. */
67  .pll_prdiv = MCG_C5_PRDIV0(0b00111), /* Divide by 8 */
68  .pll_vdiv = MCG_C6_VDIV0(0b01100), /* Multiply by 36 => PLL freq = 72 MHz */
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 (0U)
90 #define LPTMR_CONFIG { \
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 
103 static const uart_conf_t uart_config[] = {
104  {
105  .dev = UART0,
106  .freq = CLOCK_CORECLOCK,
107  .pin_rx = GPIO_PIN(PORT_B, 16), /* TEENSY PIN 0 */
108  .pin_tx = GPIO_PIN(PORT_B, 17), /* TEENSY PIN 1 */
109  .pcr_rx = PORT_PCR_MUX(3),
110  .pcr_tx = PORT_PCR_MUX(3),
111  .irqn = UART0_RX_TX_IRQn,
112  .scgc_addr = &SIM->SCGC4,
113  .scgc_bit = SIM_SCGC4_UART0_SHIFT,
114  .mode = UART_MODE_8N1,
115  .type = KINETIS_UART,
116  },
117  {
118  .dev = UART1,
119  .freq = CLOCK_CORECLOCK,
120  .pin_rx = GPIO_PIN(PORT_C, 3), /* TEENSY PIN 9 */
121  .pin_tx = GPIO_PIN(PORT_C, 4), /* TEENSY PIN 10 */
122  .pcr_rx = PORT_PCR_MUX(3),
123  .pcr_tx = PORT_PCR_MUX(3),
124  .irqn = UART1_RX_TX_IRQn,
125  .scgc_addr = &SIM->SCGC4,
126  .scgc_bit = SIM_SCGC4_UART1_SHIFT,
127  .mode = UART_MODE_8N1,
128  .type = KINETIS_UART,
129  },
130 };
131 
132 #define UART_0_ISR (isr_uart0_rx_tx)
133 #define UART_1_ISR (isr_uart1_rx_tx)
134 
135 #define UART_NUMOF ARRAY_SIZE(uart_config)
136 
142 static const pwm_conf_t pwm_config[] = {
143  {
144  .ftm = FTM0,
145  .chan = {
146  { .pin = GPIO_PIN(PORT_C, 1), .af = 4, .ftm_chan = 0 }, /* TEENSY PIN 22 */
147  { .pin = GPIO_PIN(PORT_C, 2), .af = 4, .ftm_chan = 1 }, /* TEENSY PIN 23 */
148  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
149  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
150  },
151  .chan_numof = 2,
152  .ftm_num = 0
153  },
154  {
155  .ftm = FTM1,
156  .chan = {
157  { .pin = GPIO_PIN(PORT_A, 12), .af = 3, .ftm_chan = 0 }, /* TEENSY PIN 3 */
158  { .pin = GPIO_PIN(PORT_A, 13), .af = 3, .ftm_chan = 1 }, /* TEENSY PIN 4 */
159  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 },
160  { .pin = GPIO_UNDEF, .af = 0, .ftm_chan = 0 }
161  },
162  .chan_numof = 2,
163  .ftm_num = 1
164  }
165 };
166 
167 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
168 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* PERIPH_CONF_H */
175 
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
PORT_A
@ PORT_A
port A
Definition: periph_cpu.h:36
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
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
GPIO_PIN
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:35
PORT_B
@ PORT_B
port B
Definition: periph_cpu.h:37
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