Skip to content

Commit 14e7d78

Browse files
committed
F4_HAL/rcc: Adjust computation of SYSCLK to retain precision.
1 parent c2faff2 commit 14e7d78

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,12 @@ __weak uint32_t HAL_RCC_GetSysClockFreq(void)
891891
if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI)
892892
{
893893
/* HSE used as PLL clock source */
894-
pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
894+
//pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
895+
// dpgeorge: Adjust the way the arithmetic is done so it retains
896+
// precision for the case that pllm doesn't evenly divide HSE_VALUE.
897+
// Must be sure not to overflow, so divide by 4 first. HSE_VALUE
898+
// should be a multiple of 4 (being a multiple of 100 is enough).
899+
pllvco = ((HSE_VALUE / 4) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN))) / pllm * 4;
895900
}
896901
else
897902
{

0 commit comments

Comments
 (0)