Author Topic: General question on clock tree (STM32)  (Read 1689 times)

0 Members and 1 Guest are viewing this topic.

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
General question on clock tree (STM32)
« on: September 24, 2018, 03:28:35 pm »
I've attached a fragment of the Nucleo L432 clock tree. At first insight I thought that Timer 2 (connected to APB2) were clocked at "APB2 Timer Clocks" frequency. But then I realized that I was wrong, and that timers peripheral are clocked at "APBx Peripheral Clocks" (makes sense). So, what's the purpose of APB2 Timer clocks?
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8168
  • Country: fi
Re: General question on clock tree (STM32)
« Reply #1 on: September 24, 2018, 04:32:09 pm »
Most STM32 devices seem to have this interesting concept of a seperate timer kernel clock that has an optional doubler, which is automatically enabled when you enable an upstream divider.

The reference manual explains this in detail. The idea is, say your HCLK (AHB clock) is 80MHz, and you want to divide it by 2 to make your 40MHz PCLK2 (APB2 clock). Now, the timer will have separate interface clock, and the kernel clock which runs the counter - the kernel clock is derived by doubling the 40MHz clock, so the timer runs at 80MHz again.

This doubler is automatically enabled and disabled based on the PCLK2 divider. The idea is, while the interface freq is limited, the timer can run higher, so they do this.

For example, you might want to save power with lower interface clock. Now, you can change the bus prescaler on the fly, and the timer will still run at the same frequency (by switching the doubler in or out).

Do check the details from the reference manual. For example, what is the basis of the x2 multiplier being enabled or not. It may be something else.
« Last Edit: September 24, 2018, 04:33:42 pm by Siwastaja »
 
The following users thanked this post: XaviPacheco

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: General question on clock tree (STM32)
« Reply #2 on: September 24, 2018, 06:09:47 pm »
I've attached a fragment of the Nucleo L432 clock tree. At first insight I thought that Timer 2 (connected to APB2) were clocked at "APB2 Timer Clocks" frequency. But then I realized that I was wrong, and that timers peripheral are clocked at "APBx Peripheral Clocks" (makes sense). So, what's the purpose of APB2 Timer clocks?
What Siwastaja said, plus:
APBx is just a generic name for APB1 or APB2, used (sparingly) in the manuals when the description applies to both, or a register has two similar instances, one for each APB.

A timer peripheral will be driven by either APB1 or APB2.

But you are actually right, you were in fact wrong as TIM2 is connected to APB1 according to Figure 1 in the datasheet
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
Re: General question on clock tree (STM32)
« Reply #3 on: September 24, 2018, 06:32:43 pm »

But you are actually right, you were in fact wrong as TIM2 is connected to APB1 according to Figure 1 in the datasheet

 :palm:

As I'm using TIM1 and TIM2 and they are connected to APB2 and APB1 respectively I confused myself when writing this post. At the end of the day my confusion was between APBx Peripheral Clocks and APBx Timer Clocks in CubeMx Clock Tree.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf