Loading...
Searching...
No Matches
cfg_clock_default.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Prime Controls, Inc.(R)
3 * SPDX-FileCopyrightText: 2025 Technische Universität Hamburg
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include "cpu_conf.h"
32#include "kernel_defines.h"
33#include "modules.h"
34#include "macros/units.h"
35#include "lse.h"
36#include "lsi.h"
37
38/* ==========================
39 * DEFAULT CONFIGURATION - HSI PLL
40 * ========================== */
41
47#ifndef CONFIG_USE_HSI_DIRECT
48# define CONFIG_USE_HSI_DIRECT 0
49#endif
50
54#ifndef CONFIG_USE_HSI_PLL
55# if IS_ACTIVE(CONFIG_USE_HSI_DIRECT) || IS_ACTIVE(CONFIG_USE_HSE_DIRECT) || \
56 IS_ACTIVE(CONFIG_USE_CSI_DIRECT) || IS_ACTIVE(CONFIG_USE_CSI_PLL) || \
57 IS_ACTIVE(CONFIG_USE_HSE_PLL)
58# define CONFIG_USE_HSI_PLL 0
59# else
60# define CONFIG_USE_HSI_PLL 1
61#endif
62#endif
63
68#ifndef CONFIG_CLOCK_HSI_DIV
69# define CONFIG_CLOCK_HSI_DIV 1
70#endif
71
75#ifndef CONFIG_USE_HSE_PLL
76# define CONFIG_USE_HSE_PLL 0
77#endif
78
82#ifndef CONFIG_USE_HSE_DIRECT
83# define CONFIG_USE_HSE_DIRECT 0
84#endif
85
89#ifndef CONFIG_USE_CSI_PLL
90# define CONFIG_USE_CSI_PLL 0
91#endif
92
96#ifndef CONFIG_USE_CSI_DIRECT
97# define CONFIG_USE_CSI_DIRECT 0
98#endif
99
100/* ==========================
101 * Base oscillator defaults
102 * ========================== */
103#if IS_ACTIVE(CONFIG_USE_HSI_DIRECT) || IS_ACTIVE(CONFIG_USE_HSI_PLL)
104# ifndef CONFIG_CLOCK_HSI
105# define CONFIG_CLOCK_HSI 64
106# endif
107#endif
108
109#if IS_ACTIVE(CONFIG_USE_HSE_PLL) || IS_ACTIVE(CONFIG_USE_HSE_DIRECT)
110# ifndef CONFIG_CLOCK_HSE
111# define CONFIG_CLOCK_HSE 8
112# endif
113#endif
114
115#if IS_ACTIVE(CONFIG_USE_CSI_DIRECT) || IS_ACTIVE(CONFIG_USE_CSI_PLL)
116# ifndef CONFIG_CLOCK_CSI
117# define CONFIG_CLOCK_CSI 4
118# endif
119#endif
120
121#ifndef CONFIG_CLOCK_LSE
122# define CONFIG_CLOCK_LSE 32768UL
123#endif
124
125#if IS_ACTIVE(CONFIG_USE_LSI)
126# ifndef CONFIG_CLOCK_LSI
127# define CONFIG_CLOCK_LSI 32000UL
128# endif
129#endif
130
136#ifndef CONFIG_CLOCK_CORECLOCK_DIV
137# define CONFIG_CLOCK_CORECLOCK_DIV 1
138#endif
139
140#if IS_ACTIVE(CONFIG_USE_HSI_PLL) || IS_ACTIVE(CONFIG_USE_HSE_PLL) || \
141 IS_ACTIVE(CONFIG_USE_CSI_PLL)
142/* --------------------------------------------------------------------------
143 * MODE: PLL-based (default)
144 * --------------------------------------------------------------------------
145 * SYSCLK source = PLL1_P output
146 * Target SYSCLK = 480 MHz
147 * -------------------------------------------------------------------------- */
148
149/* Default PLL1 configuration based on input clock. */
150# if (CONFIG_CLOCK_HSE == 8)
151 /* HSE with PLL1 → 480 MHz (VCO=960 MHz) */
152# ifndef CONFIG_CLOCK_PLL1_M
153# define CONFIG_CLOCK_PLL1_M 4
154# define CONFIG_CLOCK_PLL1_N 480
155# define CONFIG_CLOCK_PLL1_P 2
156# define CONFIG_CLOCK_PLL1_Q 20
157# define CONFIG_CLOCK_PLL1_R 2
158# endif
159
160# elif (CONFIG_CLOCK_HSE == 25)
161 /* HSE with PLL1 → 480 MHz (VCO=960 MHz) */
162# ifndef CONFIG_CLOCK_PLL1_M
163# define CONFIG_CLOCK_PLL1_M 5
164# define CONFIG_CLOCK_PLL1_N 192
165# define CONFIG_CLOCK_PLL1_P 2
166# define CONFIG_CLOCK_PLL1_Q 20
167# define CONFIG_CLOCK_PLL1_R 2
168# endif
169
170# elif (CONFIG_CLOCK_CSI == 4)
171 /* CSI with PLL1 → 480 MHz (VCO=960 MHz) */
172# ifndef CONFIG_CLOCK_PLL1_M
173# define CONFIG_CLOCK_PLL1_M 1
174# define CONFIG_CLOCK_PLL1_N 240
175# define CONFIG_CLOCK_PLL1_P 2
176# define CONFIG_CLOCK_PLL1_Q 20
177# define CONFIG_CLOCK_PLL1_R 2
178# endif
179
180# elif (CONFIG_CLOCK_HSI == 64)
181 /* HSI with PLL1 → 480 MHz (VCO=960 MHz) */
182# ifndef CONFIG_CLOCK_PLL1_M
183# define CONFIG_CLOCK_PLL1_M 8
184# define CONFIG_CLOCK_PLL1_N 120
185# define CONFIG_CLOCK_PLL1_P 2
186# define CONFIG_CLOCK_PLL1_Q 20
187# define CONFIG_CLOCK_PLL1_R 2
188# endif
189
190# else
191# error "Unsupported clock input for PLL configuration."
192# endif
193#endif /* CONFIG_USE_HSI_DIRECT */
194
195#include "clk/h7/lse.h"
196#include "clk/h7/lsi.h"
197#include "clk/h7/hse.h"
198#include "clk/h7/hsi.h"
199#include "clk/h7/csi.h"
200#include "clk/h7/pll1.h"
201#include "clk/h7/pll2.h"
202#include "clk/h7/pll3.h"
203#include "clk/h7/coreclock.h"
204
209#ifndef CONFIG_CLOCK_AHB_DIV
210# define CONFIG_CLOCK_AHB_DIV 2
211#endif
212
213#include "clk/h7/ahb.h"
214
219#ifndef CONFIG_CLOCK_APB1_DIV
220# define CONFIG_CLOCK_APB1_DIV 2
221#endif
222
227#ifndef CONFIG_CLOCK_APB2_DIV
228# define CONFIG_CLOCK_APB2_DIV 2
229#endif
230
235#ifndef CONFIG_CLOCK_APB3_DIV
236# define CONFIG_CLOCK_APB3_DIV 2
237#endif
238
243#ifndef CONFIG_CLOCK_APB4_DIV
244# define CONFIG_CLOCK_APB4_DIV 2
245#endif
246
247#include "clk/h7/apb1.h"
248#include "clk/h7/apb2.h"
249#include "clk/h7/apb3.h"
250#include "clk/h7/apb4.h"
251
252#ifdef __cplusplus
253}
254#endif
255
AHB clock configuration for STM32H7.
APB1 clock configuration for STM32H7.
APB2 clock configuration for STM32H7.
APB3 clock configuration for STM32H7.
APB4 clock configuration for STM32H7.
Core clock configuration for STM32H7.
CSI clock setup for STM32H7 family.
HSE clock setup for STM32H7 family.
HSI clock setup for STM32H7 family.
Common macros and compiler attributes/pragmas configuration.
LSE clock setup for STM32H7 family.
LSI clock setup for STM32H7 family.
Common macros and compiler attributes/pragmas configuration.
PLL1 clock setup for STM32H7 family.
PLL2 clock setup for STM32H7 family.
PLL3 clock setup for STM32H7 family.
Unit helper macros.