Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
stm32_clock_control.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Open-RnD Sp. z o.o.
3 * Copyright (c) 2016 BayLibre, SAS
4 * Copyright (c) 2017-2022 Linaro Limited.
5 * Copyright (c) 2017 RnDity Sp. z o.o.
6 * Copyright (c) 2023 STMicroelectronics
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_STM32_CLOCK_CONTROL_H_
11#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_STM32_CLOCK_CONTROL_H_
13
15
16/* Retrieve the main system clock from DTS. */
17#define STM32_HCLK_FREQUENCY DT_PROP(DT_NODELABEL(rcc), clock_frequency)
18
19#if defined(CONFIG_SOC_SERIES_STM32C0X)
21#elif defined(CONFIG_SOC_SERIES_STM32C5X)
23#elif defined(CONFIG_SOC_SERIES_STM32F0X)
25#elif defined(CONFIG_SOC_SERIES_STM32F1X)
26#if defined(CONFIG_SOC_STM32F10X_CONNECTIVITY_LINE_DEVICE)
28#else
30#endif
31#elif defined(CONFIG_SOC_SERIES_STM32F3X)
33#elif defined(CONFIG_SOC_SERIES_STM32F2X) || \
34 defined(CONFIG_SOC_SERIES_STM32F4X)
37#elif defined(CONFIG_SOC_SERIES_STM32F7X)
39#elif defined(CONFIG_SOC_SERIES_STM32G0X)
41#elif defined(CONFIG_SOC_SERIES_STM32G4X)
43#elif defined(CONFIG_SOC_SERIES_STM32L0X)
45#elif defined(CONFIG_SOC_SERIES_STM32L1X)
47#elif defined(CONFIG_SOC_SERIES_STM32L4X)
49#elif defined(CONFIG_SOC_SERIES_STM32L5X)
51#elif defined(CONFIG_SOC_SERIES_STM32MP2X)
53#elif defined(CONFIG_SOC_SERIES_STM32WBX)
55#elif defined(CONFIG_SOC_SERIES_STM32WB0X)
57#elif defined(CONFIG_SOC_SERIES_STM32WLX)
59#elif defined(CONFIG_SOC_SERIES_STM32H5X)
61#elif defined(CONFIG_SOC_SERIES_STM32H7X)
63#elif defined(CONFIG_SOC_SERIES_STM32H7RSX)
65#elif defined(CONFIG_SOC_SERIES_STM32MP13X)
67#elif defined(CONFIG_SOC_SERIES_STM32N6X)
69#elif defined(CONFIG_SOC_SERIES_STM32U0X)
71#elif defined(CONFIG_SOC_SERIES_STM32U3X)
73#elif defined(CONFIG_SOC_SERIES_STM32U5X)
75#elif defined(CONFIG_SOC_SERIES_STM32WBAX)
77#else
79#endif
80
82#define STM32_CLOCK_CONTROL_NODE DT_NODELABEL(rcc)
83
85
86#define STM32_AHB_PRESCALER DT_PROP(DT_NODELABEL(rcc), ahb_prescaler)
87#define STM32_APB1_PRESCALER DT_PROP(DT_NODELABEL(rcc), apb1_prescaler)
88#define STM32_APB2_PRESCALER DT_PROP(DT_NODELABEL(rcc), apb2_prescaler)
89#define STM32_APB3_PRESCALER DT_PROP(DT_NODELABEL(rcc), apb3_prescaler)
90#define STM32_APB4_PRESCALER DT_PROP(DT_NODELABEL(rcc), apb4_prescaler)
91#define STM32_APB5_PRESCALER DT_PROP(DT_NODELABEL(rcc), apb5_prescaler)
92#define STM32_APB7_PRESCALER DT_PROP(DT_NODELABEL(rcc), apb7_prescaler)
93#define STM32_AHB3_PRESCALER DT_PROP(DT_NODELABEL(rcc), ahb3_prescaler)
94#define STM32_AHB4_PRESCALER DT_PROP(DT_NODELABEL(rcc), ahb4_prescaler)
95#define STM32_AHB5_PRESCALER DT_PROP_OR(DT_NODELABEL(rcc), ahb5_prescaler, 1)
96#define STM32_CPU1_PRESCALER DT_PROP(DT_NODELABEL(rcc), cpu1_prescaler)
97#define STM32_CPU2_PRESCALER DT_PROP(DT_NODELABEL(rcc), cpu2_prescaler)
98
99#if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), ahb_prescaler)
100#define STM32_CORE_PRESCALER STM32_AHB_PRESCALER
101#elif DT_NODE_HAS_PROP(DT_NODELABEL(rcc), cpu1_prescaler)
102#define STM32_CORE_PRESCALER STM32_CPU1_PRESCALER
103#endif
104
105#if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), ahb3_prescaler)
106#define STM32_FLASH_PRESCALER STM32_AHB3_PRESCALER
107#elif DT_NODE_HAS_PROP(DT_NODELABEL(rcc), ahb4_prescaler)
108#define STM32_FLASH_PRESCALER STM32_AHB4_PRESCALER
109#else
110#define STM32_FLASH_PRESCALER STM32_CORE_PRESCALER
111#endif
112
113#define STM32_TIMER_PRESCALER DT_PROP(DT_NODELABEL(rcc), timpre)
114
116#if defined(CONFIG_SOC_SERIES_STM32H7RSX)
117#define STM32_D1CPRE DT_PROP(DT_NODELABEL(rcc), dcpre)
118#define STM32_HPRE DT_PROP(DT_NODELABEL(rcc), hpre)
119#define STM32_PPRE1 DT_PROP(DT_NODELABEL(rcc), ppre1)
120#define STM32_PPRE2 DT_PROP(DT_NODELABEL(rcc), ppre2)
121#define STM32_PPRE4 DT_PROP(DT_NODELABEL(rcc), ppre4)
122#define STM32_PPRE5 DT_PROP(DT_NODELABEL(rcc), ppre5)
123#else
124#define STM32_D1CPRE DT_PROP(DT_NODELABEL(rcc), d1cpre)
125#define STM32_HPRE DT_PROP(DT_NODELABEL(rcc), hpre)
126#define STM32_D2PPRE1 DT_PROP(DT_NODELABEL(rcc), d2ppre1)
127#define STM32_D2PPRE2 DT_PROP(DT_NODELABEL(rcc), d2ppre2)
128#define STM32_D1PPRE DT_PROP(DT_NODELABEL(rcc), d1ppre)
129#define STM32_D3PPRE DT_PROP(DT_NODELABEL(rcc), d3ppre)
130#endif /* CONFIG_SOC_SERIES_STM32H7RSX */
131
133#define STM32_AHB5_DIV DT_PROP(DT_NODELABEL(rcc), ahb5_div)
134
135#define DT_RCC_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(rcc))
136
137/* To enable use of IS_ENABLED utility macro, these symbols
138 * should not be defined directly using DT_SAME_NODE.
139 */
140#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(pll))
141#define STM32_SYSCLK_SRC_PLL 1
142#endif
143#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
144#define STM32_SYSCLK_SRC_HSI 1
145#endif
146#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
147#define STM32_SYSCLK_SRC_HSE 1
148#endif
149#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
150#define STM32_SYSCLK_SRC_MSI 1
151#endif
152#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_msis))
153#define STM32_SYSCLK_SRC_MSIS 1
154#endif
155#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_csi))
156#define STM32_SYSCLK_SRC_CSI 1
157#endif
158#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(ic2))
159#define STM32_SYSCLK_SRC_IC2 1
160#endif
161#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_hsis))
162#define STM32_SYSCLK_SRC_HSIS 1
163#endif
164#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_hsidiv3))
165#define STM32_SYSCLK_SRC_HSIDIV3 1
166#endif
167#if DT_SAME_NODE(DT_RCC_CLOCKS_CTRL, DT_NODELABEL(clk_psis))
168#define STM32_SYSCLK_SRC_PSIS 1
169#endif
170
171#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(rcc), st_stm32n6_rcc, okay)
172#if (DT_SAME_NODE(DT_CLOCKS_CTLR_BY_IDX(DT_NODELABEL(cpusw), 0), DT_NODELABEL(rcc)))
173#if (DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(cpusw), 0, bus) == STM32_SRC_HSI)
174#define STM32_CPUCLK_SRC_HSI 1
175#elif (DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(cpusw), 0, bus) == STM32_SRC_MSI)
176#define STM32_CPUCLK_SRC_MSI 1
177#elif (DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(cpusw), 0, bus) == STM32_SRC_HSE)
178#define STM32_CPUCLK_SRC_HSE 1
179#elif (DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(cpusw), 0, bus) == STM32_SRC_IC1)
180#define STM32_CPUCLK_SRC_IC1 1
181#endif
182#endif /* cpusw clk source is rcc */
183
184#define STM32_TIMG_PRESCALER DT_PROP(DT_NODELABEL(rcc), timg_prescaler)
185#endif /* rcc node compatible st_stm32n6_rcc and okay */
186
188#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk48), st_stm32_clock_mux, okay)
189#define STM32_CK48_ENABLED 1
190#endif
191
192#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(rcc), st_stm32c5_rcc, okay)
193#define STM32_PSI_FREQ_MHZ_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(rcc), st_psi_frequency)
194#if STM32_PSI_FREQ_MHZ_ENABLED
195#define STM32_PSI_FREQ_MHZ DT_PROP(DT_NODELABEL(rcc), st_psi_frequency)
196#else
197#define STM32_PSI_FREQ_MHZ 144 /* Dummy value used for macro construction */
198#endif /* STM32_PSI_FREQ_MHZ_ENABLED */
199#define STM32_PSI_SOURCE_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(rcc), st_psi_source)
200#if STM32_PSI_SOURCE_ENABLED
201#define STM32_PSI_SOURCE DT_STRING_UPPER_TOKEN(DT_NODELABEL(rcc), st_psi_source)
202#else
203#define STM32_PSI_SOURCE HSIDIV18 /* Dummy value used for macro construction */
204#endif /* STM32_PSI_SOURCE_ENABLED */
205#endif /* compat st_stm32c5_rcc */
206
208
209#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32fx_pll_clock, okay) || \
210 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32g0_pll_clock, okay) || \
211 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32g4_pll_clock, okay) || \
212 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32l4_pll_clock, okay) || \
213 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32u0_pll_clock, okay) || \
214 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32u5_pll_clock, okay) || \
215 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32wb_pll_clock, okay) || \
216 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32wba_pll_clock, okay) || \
217 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32h5_pll_clock, okay) || \
218 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32h7_pll_clock, okay) || \
219 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32h7rs_pll_clock, okay) || \
220 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32mp13_pll_clock, okay)
221#define STM32_PLL_ENABLED 1
222#define STM32_PLL_M_DIVISOR DT_PROP(DT_NODELABEL(pll), div_m)
223#define STM32_PLL_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll), mul_n)
224#define STM32_PLL_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll), div_p)
225#define STM32_PLL_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pll), div_p, 1)
226#define STM32_PLL_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll), div_q)
227#define STM32_PLL_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pll), div_q, 1)
228#define STM32_PLL_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll), div_r)
229#define STM32_PLL_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pll), div_r, 1)
230#define STM32_PLL_POST_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll), post_div_r)
231#define STM32_PLL_POST_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pll), post_div_r, 1)
232#define STM32_PLL_S_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll), div_s)
233#define STM32_PLL_S_DIVISOR DT_PROP_OR(DT_NODELABEL(pll), div_s, 1)
234#define STM32_PLL_FRACN_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll), fracn)
235#define STM32_PLL_FRACN_VALUE DT_PROP_OR(DT_NODELABEL(pll), fracn, 0)
236#endif
237
238#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(plli2s), st_stm32fx_pll_clock, okay)
239#define STM32_PLLI2S_ENABLED 1
240#define STM32_PLLI2S_M_DIVISOR DT_PROP(DT_NODELABEL(plli2s), div_m)
241#define STM32_PLLI2S_N_MULTIPLIER DT_PROP(DT_NODELABEL(plli2s), mul_n)
242#define STM32_PLLI2S_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(plli2s), div_p)
243#define STM32_PLLI2S_P_DIVISOR DT_PROP_OR(DT_NODELABEL(plli2s), div_p, 1)
244#define STM32_PLLI2S_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(plli2s), div_q)
245#define STM32_PLLI2S_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(plli2s), div_q, 1)
246#define STM32_PLLI2S_POST_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(plli2s), post_div_q)
247#define STM32_PLLI2S_POST_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(plli2s), post_div_q, 1)
248#define STM32_PLLI2S_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(plli2s), div_r)
249#define STM32_PLLI2S_R_DIVISOR DT_PROP_OR(DT_NODELABEL(plli2s), div_r, 1)
250#define STM32_PLLI2S_POST_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(plli2s), post_div_r)
251#define STM32_PLLI2S_POST_R_DIVISOR DT_PROP_OR(DT_NODELABEL(plli2s), post_div_r, 1)
252#endif
253
254#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pllsai), st_stm32fx_pll_clock, okay)
255#define STM32_PLLSAI_ENABLED 1
256#define STM32_PLLSAI_M_DIVISOR DT_PROP(DT_NODELABEL(pllsai), div_m)
257#define STM32_PLLSAI_N_MULTIPLIER DT_PROP(DT_NODELABEL(pllsai), mul_n)
258#define STM32_PLLSAI_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai), div_p)
259#define STM32_PLLSAI_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai), div_p, 1)
260#define STM32_PLLSAI_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai), div_q)
261#define STM32_PLLSAI_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai), div_q, 1)
262#define STM32_PLLSAI_POST_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai), post_div_q)
263#define STM32_PLLSAI_POST_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai), post_div_q, 1)
264#define STM32_PLLSAI_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai), div_r)
265#define STM32_PLLSAI_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai), div_r, 1)
266#define STM32_PLLSAI_POST_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai), post_div_r)
267#define STM32_PLLSAI_POST_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai), post_div_r, 1)
268#endif
269
270#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pllsai1), st_stm32l4_pll_clock, okay)
271#define STM32_PLLSAI1_ENABLED 1
272#define STM32_PLLSAI1_M_DIVISOR DT_PROP(DT_NODELABEL(pllsai1), div_m)
273#define STM32_PLLSAI1_N_MULTIPLIER DT_PROP(DT_NODELABEL(pllsai1), mul_n)
274#define STM32_PLLSAI1_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai1), div_p)
275#define STM32_PLLSAI1_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai1), div_p, 1)
276#define STM32_PLLSAI1_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai1), div_q)
277#define STM32_PLLSAI1_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai1), div_q, 1)
278#define STM32_PLLSAI1_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai1), div_r)
279#define STM32_PLLSAI1_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai1), div_r, 1)
280#endif
281
282#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pllsai2), st_stm32l4_pll_clock, okay)
283#define STM32_PLLSAI2_ENABLED 1
284#define STM32_PLLSAI2_M_DIVISOR DT_PROP(DT_NODELABEL(pllsai2), div_m)
285#define STM32_PLLSAI2_N_MULTIPLIER DT_PROP(DT_NODELABEL(pllsai2), mul_n)
286#define STM32_PLLSAI2_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai2), div_p)
287#define STM32_PLLSAI2_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai2), div_p, 1)
288#define STM32_PLLSAI2_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai2), div_q)
289#define STM32_PLLSAI2_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai2), div_q, 1)
290#define STM32_PLLSAI2_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai2), div_r)
291#define STM32_PLLSAI2_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai2), div_r, 1)
292#define STM32_PLLSAI2_POST_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pllsai2), post_div_r)
293#define STM32_PLLSAI2_POST_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pllsai2), post_div_r, 1)
294#endif
295
296#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32u5_pll_clock, okay) || \
297 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32h5_pll_clock, okay) || \
298 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32h7_pll_clock, okay) || \
299 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32h7rs_pll_clock, okay) || \
300 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32mp13_pll_clock, okay)
301#define STM32_PLL2_ENABLED 1
302#define STM32_PLL2_M_DIVISOR DT_PROP(DT_NODELABEL(pll2), div_m)
303#define STM32_PLL2_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll2), mul_n)
304#define STM32_PLL2_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll2), div_p)
305#define STM32_PLL2_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pll2), div_p, 1)
306#define STM32_PLL2_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll2), div_q)
307#define STM32_PLL2_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pll2), div_q, 1)
308#define STM32_PLL2_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll2), div_r)
309#define STM32_PLL2_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pll2), div_r, 1)
310#define STM32_PLL2_S_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll2), div_s)
311#define STM32_PLL2_S_DIVISOR DT_PROP_OR(DT_NODELABEL(pll2), div_s, 1)
312#define STM32_PLL2_T_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll2), div_t)
313#define STM32_PLL2_T_DIVISOR DT_PROP_OR(DT_NODELABEL(pll2), div_t, 1)
314#define STM32_PLL2_FRACN_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll2), fracn)
315#define STM32_PLL2_FRACN_VALUE DT_PROP_OR(DT_NODELABEL(pll2), fracn, 0)
316#endif
317
318#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll3), st_stm32h5_pll_clock, okay) || \
319 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll3), st_stm32h7_pll_clock, okay) || \
320 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll3), st_stm32u5_pll_clock, okay) || \
321 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll3), st_stm32h7rs_pll_clock, okay) || \
322 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll3), st_stm32mp13_pll_clock, okay)
323#define STM32_PLL3_ENABLED 1
324#define STM32_PLL3_M_DIVISOR DT_PROP(DT_NODELABEL(pll3), div_m)
325#define STM32_PLL3_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll3), mul_n)
326#define STM32_PLL3_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll3), div_p)
327#define STM32_PLL3_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pll3), div_p, 1)
328#define STM32_PLL3_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll3), div_q)
329#define STM32_PLL3_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pll3), div_q, 1)
330#define STM32_PLL3_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll3), div_r)
331#define STM32_PLL3_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pll3), div_r, 1)
332#define STM32_PLL3_S_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll3), div_s)
333#define STM32_PLL3_S_DIVISOR DT_PROP_OR(DT_NODELABEL(pll3), div_s, 1)
334#define STM32_PLL3_FRACN_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll3), fracn)
335#define STM32_PLL3_FRACN_VALUE DT_PROP_OR(DT_NODELABEL(pll3), fracn, 0)
336#endif
337
338#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll4), st_stm32mp13_pll_clock, okay)
339#define STM32_PLL4_ENABLED 1
340#define STM32_PLL4_M_DIVISOR DT_PROP(DT_NODELABEL(pll4), div_m)
341#define STM32_PLL4_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll4), mul_n)
342#define STM32_PLL4_P_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll4), div_p)
343#define STM32_PLL4_P_DIVISOR DT_PROP_OR(DT_NODELABEL(pll4), div_p, 1)
344#define STM32_PLL4_Q_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll4), div_q)
345#define STM32_PLL4_Q_DIVISOR DT_PROP_OR(DT_NODELABEL(pll4), div_q, 1)
346#define STM32_PLL4_R_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll4), div_r)
347#define STM32_PLL4_R_DIVISOR DT_PROP_OR(DT_NODELABEL(pll4), div_r, 1)
348#define STM32_PLL4_FRACN_ENABLED DT_NODE_HAS_PROP(DT_NODELABEL(pll4), fracn)
349#define STM32_PLL4_FRACN_VALUE DT_PROP_OR(DT_NODELABEL(pll4), fracn, 0)
350#endif
351
352#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f1_pll_clock, okay)
353#define STM32_PLL_ENABLED 1
354#define STM32_PLL_XTPRE DT_PROP(DT_NODELABEL(pll), xtpre)
355#define STM32_PLL_MULTIPLIER DT_PROP(DT_NODELABEL(pll), mul)
356#define STM32_PLL_USBPRE DT_PROP(DT_NODELABEL(pll), usbpre)
357#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f0_pll_clock, okay) || \
358 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f100_pll_clock, okay) || \
359 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32f105_pll_clock, okay)
360#define STM32_PLL_ENABLED 1
361#define STM32_PLL_MULTIPLIER DT_PROP(DT_NODELABEL(pll), mul)
362#define STM32_PLL_PREDIV DT_PROP(DT_NODELABEL(pll), prediv)
363#define STM32_PLL_USBPRE DT_PROP(DT_NODELABEL(pll), otgfspre)
364#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll), st_stm32l0_pll_clock, okay)
365#define STM32_PLL_ENABLED 1
366#define STM32_PLL_DIVISOR DT_PROP(DT_NODELABEL(pll), div)
367#define STM32_PLL_MULTIPLIER DT_PROP(DT_NODELABEL(pll), mul)
368#endif
369
370#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32f105_pll2_clock, okay)
371#define STM32_PLL2_ENABLED 1
372#define STM32_PLL2_MULTIPLIER DT_PROP(DT_NODELABEL(pll2), mul)
373#define STM32_PLL2_PREDIV DT_PROP(DT_NODELABEL(pll2), prediv)
374#endif
375
376#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll1), st_stm32n6_pll_clock, okay)
377#define STM32_PLL1_ENABLED 1
378#define STM32_PLL1_M_DIVISOR DT_PROP(DT_NODELABEL(pll1), div_m)
379#define STM32_PLL1_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll1), mul_n)
380#define STM32_PLL1_P1_DIVISOR DT_PROP(DT_NODELABEL(pll1), div_p1)
381#define STM32_PLL1_P2_DIVISOR DT_PROP(DT_NODELABEL(pll1), div_p2)
382#endif
383
384#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll2), st_stm32n6_pll_clock, okay)
385#define STM32_PLL2_ENABLED 1
386#define STM32_PLL2_M_DIVISOR DT_PROP(DT_NODELABEL(pll2), div_m)
387#define STM32_PLL2_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll2), mul_n)
388#define STM32_PLL2_P1_DIVISOR DT_PROP(DT_NODELABEL(pll2), div_p1)
389#define STM32_PLL2_P2_DIVISOR DT_PROP(DT_NODELABEL(pll2), div_p2)
390#endif
391
392#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll3), st_stm32n6_pll_clock, okay)
393#define STM32_PLL3_ENABLED 1
394#define STM32_PLL3_M_DIVISOR DT_PROP(DT_NODELABEL(pll3), div_m)
395#define STM32_PLL3_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll3), mul_n)
396#define STM32_PLL3_P1_DIVISOR DT_PROP(DT_NODELABEL(pll3), div_p1)
397#define STM32_PLL3_P2_DIVISOR DT_PROP(DT_NODELABEL(pll3), div_p2)
398#endif
399
400#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pll4), st_stm32n6_pll_clock, okay)
401#define STM32_PLL4_ENABLED 1
402#define STM32_PLL4_M_DIVISOR DT_PROP(DT_NODELABEL(pll4), div_m)
403#define STM32_PLL4_N_MULTIPLIER DT_PROP(DT_NODELABEL(pll4), mul_n)
404#define STM32_PLL4_P1_DIVISOR DT_PROP(DT_NODELABEL(pll4), div_p1)
405#define STM32_PLL4_P2_DIVISOR DT_PROP(DT_NODELABEL(pll4), div_p2)
406#endif
407
409#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll)) && \
410 DT_NODE_HAS_PROP(DT_NODELABEL(pll), clocks)
411#define DT_PLL_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll))
412#if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
413#define STM32_PLL_SRC_MSI 1
414#endif
415#if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_msis))
416#define STM32_PLL_SRC_MSIS 1
417#endif
418#if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
419#define STM32_PLL_SRC_HSI 1
420#endif
421#if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_csi))
422#define STM32_PLL_SRC_CSI 1
423#endif
424#if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
425#define STM32_PLL_SRC_HSE 1
426#endif
427#if DT_SAME_NODE(DT_PLL_CLOCKS_CTRL, DT_NODELABEL(pll2))
428#define STM32_PLL_SRC_PLL2 1
429#endif
430
431#endif
432
434#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll2)) && \
435 DT_NODE_HAS_PROP(DT_NODELABEL(pll2), clocks)
436#define DT_PLL2_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll2))
437#if DT_SAME_NODE(DT_PLL2_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
438#define STM32_PLL2_SRC_MSI 1
439#endif
440#if DT_SAME_NODE(DT_PLL2_CLOCKS_CTRL, DT_NODELABEL(clk_msis))
441#define STM32_PLL2_SRC_MSIS 1
442#endif
443#if DT_SAME_NODE(DT_PLL2_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
444#define STM32_PLL2_SRC_HSI 1
445#endif
446#if DT_SAME_NODE(DT_PLL2_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
447#define STM32_PLL2_SRC_HSE 1
448#endif
449
450#endif
451
453#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(pll3)) && \
454 DT_NODE_HAS_PROP(DT_NODELABEL(pll3), clocks)
455#define DT_PLL3_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll3))
456#if DT_SAME_NODE(DT_PLL3_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
457#define STM32_PLL3_SRC_MSI 1
458#endif
459#if DT_SAME_NODE(DT_PLL3_CLOCKS_CTRL, DT_NODELABEL(clk_msis))
460#define STM32_PLL3_SRC_MSIS 1
461#endif
462#if DT_SAME_NODE(DT_PLL3_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
463#define STM32_PLL3_SRC_HSI 1
464#endif
465#if DT_SAME_NODE(DT_PLL3_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
466#define STM32_PLL3_SRC_HSE 1
467#endif
468
469#endif
470
472#if DT_NODE_HAS_STATUS(DT_NODELABEL(pll4), okay) && \
473 DT_NODE_HAS_PROP(DT_NODELABEL(pll4), clocks)
474#define DT_PLL4_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pll4))
475#if DT_SAME_NODE(DT_PLL4_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
476#define STM32_PLL4_SRC_MSI 1
477#endif
478#if DT_SAME_NODE(DT_PLL4_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
479#define STM32_PLL4_SRC_HSI 1
480#endif
481#if DT_SAME_NODE(DT_PLL4_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
482#define STM32_PLL4_SRC_HSE 1
483#endif
484
485#endif
486
488#if DT_NODE_HAS_STATUS(DT_NODELABEL(plli2s), okay) && \
489 DT_NODE_HAS_PROP(DT_NODELABEL(plli2s), clocks)
490#define DT_PLLI2S_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(plli2s))
491#if DT_SAME_NODE(DT_PLLI2S_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
492#define STM32_PLLI2S_SRC_HSI 1
493#endif
494#if DT_SAME_NODE(DT_PLLI2S_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
495#define STM32_PLLI2S_SRC_HSE 1
496#endif
497
498#endif
499
501#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllsai), okay) && \
502 DT_NODE_HAS_PROP(DT_NODELABEL(pllsai), clocks)
503#define DT_PLLSAI_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pllsai))
504#if DT_SAME_NODE(DT_PLLSAI_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
505#define STM32_PLLSAI_SRC_HSI 1
506#endif
507#if DT_SAME_NODE(DT_PLLSAI_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
508#define STM32_PLLSAI_SRC_HSE 1
509#endif
510
511#endif
512
514#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllsai1), okay) && \
515 DT_NODE_HAS_PROP(DT_NODELABEL(pllsai1), clocks)
516#define DT_PLLSAI1_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pllsai1))
517#if DT_SAME_NODE(DT_PLLSAI1_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
518#define STM32_PLLSAI1_SRC_MSI 1
519#endif
520#if DT_SAME_NODE(DT_PLLSAI1_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
521#define STM32_PLLSAI1_SRC_HSI 1
522#endif
523#if DT_SAME_NODE(DT_PLLSAI1_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
524#define STM32_PLLSAI1_SRC_HSE 1
525#endif
526
527#endif
528
530#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllsai2), okay) && \
531 DT_NODE_HAS_PROP(DT_NODELABEL(pllsai2), clocks)
532#define DT_PLLSAI2_CLOCKS_CTRL DT_CLOCKS_CTLR(DT_NODELABEL(pllsai2))
533#if DT_SAME_NODE(DT_PLLSAI2_CLOCKS_CTRL, DT_NODELABEL(clk_msi))
534#define STM32_PLLSAI2_SRC_MSI 1
535#endif
536#if DT_SAME_NODE(DT_PLLSAI2_CLOCKS_CTRL, DT_NODELABEL(clk_hsi))
537#define STM32_PLLSAI2_SRC_HSI 1
538#endif
539#if DT_SAME_NODE(DT_PLLSAI2_CLOCKS_CTRL, DT_NODELABEL(clk_hse))
540#define STM32_PLLSAI2_SRC_HSE 1
541#endif
542
543#endif
544
546
547#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_lse), fixed_clock, okay)
548#define STM32_LSE_ENABLED 1
549#define STM32_LSE_FREQ DT_PROP(DT_NODELABEL(clk_lse), clock_frequency)
550#define STM32_LSE_DRIVING 0
551#define STM32_LSE_BYPASS DT_PROP(DT_NODELABEL(clk_lse), lse_bypass)
552#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_lse), st_stm32_lse_clock, okay)
553#define STM32_LSE_ENABLED 1
554#define STM32_LSE_FREQ DT_PROP(DT_NODELABEL(clk_lse), clock_frequency)
555#define STM32_LSE_DRIVING DT_PROP(DT_NODELABEL(clk_lse), driving_capability)
556#define STM32_LSE_BYPASS DT_PROP(DT_NODELABEL(clk_lse), lse_bypass)
557#else
558#define STM32_LSE_FREQ 0
559#define STM32_LSE_DRIVING 0
560#define STM32_LSE_BYPASS 0
561#endif
562
563#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msi), st_stm32_msi_clock, okay) || \
564 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msi), st_stm32l0_msi_clock, okay) || \
565 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msi), st_stm32n6_msi_clock, okay)
566#define STM32_MSI_ENABLED 1
567#define STM32_MSI_RANGE DT_PROP(DT_NODELABEL(clk_msi), msi_range)
568#endif
569
570#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msi), st_stm32_msi_clock, okay)
571#define STM32_MSI_PLL_MODE DT_PROP(DT_NODELABEL(clk_msi), msi_pll_mode)
572
573# if defined(CONFIG_SOC_SERIES_STM32L4X) && STM32_MSI_PLL_MODE && !defined(STM32_LSE_ENABLED)
574# error "On STM32L4 series, MSI PLL mode requires LSE to be enabled"
575# endif /* stm32l4 && msi_pll_mode && !STM32_LSE_ENABLED */
576#endif /* st_stm32_msi_clock */
577
578#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msis), st_stm32u5_msi_clock, okay) || \
579 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msis), st_stm32u3_msi_clock, okay)
580#define STM32_MSIS_ENABLED 1
581#define STM32_MSIS_RANGE DT_PROP(DT_NODELABEL(clk_msis), msi_range)
582#define STM32_MSIS_PLL_MODE DT_PROP(DT_NODELABEL(clk_msis), msi_pll_mode)
583#else
584#define STM32_MSIS_RANGE 0
585#define STM32_MSIS_PLL_MODE 0
586#endif
587
588#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msik), st_stm32u5_msi_clock, okay) || \
589 DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_msik), st_stm32u3_msi_clock, okay)
590#define STM32_MSIK_ENABLED 1
591#define STM32_MSIK_RANGE DT_PROP(DT_NODELABEL(clk_msik), msi_range)
592#define STM32_MSIK_PLL_MODE DT_PROP(DT_NODELABEL(clk_msik), msi_pll_mode)
593#else
594#define STM32_MSIK_RANGE 0
595#define STM32_MSIK_PLL_MODE 0
596#endif
597
598#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_csi), fixed_clock, okay)
599#define STM32_CSI_ENABLED 1
600#define STM32_CSI_FREQ DT_PROP(DT_NODELABEL(clk_csi), clock_frequency)
601#else
602#define STM32_CSI_FREQ 0
603#endif
604
605#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_lsi), fixed_clock, okay)
606#define STM32_LSI_ENABLED 1
607#define STM32_LSI_FREQ DT_PROP(DT_NODELABEL(clk_lsi), clock_frequency)
608#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_lsi1), fixed_clock, okay)
609#define STM32_LSI_ENABLED 1
610#define STM32_LSI_FREQ DT_PROP(DT_NODELABEL(clk_lsi1), clock_frequency)
611#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_lsi2), fixed_clock, okay)
612#define STM32_LSI_ENABLED 1
613#define STM32_LSI_FREQ DT_PROP(DT_NODELABEL(clk_lsi2), clock_frequency)
614#else
615#define STM32_LSI_FREQ 0
616#endif
617
618#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), fixed_clock, okay)
619#define STM32_HSI_DIV_ENABLED 0
620#define STM32_HSI_ENABLED 1
621#define STM32_HSI_FREQ DT_PROP(DT_NODELABEL(clk_hsi), clock_frequency)
622#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32h7_hsi_clock, okay) \
623 || DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32l0_hsi_clock, okay) \
624 || DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32g0_hsi_clock, okay) \
625 || DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32c0_hsi_clock, okay) \
626 || DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32n6_hsi_clock, okay)
627#define STM32_HSI_DIV_ENABLED 1
628#define STM32_HSI_ENABLED 1
629#define STM32_HSI_DIVISOR DT_PROP(DT_NODELABEL(clk_hsi), hsi_div)
630#define STM32_HSI_FREQ DT_PROP(DT_NODELABEL(clk_hsi), clock_frequency)
631#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsis), fixed_clock, okay)
632#define STM32_HSIS_ENABLED 1
633#define STM32_HSIS_FREQ DT_PROP(DT_NODELABEL(clk_hsis), clock_frequency)
634#else
635#define STM32_HSI_DIVISOR 1
636#define STM32_HSI_FREQ 0
637#endif
638
639#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsidiv3), fixed_clock, okay)
640#define STM32_HSIDIV3_ENABLED 1
641#define STM32_HSIDIV3_FREQ DT_PROP(DT_NODELABEL(clk_hsidiv3), clock_frequency)
642#else
643#define STM32_HSIDIV3_FREQ 0
644#endif
645
646#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsik), st_stm32c5_xsik_clock, okay)
647#define STM32_HSIK_ENABLED 1
648#define STM32_HSIK_DIVIDER DT_STRING_UPPER_TOKEN(DT_NODELABEL(clk_hsik), xsik_div)
649#define STM32_HSIK_FREQ DT_PROP(DT_NODELABEL(clk_hsik), clock_frequency)
650#else
651#define STM32_HSIK_DIVIDER 1
652#define STM32_HSIK_FREQ 0
653#endif
654
655#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hse), fixed_clock, okay)
656#define STM32_HSE_ENABLED 1
657#define STM32_HSE_FREQ DT_PROP(DT_NODELABEL(clk_hse), clock_frequency)
658#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hse), st_stm32_hse_clock, okay)
659#define STM32_HSE_ENABLED 1
660#define STM32_HSE_BYPASS DT_PROP(DT_NODELABEL(clk_hse), hse_bypass)
661#define STM32_HSE_FREQ DT_PROP(DT_NODELABEL(clk_hse), clock_frequency)
662#if DT_PROP(DT_NODELABEL(clk_hse), css_enabled)
663#define STM32_HSE_CSS 1
664#endif /* css_enabled */
665#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hse), st_stm32wl_hse_clock, okay)
666#define STM32_HSE_ENABLED 1
667#define STM32_HSE_TCXO DT_PROP(DT_NODELABEL(clk_hse), hse_tcxo)
668#define STM32_HSE_DIV2 DT_PROP(DT_NODELABEL(clk_hse), hse_div2)
669#define STM32_HSE_FREQ DT_PROP(DT_NODELABEL(clk_hse), clock_frequency)
670#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hse), st_stm32wba_hse_clock, okay)
671#define STM32_HSE_ENABLED 1
672#define STM32_HSE_DIV2 DT_PROP(DT_NODELABEL(clk_hse), hse_div2)
673#define STM32_HSE_FREQ DT_PROP(DT_NODELABEL(clk_hse), clock_frequency)
674#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hse), st_stm32n6_hse_clock, okay)
675#define STM32_HSE_ENABLED 1
676#define STM32_HSE_BYPASS DT_PROP(DT_NODELABEL(clk_hse), hse_bypass)
677#define STM32_HSE_DIV2 DT_PROP(DT_NODELABEL(clk_hse), hse_div2)
678#define STM32_HSE_FREQ DT_PROP(DT_NODELABEL(clk_hse), clock_frequency)
679#else
680#define STM32_HSE_FREQ 0
681#endif
682
683#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi48), fixed_clock, okay)
684#define STM32_HSI48_ENABLED 1
685#define STM32_HSI48_FREQ DT_PROP(DT_NODELABEL(clk_hsi48), clock_frequency)
686#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi48), st_stm32_hsi48_clock, okay)
687#define STM32_HSI48_ENABLED 1
688#define STM32_HSI48_FREQ DT_PROP(DT_NODELABEL(clk_hsi48), clock_frequency)
689#define STM32_HSI48_CRS_USB_SOF DT_PROP(DT_NODELABEL(clk_hsi48), crs_usb_sof)
690#endif
691
692#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_psis), fixed_clock, okay)
693#define STM32_PSIS_ENABLED 1
694#define STM32_PSIS_FREQ DT_PROP(DT_NODELABEL(clk_psis), clock_frequency)
695#else
696#define STM32_PSIS_FREQ 0
697#endif
698
699#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_psidiv3), fixed_clock, okay)
700#define STM32_PSIDIV3_ENABLED 1
701#define STM32_PSIDIV3_FREQ DT_PROP(DT_NODELABEL(clk_psidiv3), clock_frequency)
702#else
703#define STM32_PSIDIV3_FREQ 0
704#endif
705
706#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_psik), st_stm32c5_xsik_clock, okay)
707#define STM32_PSIK_ENABLED 1
708#define STM32_PSIK_DIVIDER DT_STRING_UPPER_TOKEN(DT_NODELABEL(clk_psik), xsik_div)
709#define STM32_PSIK_FREQ DT_PROP(DT_NODELABEL(clk_psik), clock_frequency)
710#else
711#define STM32_PSIK_DIVIDER 1
712#define STM32_PSIK_FREQ 0
713#endif
714
715#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(perck), st_stm32_clock_mux, okay)
716#define STM32_CKPER_ENABLED 1
717#endif
718
719#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(cpusw), st_stm32_clock_mux, okay)
720#define STM32_CPUSW_ENABLED 1
721#endif
722
723#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic1), st_stm32n6_ic_clock_mux, okay)
724#define STM32_IC1_ENABLED 1
725#define STM32_IC1_PLL_SRC DT_PROP(DT_NODELABEL(ic1), pll_src)
726#define STM32_IC1_DIV DT_PROP(DT_NODELABEL(ic1), ic_div)
727#endif
728
729#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic2), st_stm32n6_ic_clock_mux, okay)
730#define STM32_IC2_ENABLED 1
731#define STM32_IC2_PLL_SRC DT_PROP(DT_NODELABEL(ic2), pll_src)
732#define STM32_IC2_DIV DT_PROP(DT_NODELABEL(ic2), ic_div)
733#endif
734
735#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic3), st_stm32n6_ic_clock_mux, okay)
736#define STM32_IC3_ENABLED 1
737#define STM32_IC3_PLL_SRC DT_PROP(DT_NODELABEL(ic3), pll_src)
738#define STM32_IC3_DIV DT_PROP(DT_NODELABEL(ic3), ic_div)
739#endif
740
741#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic4), st_stm32n6_ic_clock_mux, okay)
742#define STM32_IC4_ENABLED 1
743#define STM32_IC4_PLL_SRC DT_PROP(DT_NODELABEL(ic4), pll_src)
744#define STM32_IC4_DIV DT_PROP(DT_NODELABEL(ic4), ic_div)
745#endif
746
747#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic5), st_stm32n6_ic_clock_mux, okay)
748#define STM32_IC5_ENABLED 1
749#define STM32_IC5_PLL_SRC DT_PROP(DT_NODELABEL(ic5), pll_src)
750#define STM32_IC5_DIV DT_PROP(DT_NODELABEL(ic5), ic_div)
751#endif
752
753#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic6), st_stm32n6_ic_clock_mux, okay)
754#define STM32_IC6_ENABLED 1
755#define STM32_IC6_PLL_SRC DT_PROP(DT_NODELABEL(ic6), pll_src)
756#define STM32_IC6_DIV DT_PROP(DT_NODELABEL(ic6), ic_div)
757#endif
758
759#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic7), st_stm32n6_ic_clock_mux, okay)
760#define STM32_IC7_ENABLED 1
761#define STM32_IC7_PLL_SRC DT_PROP(DT_NODELABEL(ic7), pll_src)
762#define STM32_IC7_DIV DT_PROP(DT_NODELABEL(ic7), ic_div)
763#endif
764
765#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic8), st_stm32n6_ic_clock_mux, okay)
766#define STM32_IC8_ENABLED 1
767#define STM32_IC8_PLL_SRC DT_PROP(DT_NODELABEL(ic8), pll_src)
768#define STM32_IC8_DIV DT_PROP(DT_NODELABEL(ic8), ic_div)
769#endif
770
771#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic9), st_stm32n6_ic_clock_mux, okay)
772#define STM32_IC9_ENABLED 1
773#define STM32_IC9_PLL_SRC DT_PROP(DT_NODELABEL(ic9), pll_src)
774#define STM32_IC9_DIV DT_PROP(DT_NODELABEL(ic9), ic_div)
775#endif
776
777#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic10), st_stm32n6_ic_clock_mux, okay)
778#define STM32_IC10_ENABLED 1
779#define STM32_IC10_PLL_SRC DT_PROP(DT_NODELABEL(ic10), pll_src)
780#define STM32_IC10_DIV DT_PROP(DT_NODELABEL(ic10), ic_div)
781#endif
782
783#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic11), st_stm32n6_ic_clock_mux, okay)
784#define STM32_IC11_ENABLED 1
785#define STM32_IC11_PLL_SRC DT_PROP(DT_NODELABEL(ic11), pll_src)
786#define STM32_IC11_DIV DT_PROP(DT_NODELABEL(ic11), ic_div)
787#endif
788
789#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic12), st_stm32n6_ic_clock_mux, okay)
790#define STM32_IC12_ENABLED 1
791#define STM32_IC12_PLL_SRC DT_PROP(DT_NODELABEL(ic12), pll_src)
792#define STM32_IC12_DIV DT_PROP(DT_NODELABEL(ic12), ic_div)
793#endif
794
795#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic13), st_stm32n6_ic_clock_mux, okay)
796#define STM32_IC13_ENABLED 1
797#define STM32_IC13_PLL_SRC DT_PROP(DT_NODELABEL(ic13), pll_src)
798#define STM32_IC13_DIV DT_PROP(DT_NODELABEL(ic13), ic_div)
799#endif
800
801#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic14), st_stm32n6_ic_clock_mux, okay)
802#define STM32_IC14_ENABLED 1
803#define STM32_IC14_PLL_SRC DT_PROP(DT_NODELABEL(ic14), pll_src)
804#define STM32_IC14_DIV DT_PROP(DT_NODELABEL(ic14), ic_div)
805#endif
806
807#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic15), st_stm32n6_ic_clock_mux, okay)
808#define STM32_IC15_ENABLED 1
809#define STM32_IC15_PLL_SRC DT_PROP(DT_NODELABEL(ic15), pll_src)
810#define STM32_IC15_DIV DT_PROP(DT_NODELABEL(ic15), ic_div)
811#endif
812
813#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic16), st_stm32n6_ic_clock_mux, okay)
814#define STM32_IC16_ENABLED 1
815#define STM32_IC16_PLL_SRC DT_PROP(DT_NODELABEL(ic16), pll_src)
816#define STM32_IC16_DIV DT_PROP(DT_NODELABEL(ic16), ic_div)
817#endif
818
819#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic17), st_stm32n6_ic_clock_mux, okay)
820#define STM32_IC17_ENABLED 1
821#define STM32_IC17_PLL_SRC DT_PROP(DT_NODELABEL(ic17), pll_src)
822#define STM32_IC17_DIV DT_PROP(DT_NODELABEL(ic17), ic_div)
823#endif
824
825#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic18), st_stm32n6_ic_clock_mux, okay)
826#define STM32_IC18_ENABLED 1
827#define STM32_IC18_PLL_SRC DT_PROP(DT_NODELABEL(ic18), pll_src)
828#define STM32_IC18_DIV DT_PROP(DT_NODELABEL(ic18), ic_div)
829#endif
830
831#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic19), st_stm32n6_ic_clock_mux, okay)
832#define STM32_IC19_ENABLED 1
833#define STM32_IC19_PLL_SRC DT_PROP(DT_NODELABEL(ic19), pll_src)
834#define STM32_IC19_DIV DT_PROP(DT_NODELABEL(ic19), ic_div)
835#endif
836
837#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(ic20), st_stm32n6_ic_clock_mux, okay)
838#define STM32_IC20_ENABLED 1
839#define STM32_IC20_PLL_SRC DT_PROP(DT_NODELABEL(ic20), pll_src)
840#define STM32_IC20_DIV DT_PROP(DT_NODELABEL(ic20), ic_div)
841#endif
842
844
845struct stm32_pclken {
847 uint32_t div : (32 - STM32_CLOCK_DIV_SHIFT);
848 uint32_t enr;
849};
850
852
853/* Get STM32 clock information for an indexed clock phandle in a DT node */
854#define STM32_CLOCK_INFO(clk_index, node_id) \
855 { \
856 .enr = DT_CLOCKS_CELL_BY_IDX(node_id, clk_index, bits), \
857 .bus = DT_CLOCKS_CELL_BY_IDX(node_id, clk_index, bus) & \
858 GENMASK(STM32_CLOCK_DIV_SHIFT - 1, 0), \
859 .div = DT_CLOCKS_CELL_BY_IDX(node_id, clk_index, bus) >> \
860 STM32_CLOCK_DIV_SHIFT, \
861 }
862
863/* Get an array of STM32 clocks information for clocks listed in a DT node */
864#define STM32_DT_CLOCKS(node_id) \
865 { \
866 LISTIFY(DT_NUM_CLOCKS(node_id), \
867 STM32_CLOCK_INFO, (,), node_id) \
868 }
869
870/* Get an array of STM32 clocks information for clocks listed in a DT_DRV_COMPAT instance node */
871#define STM32_DT_INST_CLOCKS(inst) \
872 STM32_DT_CLOCKS(DT_DRV_INST(inst))
873
874/* Get STM32 clock information for an indexed clock phandle in a DT_DRV_COMPAT instance node */
875#define STM32_DT_INST_CLOCK_INFO_BY_IDX(clk_index, inst) \
876 STM32_CLOCK_INFO(clk_index, DT_DRV_INST(inst))
877
878/* Get STM32 clock information for clock index 0 in a DT_DRV_COMPAT instance node */
879#define STM32_DT_INST_CLOCK_INFO(inst) \
880 STM32_DT_INST_CLOCK_INFO_BY_IDX(0, inst)
881
882/* Get STM32 clock information for a named clock phandle in DT node */
883#define STM32_CLOCK_INFO_BY_NAME(node_id, name) \
884 { \
885 .enr = DT_CLOCKS_CELL_BY_NAME(node_id, name, bits), \
886 .bus = DT_CLOCKS_CELL_BY_NAME(node_id, name, bus) & \
887 GENMASK(STM32_CLOCK_DIV_SHIFT - 1, 0), \
888 .div = DT_CLOCKS_CELL_BY_NAME(node_id, name, bus) >> \
889 STM32_CLOCK_DIV_SHIFT, \
890 }
891
892/* Get STM32 clock information for named clock phandle in a DT_DRV_COMPAT instance node */
893#define STM32_DT_INST_CLOCK_INFO_BY_NAME(inst, name) \
894 STM32_CLOCK_INFO_BY_NAME(DT_DRV_INST(inst), name)
895
896/* Return true only if at least an enabled instance of the DT_DRV_COMPAT has at least 2 clocks */
897#define STM32_DOMAIN_CLOCK_INST_SUPPORT(inst) DT_INST_CLOCKS_HAS_IDX(inst, 1) ||
898#define STM32_DT_INST_DEV_DOMAIN_CLOCK_SUPPORT \
899 (DT_INST_FOREACH_STATUS_OKAY(STM32_DOMAIN_CLOCK_INST_SUPPORT) 0)
900
902
908#define STM32_DT_CLKSEL_REG_GET(clock) \
909 (((clock) >> STM32_DT_CLKSEL_REG_SHIFT) & STM32_DT_CLKSEL_REG_MASK)
910
916#define STM32_DT_CLKSEL_SHIFT_GET(clock) \
917 (((clock) >> STM32_DT_CLKSEL_SHIFT_SHIFT) & STM32_DT_CLKSEL_SHIFT_MASK)
918
924#define STM32_DT_CLKSEL_MASK_GET(clock) \
925 BIT_MASK((((clock) >> STM32_DT_CLKSEL_WIDTH_SHIFT) & STM32_DT_CLKSEL_WIDTH_MASK) + 1)
926
932#define STM32_DT_CLKSEL_VAL_GET(clock) \
933 (((clock) >> STM32_DT_CLKSEL_VAL_SHIFT) & STM32_DT_CLKSEL_VAL_MASK)
934
935#if defined(STM32_HSE_CSS)
944void stm32_hse_css_callback(void);
945#endif /* STM32_HSE_CSS */
946
947#ifdef CONFIG_SOC_SERIES_STM32WB0X
952typedef void (*lsi_update_cb_t)(uint32_t new_lsi_frequency);
953
965int stm32wb0_register_lsi_update_callback(lsi_update_cb_t cb);
966#endif /* CONFIG_SOC_SERIES_STM32WB0X */
967
969#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_STM32_CLOCK_CONTROL_H_ */
Main header file for clock control driver API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
#define STM32_CLOCK_DIV_SHIFT
Definition stm32_clock.h:27
DT bindings for STM32C5 clock system.