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 1 commit
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

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, nice catch.

#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