Loading...
Searching...
No Matches
cfg_clock_default.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018-2020 Inria
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
19#include "kernel_defines.h"
20#include "macros/units.h"
21#include "periph_cpu.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
31#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(1) || CONFIG_CLOCK_HSE > MHZ(24))
32#error "HSE clock frequency must be between 1MHz and 24MHz"
33#endif
34
35/* The following parameters configure a 32MHz system clock with HSI as input clock */
36#ifndef CONFIG_CLOCK_PLL_DIV
37#define CONFIG_CLOCK_PLL_DIV (2)
38#endif
39#ifndef CONFIG_CLOCK_PLL_MUL
40#define CONFIG_CLOCK_PLL_MUL (4)
41#endif
42
43#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
44#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
45
46#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
47#if !IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
48#error "The board doesn't provide an HSE oscillator"
49#endif
50#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
51
52#elif IS_ACTIVE(CONFIG_USE_CLOCK_MSI)
53#define CLOCK_CORECLOCK (CONFIG_CLOCK_MSI)
54
55#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
56#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
57#if CONFIG_CLOCK_HSE < MHZ(2)
58#error "HSE must be greater than 2MHz when used as PLL input clock"
59#endif
60#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
61#else /* CONFIG_CLOCK_HSI */
62#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
63#endif /* CONFIG_BOARD_HAS_HSE */
64/* PLL configuration: make sure your values are legit!
65 *
66 * compute by: CORECLOCK = ((PLL_IN / PLL_PREDIV) * PLL_MUL)
67 * with:
68 * PLL_IN: input clock is HSE if available or HSI otherwise
69 * PLL_DIV : divider, allowed values: 2, 3, 4. Default is 2.
70 * PLL_MUL: multiplier, allowed values: 3, 4, 6, 8, 12, 16, 24, 32, 48. Default is 4.
71 * CORECLOCK -> 32MHz MAX!
72 */
73#define CLOCK_CORECLOCK ((CLOCK_PLL_SRC * CONFIG_CLOCK_PLL_MUL) / CONFIG_CLOCK_PLL_DIV)
74#if CLOCK_CORECLOCK > MHZ(32)
75#error "SYSCLK cannot exceed 32MHz"
76#endif
77#endif /* CONFIG_USE_CLOCK_PLL */
78
79#define CLOCK_AHB CLOCK_CORECLOCK /* max: 32MHz */
80
81#ifndef CONFIG_CLOCK_APB1_DIV
82#define CONFIG_CLOCK_APB1_DIV (1)
83#endif
84#define CLOCK_APB1 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB1_DIV) /* max: 32MHz */
85#ifndef CONFIG_CLOCK_APB2_DIV
86#define CONFIG_CLOCK_APB2_DIV (1)
87#endif
88#define CLOCK_APB2 (CLOCK_CORECLOCK / CONFIG_CLOCK_APB2_DIV) /* max: 32MHz */
90
91#ifdef __cplusplus
92}
93#endif
94
Base STM32Lx/U5/Wx clock configuration.
Common macros and compiler attributes/pragmas configuration.
Unit helper macros.