cancel
Showing results for 
Search instead for 
Did you mean: 

How to read clock frequencies from code? Even a #define for the hardcoded startup values would be useful.

FColl.1
Associate III

CubeMX allows one to enter clock frequencies and have all the registers to be set back calculated. Great! This saves much fiddling. However... is there anyway for the code to determine, for example, what the frequency if a clock going to the ADC is without doing all those calculations that CubeMX saved us from?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

There are functions like HAL_RCC_GetPCLK1Freq that you can call to calculate them. There are no hardcoded #defined values.

Per CMSIS standard, the SystemCoreClock variable reflects the current system core clock frequency and is updated when the clock changes.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

There are functions like HAL_RCC_GetPCLK1Freq that you can call to calculate them. There are no hardcoded #defined values.

Per CMSIS standard, the SystemCoreClock variable reflects the current system core clock frequency and is updated when the clock changes.

If you feel a post has answered your question, please click "Accept as Solution".
FColl.1
Associate III

Thanks! I found   HAL_RCCEx_GetPLL2ClockFreq(); Which gives me the ADC input freq. Very useful.

Do you know of a function that will calculate ADC sample rate? It would need to wrap up, conversion time, oversampling , hold time, prescaler etc.

There isn’t a function that does that. It would be difficult given all the different ways to set up the ADC.
If you feel a post has answered your question, please click "Accept as Solution".