Skip to content

STM32L0: fix PLL input frequency division by HSI clock divider #92546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drivers/clock_control/clock_stm32_ll_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ static int stm32_clock_control_get_subsys_rate(const struct device *clock,
#endif
#if defined(STM32_SRC_HSI)
case STM32_SRC_HSI:
#if defined(CONFIG_SOC_SERIES_STM32L0X)
*rate = STM32_HSI_FREQ / STM32_HSI_DIVISOR;
#else
*rate = STM32_HSI_FREQ;
#endif
break;
#endif
#if defined(STM32_SRC_MSI)
Expand Down Expand Up @@ -662,7 +666,13 @@ static void set_up_fixed_clock_sources(void)
}
}
#if STM32_HSI_DIV_ENABLED
#if defined(CONFIG_SOC_SERIES_STM32L0X)
if (STM32_HSI_DIVISOR == 4) {
LL_RCC_HSI_EnableDivider();
}
Comment on lines +670 to +672
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disable function should also be called in an else. I think it is necessary if for example an MCUBoot enables the divider, but the application wants it disabled

#else
LL_RCC_SetHSIDiv(hsi_divider(STM32_HSI_DIVISOR));
#endif
#endif
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/clock_control/clock_stm32l0_l1.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ __unused
uint32_t get_pllsrc_frequency(void)
{
if (IS_ENABLED(STM32_PLL_SRC_HSI)) {
#if defined(CONFIG_SOC_SERIES_STM32L0X)
return STM32_HSI_FREQ / STM32_HSI_DIVISOR;
#else
return STM32_HSI_FREQ;
#endif
} else if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
return STM32_HSE_FREQ;
}
Expand Down
3 changes: 2 additions & 1 deletion dts/arm/st/l0/stm32l0.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@

clk_hsi: clk-hsi {
#clock-cells = <0>;
compatible = "fixed-clock";
compatible = "st,stm32l0-hsi-clock";
clock-frequency = <DT_FREQ_M(16)>;
hsi-div = <1>;
status = "disabled";
};

Expand Down
18 changes: 18 additions & 0 deletions dts/bindings/clock/st,stm32l0-hsi-clock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2025 STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

description: STM32L0 HSI Clock

compatible: "st,stm32l0-hsi-clock"

include: [fixed-clock.yaml]

properties:
hsi-div:
type: int
required: true
description: |
HSI clock divider. Configures the output HSI clock frequency
enum:
- 1 # hsi_clk = 16MHz
- 4 # hsi_clk = 4MHz
1 change: 1 addition & 0 deletions include/zephyr/drivers/clock_control/stm32_clock_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@
#define STM32_HSI_ENABLED 1
#define STM32_HSI_FREQ DT_PROP(DT_NODELABEL(clk_hsi), clock_frequency)
#elif DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32h7_hsi_clock, okay) \
|| DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32l0_hsi_clock, okay) \
|| DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32g0_hsi_clock, okay) \
|| DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32c0_hsi_clock, okay) \
|| DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(clk_hsi), st_stm32n6_hsi_clock, okay)
Expand Down