cancel
Showing results for 
Search instead for 
Did you mean: 

How to get HCLK for LL_Init1msTick?

PGroe.2
Associate III

Hi

I noticed on my STM32G071.. that the "LL_mDelay(1000)" function did not produce a steady 1000ms delay if I vary the HCLK frequency (code generated by CubeIDE)...

I did not have this problem with other MCUs code generated, it worked out of the box (F103/F407).

Then I stumbled upon the "LL_Init1msTick(uint32_t HCLKFrequency)" function which seemed to have solved my problem.

But what is the proper (dynamic) way to get the HCLK frequency for the function?

I currently use this in my main.c:

  /* USER CODE BEGIN SysInit */
  LL_Init1msTick(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  /* USER CODE END SysInit */

This seems to pass a valid HCLK to the function. But CubeIDE tells me a warning that:

../Core/Src/main.c: In function 'main':
../Core/Src/main.c:85:18: warning: implicit declaration of function 'RCC_GetHCLKClockFreq'; did you mean 'LL_RCC_GetCECClockFreq'? [-Wimplicit-function-declaration]
   LL_Init1msTick(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
                  ^~~~~~~~~~~~~~~~~~~~
                  LL_RCC_GetCECClockFreq
../Core/Src/main.c:85:39: warning: implicit declaration of function 'RCC_GetSystemClockFreq'; did you mean 'LL_RCC_GetSystemClocksFreq'? [-Wimplicit-function-declaration]
   LL_Init1msTick(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
                                       ^~~~~~~~~~~~~~~~~~~~~~
                                       LL_RCC_GetSystemClocksFreq

0693W000005AevWQAS.pngWhats the problem here?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

The proper LL way is to call LL_RCC_GetSystemClocksFreq and use the HCLK value it returns. RCC_GetHCLKClockFreq is a private function, for whatever reason.

You could also just put the function declaration for RCC_GetHCLKClockFreq in your header and use it directly, but using a private function is probably not the proper way.

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

View solution in original post

3 REPLIES 3
TDK
Guru

The proper LL way is to call LL_RCC_GetSystemClocksFreq and use the HCLK value it returns. RCC_GetHCLKClockFreq is a private function, for whatever reason.

You could also just put the function declaration for RCC_GetHCLKClockFreq in your header and use it directly, but using a private function is probably not the proper way.

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

Thanks, already figured it out :)

 LL_RCC_ClocksTypeDef RCC_CLOCKS;
 LL_RCC_GetSystemClocksFreq(&RCC_CLOCKS);
 LL_Init1msTick(RCC_CLOCKS.HCLK_Frequency);

Piranha
Chief II

https://github.com/STMicroelectronics/STM32CubeG0/blob/5114d9a57d8a450082fc8cafe4fe34d3610d0cef/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_rcc.c#L89

A "private" functions, which are not private - not declared as static... There wouldn't be this misunderstanding if those "private" functions would actually be private. The HAL team's incompetence level is top notch!