2020-11-02 01:22 PM
Hi,
I want to know the configured core clock frequency at compile time, but unfortunately this value is not defined anywhere.
Thus I propose that the code generator should create a list of #defines for every node in the clock tree. I think SYSCLK, HCLK, APB1 and APB2 would suffice in most cases, but might as well #define all nodes.
Kind regards,
2020-11-02 04:43 PM
> I want to know the configured core clock frequency at compile time, but unfortunately this value is not defined anywhere.
The SystemCoreClock variable holds the current speed. Pretty sure CMSIS requires this. This is updated when the clock changes (in SystemCoreClockUpdate or HAL_RCC_GetSysClockFreq) if you're using HAL functions.
> Thus I propose that the code generator should create a list of #defines for every node in the clock tree. I think SYSCLK, HCLK, APB1 and APB2 would suffice in most cases, but might as well #define all nodes.
I don't think additional #defines need to be defined. Definitions get stale and inhibit debugging efforts. If you want to find out those values, inspect the registers, as is done with various HAL clock functions. Plus, they core boots up in one speed and is then typically modified one or or more times in the program. I don't love HAL, but using HAL_RCC_GetSysClockFreq and similar to return the actual clock speed as given by registers rather than some compiler constant is useful (subject to the limitations of HSE_VALUE).
2020-11-04 02:59 PM
The developer of course should know when to use #defined values and when to query the actual value from the system.
Often the clock tree is changed at startup and never touched again.
Knowing this you can use compile time switches depending on what the clock frequencies are (or will be after startup), but this requires the mentioned #defines.