Skip to main content
FColl.1
Associate III
October 29, 2021
Solved

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

  • October 29, 2021
  • 3 replies
  • 914 views

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?

This topic has been closed for replies.
Best answer by TDK

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.

3 replies

TDK
TDKBest answer
October 29, 2021

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
FColl.1Author
Associate III
October 31, 2021

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.

TDK
October 31, 2021
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""."