SystemCoreClock variable is updated in two ways only
Dear Developer in Drivers/CMSIS/Device/ST/Source/Templates/system_stm32l4xx.c stands:
The SystemCoreClock variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
But HAL_RCC_GetHCLKFreq() does not update SystemCoreClock
Either fix the doc or the code
BTW: HAL_RCC_GetSysClockFreq() and SystemCoreClockUpdate() are very similar Can they merged together?
In HAL_RCC_GetSysClockFreq() are RCC_xxx_Pos used. In SystemCoreClockUpdate() are numerical Values used. Please use in both case RCC_xxx_Pos.
ST Internal Reference: 199230
BTW. This Problem is also in all other families
Hello @CanastraRF,
You have raised three points in this issue, and below are the details:
1. Documentation and Code Discrepancy
Dear Developer in Drivers/CMSIS/Device/ST/Source/Templates/system_stm32l4xx.c stands:
The SystemCoreClock variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
But HAL_RCC_GetHCLKFreq() does not update SystemCoreClock
Either fix the doc or the code
We appreciate your observation and have submitted an internal bug tracker to our development team to address this issue. It will be fixed as soon as possible. Additionally, this fix will be cloned across all impacted series to ensure consistency.
2. Merging HAL_RCC_GetSysClockFreq() and SystemCoreClockUpdate()
Regarding your suggestion to merge HAL_RCC_GetSysClockFreq() and SystemCoreClockUpdate(), we respectfully disagree. Although these functions are related, they serve distinct purposes:
-
HAL_RCC_GetSysClockFreq(): This API is part of the HAL library and is used to get the current system clock frequency.
-
SystemCoreClockUpdate(): This API is part of the CMSIS library and is used to update the
SystemCoreClockvariable.
While both functions deal with the system clock frequency, they should remain separate to maintain clear and efficient code.
3. Use of RCC_xxx_Pos Constants
You also pointed out that HAL_RCC_GetSysClockFreq() uses RCC_xxx_Pos constants, whereas SystemCoreClockUpdate() uses numerical values. We agree that using RCC_xxx_Pos constants in both functions would enhance code readability. However, we currently do not accept this kind of enhancement as it does not affect the functionality of the code.
Thank you for your valuable feedback. Best regards,