Skip to content

Commit 76e53d2

Browse files
committed
F7_HAL/rcc: Adjust computation of SYSCLK to retain precision.
1 parent 14e7d78 commit 76e53d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,12 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
917917
if (__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLCFGR_PLLSRC_HSI)
918918
{
919919
/* HSE used as PLL clock source */
920-
pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
920+
//pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
921+
// dpgeorge: Adjust the way the arithmetic is done so it retains
922+
// precision for the case that pllm doesn't evenly divide HSE_VALUE.
923+
// Must be sure not to overflow, so divide by 4 first. HSE_VALUE
924+
// should be a multiple of 4 (being a multiple of 100 is enough).
925+
pllvco = ((HSE_VALUE / 4) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN))) / pllm * 4;
921926
}
922927
else
923928
{

0 commit comments

Comments
 (0)