Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit c568a2b

Browse files
committed
stmhal: Adjust computation of SYSCLK to retain precision.
1 parent 1f2558d commit c568a2b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stmhal/hal/src/stm32f4xx_hal_rcc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,12 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
972972
if (__RCC_PLLSRC() != 0)
973973
{
974974
/* HSE used as PLL clock source */
975-
pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
975+
//pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
976+
// dpgeorge: Adjust the way the arithmetic is done so it retains
977+
// precision for the case that pllm doesn't evenly divide HSE_VALUE.
978+
// Must be sure not to overflow, so divide by 4 first. HSE_VALUE
979+
// should be a multiple of 4 (being a multiple of 100 is enough).
980+
pllvco = ((HSE_VALUE / 4) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN))) / pllm * 4;
976981
}
977982
else
978983
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy