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