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