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