cancel
Showing results for 
Search instead for 
Did you mean: 

Read system clock in LL driver

IDavo.1
Associate II

Hi Everyone,

I'm working with LL driver and want to read the system clock. There is this function:

LL_RCC_GetSystemClockFreq(PCLK1_Frequency)

to get the frequencies but although I include stm32f1xx_ll_rcc.h, I receive this Error

'PCLK1_Frequency' undeclared (first use in this function) .

Could you please help me. It's making me crazy ;)

9 REPLIES 9
Pavel A.
Evangelist III

> LL_RCC_GetSystemClockFreq(PCLK1_Frequency)

Where this line come from? Was it generated by the Cube/CubeIDE?

-- pa

IDavo.1
Associate II

I'm using STM32CubeIDE however this is a standard function on LL driver found in HAL and LL driver description by ST.

Pavel A.
Evangelist III

STM32F1 does not have LL_RCC_GetSystemClockFreq. Rather, it has LL_RCC_GetSystemClocksFreq.

Here. It's parameter is a pointer to 4 frequencies.

-- pa

Jack Peacock_2
Senior III

The RCC has no way to actually determine the frequency of the PCLK bus clocks if you are using the HSE oscillator. CSMIS historically uses a hard-coded HSE frequency to base calculations, with no guarantee it matches the crystal. Internal RC oscillator frequencies can be determined by RCC settings, though I'm not sure how well LL does this. If the base oscillator used for the PLL or HCLK system clock can be determined then all other clocks can be derived through RCC registers.

Check the LL source code to see what it expects for the call parameter. Your error implies the parameter isn't what you think it is. I don;t use LL so I'm not sure how well it parses the RCC setting to derive the clock tree. However, you can fined any bus frequency if you know the actual HSE crystal by directly reading the RCC registers.

Jack Peacock

Yes you are right but still same problem with this

a = LL_RCC_GetSystemClocksFreq(PCLK1_Frequency);

IDavo.1
Associate II

Thank you guys,

Actually there was no success with this function:

LL_RCC_GetSystemClocksFreq(PCLK1_Frequency)

I don't know if it's a bug by LL or I'm using it wrong. Anyway, digging through it directed me to another function (I guess like Jack said it's a CMSIS function) and enabled me to read the clock and it was:

RCC_GetSystemClockFreq()

Which returns me the SYSCLK. Although it asks me to define it as a prototype first by a Warning and I don't know WHY (because it has been defined once in header) but I'm happy now :smiling_face_with_smiling_eyes: .

Piranha
Chief II

> although I include stm32f1xx_ll_rcc.h, I receive this Error

> I don't know if it's a bug by LL or I'm using it wrong.

In both cases you ha NOT included the respective header file.

https://www.tutorialspoint.com/cprogramming/c_header_files.htm

What do you mean by respective. I included "stm32f1xx_ll_rcc.h" which is the respective header file.

Piranha
Chief II

https://dictionary.cambridge.org/dictionary/english/respective

Looked once more at this... OK, let's rewind it back. The compiler already tells you the problem - the PCLK1_Frequency is not defined. The LL_RCC_GetSystemClocksFreq() function takes a single parameter, which must be a pointer to specific structure. You have to provide that structure and pass the pointer to it into that function.