periph_conf_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Eistec AB
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
9 #pragma once
10 
21 #include "periph_cpu.h"
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
32 static const clock_config_t clock_config = {
33  /*
34  * This configuration results in the system running with the internal clock
35  * with the following clock frequencies:
36  * Core: 48 MHz
37  * Bus: 24 MHz
38  * Flash: 24 MHz
39  */
40  .clkdiv1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1),
41  /* unsure if this RTC load cap configuration is correct, but it matches the
42  * settings used by the example code in the NXP provided SDK */
43  .rtc_clc = 0,
44  /* Use the 32 kHz oscillator as ERCLK32K. Note that the values here have a
45  * different mapping for the KW41Z than the values used in the Kinetis K series */
46  .osc32ksel = SIM_SOPT1_OSC32KSEL(0),
47  .clock_flags =
48  KINETIS_CLOCK_OSC0_EN | /* Enable RSIM oscillator */
49  KINETIS_CLOCK_RTCOSC_EN |
50  KINETIS_CLOCK_USE_FAST_IRC |
51  KINETIS_CLOCK_MCGIRCLK_EN | /* Used for LPUART clocking */
52  KINETIS_CLOCK_MCGIRCLK_STOP_EN |
53  0,
54  /* Using FEI mode by default, the external crystal settings below are only
55  * used if mode is changed to an external mode (PEE, FBE, or FEE) */
56  .default_mode = KINETIS_MCG_MODE_FEI,
57  /* The crystal connected to RSIM OSC is 32 MHz */
58  .erc_range = KINETIS_MCG_ERC_RANGE_VERY_HIGH,
59  .osc_clc = 0, /* no load cap configuration */
60  .oscsel = MCG_C7_OSCSEL(0), /* Use RSIM for external clock */
61  .fcrdiv = MCG_SC_FCRDIV(0), /* Fast IRC divide by 1 => 4 MHz */
62  .fll_frdiv = MCG_C1_FRDIV(0b101), /* Divide by 1024 */
63  .fll_factor_fei = KINETIS_MCG_FLL_FACTOR_1464, /* FEI FLL freq = 48 MHz */
64  .fll_factor_fee = KINETIS_MCG_FLL_FACTOR_1280, /* FEE FLL freq = 40 MHz */
65 };
66 /* Radio xtal frequency, either 32 MHz or 26 MHz */
67 #define CLOCK_RADIOXTAL (32000000ul)
68 /* CPU core clock, the MCG clock output frequency */
69 #define CLOCK_CORECLOCK (48000000ul)
70 #define CLOCK_BUSCLOCK (CLOCK_CORECLOCK / 2)
71 #define CLOCK_MCGIRCLK (4000000ul)
78 #define PIT_NUMOF (1U)
79 #define PIT_CONFIG { \
80  { \
81  .prescaler_ch = 0, \
82  .count_ch = 1, \
83  }, \
84  }
85 #define LPTMR_NUMOF (1U)
86 #define LPTMR_CONFIG { \
87  { \
88  .dev = LPTMR0, \
89  .irqn = LPTMR0_IRQn, \
90  .src = 2, \
91  .base_freq = 32768u, \
92  } \
93  }
94 #define TIMER_NUMOF ((PIT_NUMOF) + (LPTMR_NUMOF))
95 #define PIT_BASECLOCK (CLOCK_BUSCLOCK)
96 #define LPTMR_ISR_0 isr_lptmr0
103 static const uart_conf_t uart_config[] = {
104  {
105  .dev = LPUART0,
106  .freq = CLOCK_MCGIRCLK,
107  .pin_rx = GPIO_PIN(PORT_C, 6),
108  .pin_tx = GPIO_PIN(PORT_C, 7),
109  .pcr_rx = PORT_PCR_MUX(4),
110  .pcr_tx = PORT_PCR_MUX(4),
111  .irqn = LPUART0_IRQn,
112  .scgc_addr = &SIM->SCGC5,
113  .scgc_bit = SIM_SCGC5_LPUART0_SHIFT,
114  .mode = UART_MODE_8N1,
115  .type = KINETIS_LPUART,
116  },
117 };
118 #define UART_NUMOF ARRAY_SIZE(uart_config)
119 #define LPUART_0_ISR isr_lpuart0
120 /* Use MCGIRCLK (internal reference 4 MHz clock) */
121 #define LPUART_0_SRC 3
134 static const uint32_t spi_clk_config[] = {
135  (
136  SPI_CTAR_PBR(2) | SPI_CTAR_BR(5) | /* -> 100000Hz */
137  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(4) |
138  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(4) |
139  SPI_CTAR_PDT(2) | SPI_CTAR_DT(4)
140  ),
141  (
142  SPI_CTAR_PBR(2) | SPI_CTAR_BR(3) | /* -> 400000Hz */
143  SPI_CTAR_PCSSCK(2) | SPI_CTAR_CSSCK(2) |
144  SPI_CTAR_PASC(2) | SPI_CTAR_ASC(2) |
145  SPI_CTAR_PDT(2) | SPI_CTAR_DT(2)
146  ),
147  (
148  SPI_CTAR_PBR(0) | SPI_CTAR_BR(3) | /* -> 1000000Hz */
149  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(3) |
150  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(3) |
151  SPI_CTAR_PDT(0) | SPI_CTAR_DT(3)
152  ),
153  (
154  SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | /* -> 4000000Hz */
155  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(1) |
156  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(1) |
157  SPI_CTAR_PDT(0) | SPI_CTAR_DT(1)
158  ),
159  (
160  SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | /* -> 4000000Hz */
161  SPI_CTAR_PCSSCK(0) | SPI_CTAR_CSSCK(0) |
162  SPI_CTAR_PASC(0) | SPI_CTAR_ASC(0) |
163  SPI_CTAR_PDT(0) | SPI_CTAR_DT(0)
164  )
165 };
172 #define KINETIS_TRNG TRNG
175 #ifdef __cplusplus
176 }
177 #endif
178 
@ PORT_C
port C
Definition: periph_cpu.h:48
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
static const spi_clk_conf_t spi_clk_config[]
Pre-calculated clock divider values based on a CLOCK_CORECLOCK (32MHz)
Definition: periph_cpu.h:281
static const uart_conf_t uart_config[]
Static array with configuration for declared UART devices.
@ KINETIS_LPUART
Kinetis Low-power UART (LPUART) module type.
Definition: periph_cpu.h:538
@ UART_MODE_8N1
8 data bits, no parity, 1 stop bit
Definition: periph_cpu.h:293
UART device configuration.
Definition: periph_cpu.h:217
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:218