2023-05-17 08:15 AM
When changing the HSE clock divider to 2 in STM32cubeMX the code:
/** Enable the HSE Prescaler
*/
__HAL_RCC_HSE_DIV2_ENABLE();
Is generated after the HAL_RCC_ClockConfig is called. causing the clock divider on the HSE not to be taken into account when calculation the peripheral clock dividers/periods.
2023-05-18 01:20 AM - edited 2023-11-20 05:12 AM
Hello @NickAssink
First let me thank you for posting.
After double check the issue mentioned above , I would like to share with you my results please have a look.
After generating the code (without changing the location of the generated call of function " __HAL_RCC_HSE_DIV2_ENABLE();" ) and debug it
and based on the RM0473 (8.4.1 RCC clock control register (RCC_CR )
The bit HSEPRE=1 as shown in the screenshot that means that the clock divider on the HSE is taken into account when calculation the peripheral clock dividers/periods.
I will be waiting for your feedback .
Thx
Ghofrane
2023-05-22 12:32 AM - edited 2023-11-20 05:12 AM
Hello Ghofrane,
Thanks for the fast response. There was a national holiday in the Netherlands so I could not respond immediately. but I should have given a more in depth explanation.
The HAL_RCC_ClockConfig uses the HSE clock divider to calculate the configuration of the SysTick timer. But as shown in the image below the HAL_RCC_ClockConfig function is called before the clock divider is set.
this will cause the SysTick timer to be set without the correct clock config.
another way to see this is:
So if __HAL_RCC_HSE_DIV2_ENABLE is called after HAL_RCC_ClockConfig the div 2 config will not be used in HAL_RCC_ClockConfig. The HAL_RCC_ClockConfig uses HAL_RCC_GetHCLKFreq to set the SystemCoreClock so if the clock divider is changed after the fact, the SystemCoreClock is not set correctly. and that is the same for the SysTick timer set in HAL_RCC_ClockConfig.
With kind regards,
Nick Assink
2023-05-22 07:41 AM
Hello @NickAssink
Thank you for your contributions and for your detailed explanations,
I confirm the issue on my side, it has been reported to STM32CubeMX development team .
Internal ticket number: 152728(This is an internal tracking number and is not accessible or usable by customers).
I will keep you posted with updates.
Ghofrane