2022-11-04 05:11 AM
The HAL Timebase Generation using another Timer as SYSTICK is buggy when clocks APBxCLKDivider is switched in runtime. The Timebase is then re-initialized without respect to an (re-) configured APBxClockDivider. The condition if a APBxCLKDivier is set is only evaluated at CubeMx-Code-Generation-Time. Instead of fixing this issue during code generation time (which then does not allow switching APBxClockDivider in runtime) this should be done by those Code-Lines during runtime as the clkconfig struct is already available in the code.:
/* Compute TIMx clock */
if(clkconfig.APBxCLKDivider) {
uwTimclock = 2*HAL_RCC_GetPCLKxFreq();
} else {
uwTimclock = HAL_RCC_GetPCLKxFreq();
}
This would work in any case without having a conditional code-generation dependent on the APBxCLKDivider.
Regards Pascal