Loading...
Searching...
No Matches
pll2.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Technische Universität Hamburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#include "cfg_clock_default.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/* PLL2 configuration (DEFAULT): the following parameters configure a 48MHz USB clock
25 * with HSE (8MHz/25MHz) or HSI (64MHz) or CSI (4MHz) as PLL input clock. */
26#ifndef CONFIG_CLOCK_PLL2_M
27# if IS_ACTIVE(CONFIG_USE_CSI_PLL)
28# define CONFIG_CLOCK_PLL2_M (1)
29# elif IS_ACTIVE(CONFIG_USE_HSE_PLL)
30# if CONFIG_CLOCK_HSE == MHZ(8)
31# define CONFIG_CLOCK_PLL2_M (4)
32# elif CONFIG_CLOCK_HSE == MHZ(25)
33# define CONFIG_CLOCK_PLL2_M (5)
34# endif
35# else /* HSI - 64MHz */
36# define CONFIG_CLOCK_PLL2_M (8)
37# endif
38#endif
39
40#ifndef CONFIG_CLOCK_PLL2_N
41# if IS_ACTIVE(CONFIG_USE_CSI_PLL)
42# define CONFIG_CLOCK_PLL2_N (240)
43# elif IS_ACTIVE(CONFIG_USE_HSE_PLL)
44# if CONFIG_CLOCK_HSE == MHZ(8)
45# define CONFIG_CLOCK_PLL2_N (480)
46# elif CONFIG_CLOCK_HSE == MHZ(25)
47# define CONFIG_CLOCK_PLL2_N (192)
48# endif
49# else /* HSI */
50# define CONFIG_CLOCK_PLL2_N (120)
51# endif
52#endif
53
54#ifndef CONFIG_CLOCK_PLL2_P
55# if IS_ACTIVE(CONFIG_USE_CSI_PLL)
56# define CONFIG_CLOCK_PLL2_P (2)
57# elif IS_ACTIVE(CONFIG_USE_HSE_PLL)
58# if CONFIG_CLOCK_HSE == MHZ(8)
59# define CONFIG_CLOCK_PLL2_P (2)
60# elif CONFIG_CLOCK_HSE == MHZ(25)
61# define CONFIG_CLOCK_PLL2_P (2)
62# endif
63# else /* HSI */
64# define CONFIG_CLOCK_PLL2_P (2)
65# endif
66#endif
67
68#ifndef CONFIG_CLOCK_PLL2_Q
69# if IS_ACTIVE(CONFIG_USE_CSI_PLL)
70# define CONFIG_CLOCK_PLL2_Q (20)
71# elif IS_ACTIVE(CONFIG_USE_HSE_PLL)
72# if CONFIG_CLOCK_HSE == MHZ(8)
73# define CONFIG_CLOCK_PLL2_Q (20)
74# elif CONFIG_CLOCK_HSE == MHZ(25)
75# define CONFIG_CLOCK_PLL2_Q (20)
76# endif
77# else /* HSI */
78# define CONFIG_CLOCK_PLL2_Q (20)
79# endif
80#endif
81
82#ifndef CONFIG_CLOCK_PLL2_R
83# if IS_ACTIVE(CONFIG_USE_CSI_PLL)
84# define CONFIG_CLOCK_PLL2_R (2)
85# elif IS_ACTIVE(CONFIG_USE_HSE_PLL)
86# if CONFIG_CLOCK_HSE == MHZ(8)
87# define CONFIG_CLOCK_PLL2_R (2)
88# elif CONFIG_CLOCK_HSE == MHZ(25)
89# define CONFIG_CLOCK_PLL2_R (2)
90# endif
91# else /* HSI */
92# define CONFIG_CLOCK_PLL2_R (2)
93# endif
94#endif
95
96#if IS_ACTIVE(CONFIG_USE_HSI_PLL) || IS_ACTIVE(CONFIG_USE_HSE_PLL) || \
97 IS_ACTIVE(CONFIG_USE_CSI_PLL)
98
99/* Configure these values using KCONFIG */
100# define CLOCK_PLL2_M CONFIG_CLOCK_PLL2_M
101# define CLOCK_PLL2_N CONFIG_CLOCK_PLL2_N
102# define CLOCK_PLL2_P CONFIG_CLOCK_PLL2_P
103# define CLOCK_PLL2_Q CONFIG_CLOCK_PLL2_Q
104# define CLOCK_PLL2_R CONFIG_CLOCK_PLL2_R
105
106/* PLL2 input selection */
107# if IS_ACTIVE(CONFIG_USE_HSI_PLL)
108# define CLOCK_PLL2_INPUT CLOCK_HSI
109# elif IS_ACTIVE(CONFIG_USE_HSE_PLL)
110# define CLOCK_PLL2_INPUT CLOCK_HSE
111# elif IS_ACTIVE(CONFIG_USE_CSI_PLL)
112# define CLOCK_PLL2_INPUT CLOCK_CSI
113# endif
114
115/* PLL2 output frequencies */
116# define CLOCK_PLL2_VCO ((CLOCK_PLL2_INPUT * CLOCK_PLL2_N) / (CLOCK_PLL2_M))
117# define CLOCK_PLL2_P_OUT (CLOCK_PLL2_VCO / CLOCK_PLL2_P)
118# define CLOCK_PLL2_Q_OUT (CLOCK_PLL2_VCO / CLOCK_PLL2_Q)
119# define CLOCK_PLL2_R_OUT (CLOCK_PLL2_VCO / CLOCK_PLL2_R)
120
121#endif /* PLL usage */
122
123#ifdef __cplusplus
124}
125#endif
126
Main header for STM32H7 clock configuration (STM32H753ZI)