2
\$\begingroup\$

When configuring a STM32 (or at least my STM32F722ZE based nucleo board), there are 2 clock frequencies, one for APB1, the other for APB2. The annoying thing is that some timers use APB1, other use APB2. So each time I want to configure a PWM (or other timer based application), I have to first check which timer is connected on which APB.

It would be easiest to just set the same frequency for both (so ne need anymore to look up what is connected to which APB).

This could easily be done in STMCubeIDE : enter image description here

I can just replace the APB2 prescaler by "/4", and have all timers running at 108MHz (I have no need for a timer at 216 MHz).

Is there any downside to it?

Anything that would no longer work as expected?

(nb : I'm starting from a new project, so there is no code I wrote to mess up, but I have no idea about time keeping, UART, ...)

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Yeah that's fine if you want to run APB1 and APB2 at the same speed. Many applications need two clocks so that is why they give you the option. You may already know this, but the cubeMX tool will also generate code for the HAL to configure all timers and clocks for you through the hardware abstraction layer (HAL) libraries.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. Yes, I was using the CubeMX part of STMCubeIDE. And I use it to configure the timers and clocks. Still, I cannot (at least as far as I know) just tell that I want a timer running at 10kHz : I have to check the clock source for that timer, and then compute prescaler and counter-period. Nothing too complicated, but I still need the frequency of the clock source to do the maths \$\endgroup\$
    – Sandro
    Jan 31, 2022 at 20:11
  • \$\begingroup\$ @Sandro CubeMX is an example generator at best. If you want flexibility, I recommend rolling your own Timer class. You can get peripheral clock using HAL_RCC_GetPCLK1Freq() and HAL_RCC_GetPCLK2Freq() \$\endgroup\$
    – Armandas
    Jan 31, 2022 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.