Skip to content

Commit 48ba84b

Browse files
gautierg-stnashif
authored andcommitted
drivers: clock: stm32 common: update ahb prescaler
STM32C0 have a different prescaler for SYSCLK and for HCLK. Updates the clock driver to use the appropriate prescaler for each series. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent d61a984 commit 48ba84b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/clock_control/clock_stm32_ll_common.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424
#define z_hsi_divider(v) LL_RCC_HSI_DIV_ ## v
2525
#define hsi_divider(v) z_hsi_divider(v)
2626

27+
#if defined(LL_RCC_HCLK_DIV_1)
28+
#define fn_ahb_prescaler(v) LL_RCC_HCLK_DIV_ ## v
29+
#define ahb_prescaler(v) fn_ahb_prescaler(v)
30+
#else
2731
#define fn_ahb_prescaler(v) LL_RCC_SYSCLK_DIV_ ## v
2832
#define ahb_prescaler(v) fn_ahb_prescaler(v)
33+
#endif
2934

3035
#define fn_apb1_prescaler(v) LL_RCC_APB1_DIV_ ## v
3136
#define apb1_prescaler(v) fn_apb1_prescaler(v)
@@ -537,7 +542,7 @@ static void set_up_plls(void)
537542
*/
538543
if (LL_RCC_GetSysClkSource() == LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {
539544
stm32_clock_switch_to_hsi();
540-
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
545+
LL_RCC_SetAHBPrescaler(ahb_prescaler(1));
541546
}
542547
LL_RCC_PLL_Disable();
543548

@@ -800,9 +805,9 @@ int stm32_clock_control_init(const struct device *dev)
800805
set_up_plls();
801806

802807
if (DT_PROP(DT_NODELABEL(rcc), undershoot_prevention) &&
803-
(STM32_CORE_PRESCALER == LL_RCC_SYSCLK_DIV_1) &&
808+
(ahb_prescaler(STM32_CORE_PRESCALER) == ahb_prescaler(1)) &&
804809
(MHZ(80) < CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC)) {
805-
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);
810+
LL_RCC_SetAHBPrescaler(ahb_prescaler(2));
806811
} else {
807812
LL_RCC_SetAHBPrescaler(ahb_prescaler(STM32_CORE_PRESCALER));
808813
}
@@ -827,7 +832,7 @@ int stm32_clock_control_init(const struct device *dev)
827832
#endif /* STM32_SYSCLK_SRC_... */
828833

829834
if (DT_PROP(DT_NODELABEL(rcc), undershoot_prevention) &&
830-
(STM32_CORE_PRESCALER == LL_RCC_SYSCLK_DIV_1) &&
835+
(ahb_prescaler(STM32_CORE_PRESCALER) == ahb_prescaler(1)) &&
831836
(MHZ(80) < CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC)) {
832837
LL_RCC_SetAHBPrescaler(ahb_prescaler(STM32_CORE_PRESCALER));
833838
}

0 commit comments

Comments
 (0)