Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
cfg_clock_default.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2017 Freie Universität Berlin
3
* 2019 Inria
4
*
5
* This file is subject to the terms and conditions of the GNU Lesser
6
* General Public License v2.1. See the file LICENSE in the top level
7
* directory for more details.
8
*/
9
10
#pragma once
11
23
#include "
cfg_clock_common_lx_u5_wx.h
"
24
#include "
kernel_defines.h
"
25
#include "
macros/units.h
"
26
27
#ifdef __cplusplus
28
extern
"C"
{
29
#endif
30
35
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE < MHZ(4) || CONFIG_CLOCK_HSE > MHZ(48))
36
#error "HSE clock frequency must be between 4MHz and 48MHz"
37
#endif
38
39
/* The following parameters configure a 80MHz system clock with PLL as input clock */
40
#ifndef CONFIG_CLOCK_PLL_SRC_MSI
41
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE) || IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSI) || \
42
IS_ACTIVE(CONFIG_BOARD_HAS_HSE)
43
#define CONFIG_CLOCK_PLL_SRC_MSI 0
44
#else
45
#define CONFIG_CLOCK_PLL_SRC_MSI 1
/* Use MSI as input clock by default */
46
#endif
47
#endif
/* CONFIG_CLOCK_PLL_SRC_MSI */
48
#ifndef CONFIG_CLOCK_PLL_SRC_HSE
49
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && \
50
!IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSI) && !IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_MSI)
51
#define CONFIG_CLOCK_PLL_SRC_HSE 1
52
#else
53
#define CONFIG_CLOCK_PLL_SRC_HSE 0
54
#endif
55
#endif
56
#ifndef CONFIG_CLOCK_PLL_SRC_HSI
57
#define CONFIG_CLOCK_PLL_SRC_HSI 0
58
#endif
59
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_MSI)
60
#define CLOCK_PLL_SRC (CONFIG_CLOCK_MSI)
61
#elif IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE)
62
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSE)
63
#else
/* CONFIG_CLOCK_PLL_SRC_ */
64
#define CLOCK_PLL_SRC (CONFIG_CLOCK_HSI)
65
#endif
66
#ifndef CONFIG_CLOCK_PLL_M
67
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_MSI)
68
#define CONFIG_CLOCK_PLL_M (6)
/* MSI at 48MHz */
69
#elif IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE) && (CONFIG_CLOCK_HSE == MHZ(8))
70
#define CONFIG_CLOCK_PLL_M (1)
/* HSE at 8MHz */
71
#elif IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE) && (CONFIG_CLOCK_HSE == MHZ(32))
72
#define CONFIG_CLOCK_PLL_M (4)
/* HSE at 32MHz */
73
#else
74
#define CONFIG_CLOCK_PLL_M (2)
/* HSI at 16MHz */
75
#endif
76
#endif
77
#ifndef CONFIG_CLOCK_PLL_N
78
#if IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE) && (CONFIG_CLOCK_HSE == MHZ(32))
79
/* For STM32WL, VCO output frequency ((PLL input clock frequency / PLLM ) x PLLN )
80
must be between 96 and 344 MHz. PLLN can have values <=127 & >=6 */
81
#if IS_ACTIVE(CPU_FAM_STM32WL)
82
#define CONFIG_CLOCK_PLL_N (12)
83
#else
84
#define CONFIG_CLOCK_PLL_N (16)
85
#endif
/* CPU_FAM_STM32WL */
86
#elif IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSI) || \
87
(IS_ACTIVE(CONFIG_CLOCK_PLL_SRC_HSE) && (CONFIG_CLOCK_HSE == MHZ(16)))
88
#define CONFIG_CLOCK_PLL_N (32)
89
#else
90
#if defined(CPU_LINE_STM32L4A6xx) || defined(CPU_LINE_STM32L4P5xx) || \
91
defined(CPU_LINE_STM32L4Q5xx) || defined(CPU_LINE_STM32L4R5xx) || \
92
defined(CPU_LINE_STM32L4R7xx) || defined(CPU_LINE_STM32L4R9xx) || \
93
defined(CPU_LINE_STM32L4S5xx) || defined(CPU_LINE_STM32L4S7xx) || \
94
defined(CPU_LINE_STM32L4S9xx)
95
#define CONFIG_CLOCK_PLL_N (30)
96
#elif defined(CPU_FAM_STM32L5)
97
#define CONFIG_CLOCK_PLL_N (27)
98
#else
99
#define CONFIG_CLOCK_PLL_N (20)
100
#endif
101
#endif
102
#endif
103
#ifndef CONFIG_CLOCK_PLL_Q
104
#define CONFIG_CLOCK_PLL_Q (2)
105
#endif
106
#ifndef CONFIG_CLOCK_PLL_R
107
#define CONFIG_CLOCK_PLL_R (2)
108
#endif
109
110
#if IS_ACTIVE(CONFIG_USE_CLOCK_HSI)
111
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSI)
112
113
#elif IS_ACTIVE(CONFIG_USE_CLOCK_HSE)
114
#define CLOCK_CORECLOCK (CONFIG_CLOCK_HSE)
115
116
#elif IS_ACTIVE(CONFIG_USE_CLOCK_MSI)
117
#define CLOCK_CORECLOCK (CONFIG_CLOCK_MSI)
118
119
#elif IS_ACTIVE(CONFIG_USE_CLOCK_PLL)
120
/* PLL configuration: make sure your values are legit!
121
*
122
* compute by: CORECLOCK = (((PLL_IN / M) * N) / R)
123
* with:
124
* PLL_IN: input clock, HSE or MSI
125
* M: pre-divider, allowed range: [1:8]
126
* N: multiplier, allowed range: [8:86]
127
* R: post-divider, allowed range: [2:8]
128
*
129
* Also the following constraints need to be met:
130
* (PLL_IN / M) -> [4MHz:16MHz]
131
* (PLL_IN / M) * N -> [64MHz:344MHz]
132
* CORECLOCK -> 64MHz, 80MHZ or 120MHz MAX!
133
*/
134
#define CLOCK_CORECLOCK \
135
((CLOCK_PLL_SRC / CONFIG_CLOCK_PLL_M) * CONFIG_CLOCK_PLL_N) / CONFIG_CLOCK_PLL_R
136
137
/* Set max allowed sysclk */
138
#if defined(CPU_FAM_STM32WL)
139
#define CLOCK_CORECLOCK_MAX MHZ(48)
140
#elif defined(CPU_FAM_STM32WB)
141
#define CLOCK_CORECLOCK_MAX MHZ(64)
142
#elif defined(CPU_FAM_STM32L5)
143
#define CLOCK_CORECLOCK_MAX MHZ(110)
144
#elif defined(CPU_LINE_STM32L4A6xx) || defined(CPU_LINE_STM32L4P5xx) || \
145
defined(CPU_LINE_STM32L4Q5xx) || defined(CPU_LINE_STM32L4R5xx) || \
146
defined(CPU_LINE_STM32L4R7xx) || defined(CPU_LINE_STM32L4R9xx) || \
147
defined(CPU_LINE_STM32L4S5xx) || defined(CPU_LINE_STM32L4S7xx) || \
148
defined(CPU_LINE_STM32L4S9xx)
149
#define CLOCK_CORECLOCK_MAX MHZ(120)
150
#else
/* all the other L4 */
151
#define CLOCK_CORECLOCK_MAX MHZ(80)
152
#endif
153
154
#if CLOCK_CORECLOCK > CLOCK_CORECLOCK_MAX
155
#if CLOCK_CORECLOCK_MAX == MHZ(48)
156
#error "SYSCLK cannot exceed 48MHz"
157
#elif CLOCK_CORECLOCK_MAX == MHZ(64)
158
#error "SYSCLK cannot exceed 64MHz"
159
#elif CLOCK_CORECLOCK_MAX == MHZ(80)
160
#error "SYSCLK cannot exceed 80MHz"
161
#elif CLOCK_CORECLOCK_MAX == MHZ(110)
162
#error "SYSCLK cannot exceed 110MHz"
163
#elif CLOCK_CORECLOCK_MAX == MHZ(120)
164
#error "SYSCLK cannot exceed 120MHz"
165
#else
166
#error "invalid SYSCLK"
167
#endif
168
#endif
/* CLOCK_CORECLOCK > CLOCK_CORECLOCK_MAX */
169
#endif
/* CONFIG_USE_CLOCK_PLL */
170
171
#define CLOCK_AHB CLOCK_CORECLOCK
/* HCLK, max: 48/64/80/120MHz */
172
173
#ifndef CONFIG_CLOCK_APB1_DIV
174
#define CONFIG_CLOCK_APB1_DIV (4)
175
#endif
176
#define CLOCK_APB1 (CLOCK_AHB / CONFIG_CLOCK_APB1_DIV)
/* PCLK1, max: 48/64/80/120MHz */
177
#ifndef CONFIG_CLOCK_APB2_DIV
178
#define CONFIG_CLOCK_APB2_DIV (2)
179
#endif
180
#define CLOCK_APB2 (CLOCK_AHB / CONFIG_CLOCK_APB2_DIV)
/* PCLK1, max: 48/64/80/120MHz */
183
#ifdef __cplusplus
184
}
185
#endif
186
cfg_clock_common_lx_u5_wx.h
Base STM32Lx/U5/Wx clock configuration.
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
units.h
Unit helper macros.
Generated on Mon Jun 30 2025 18:46:45 by
1.9.1