cancel
Showing results for 
Search instead for 
Did you mean: 

How to choose APB1/2 and freq. multiplied by two or not for TIMERs

ihouses ihouses
Associate III

Hello,

I am generating a PWM frequency with Timer5 in a STM32F7 device and I noticed that the TIMER5 input clock is 1/4 of HCLK by default and it is connected to APB1. I was checking in the documentation or in the code how to connect the input clock to APB1 multiplied by two or if it is possible to connect to APB2.

Where is indicated the APBx of a certain TIMx and how to select the APBx freq or APBx freq x 2?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ihouses ihouses
Associate III

Well, finally the solution is:

RCC->DCKCFGR1 |= 0x1 << 24; // Double frequency!!!!!

With this APB1 will run at double frequency :)

Thanks!

View solution in original post

8 REPLIES 8

The Reference Manual and clock tree diagrams?

The TIMCLK is always APB x2 except in the case where APB is DIV1 wrt AHB, as it doesn't actually multiply, it just pulls a clock feed one divider earlier in the chain.

A TIM uses APB1 or APB2 depending on how resources were allocated to peripherals in the design, it is fixed.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ihouses ihouses
Associate III

Hi,

Well cubeMX selects PCLK1 by default for TIM5, so not x2.

> A TIM uses APB1 or APB2 depending on how resources were allocated to peripherals in the design, it is fixed.

Where are such resources allocated? Can I check that with CubeMX?

Depends on what APB1 is set too, most systems it is usually DIV2 or DIV4, as APB2 is the faster bus

The system block diagram from the data sheet might be what you need to review.

0690X000009YkirQAC.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ihouses ihouses
Associate III

Hi,

I see thanks. I am not familiar with STM32 architecture so I not even thought looking at the main diagram, I am coming from the PIC world :)

Now only remains to know how to select between ATBx and ATBx x 2, any idea?

You don't really get much of a choice, it is primarily driven by the APB divisor, and you get to further divide with the prescaler.

The F7 provides additional clock sourcing options via RCC_DCKCFGR

I came from 8-bit 6502 micro-controllers, and printed manuals is all we had to work with.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ihouses ihouses
Associate III

Ok, thanks. Now I am going to do a question may too basic...

I want to modify the register RCC_DCKCFGR (bit 24, TRIMPRE), that as you say is as well in my STM32F732. How to do that?

What I am doing is: I go to this file: stm32f7xx_hal_rcc.h and check for that register name and.... nothing. Is not there? What is the "correct" procedure?

ihouses ihouses
Associate III

Ok, I found that this is possible: RCC->DCKCFGR1 and RCC->DCKCFGR2...

ihouses ihouses
Associate III

Well, finally the solution is:

RCC->DCKCFGR1 |= 0x1 << 24; // Double frequency!!!!!

With this APB1 will run at double frequency :)

Thanks!