Hi,
For a little timer project, I wanted to use the STM Timer2 to get some precision, but after some testing, the timing was off. So I made a little code with an LED and a UART output to get the timestamp. If my settings are correct, I should have an interrupt every second, and with the TIME variable set to 10, the LED should turn on and off every 10 seconds. But looking at the UART timestamp, it happens every second or so. Why is this? Where did I go wrong? The STM32 uses the internal 16 MHz HSI clock, not the external quartz.
Thanks
TIMER2 STM32F411 BLACKPILL
-
- Posts: 127
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 10, 2020 5:40 pm
- Been thanked: 10 times
TIMER2 STM32F411 BLACKPILL
- Attachments
-
- led.fcfx
- (18.58 KiB) Downloaded 5 times
-
- Screenshot 2025-10-21 190941.png (228.21 KiB) Viewed 82 times
-
- Matrix Staff
- Posts: 2146
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 662 times
- Been thanked: 724 times
Re: TIMER2 STM32F411 BLACKPILL
Hello.
Can you try with RCC_SYSCLK_SRC changed to HSI instead of PLL
With RCC_SYSCLK_SRC set to PLL the clock frequency is being multiplied.
Therefore there is a mismatch between clock frequency on hardware and on Flowcode clock speed.
Can you try with RCC_SYSCLK_SRC changed to HSI instead of PLL
With RCC_SYSCLK_SRC set to PLL the clock frequency is being multiplied.
Therefore there is a mismatch between clock frequency on hardware and on Flowcode clock speed.
Martin
-
- Valued Contributor
- Posts: 503
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 88 times
- Been thanked: 269 times
Re: TIMER2 STM32F411 BLACKPILL
This is one of a couple of "gotchas" with STM devices.
The issue is with the Timer Interrupt calculation dialog.
STM devices have numerous clocks, Flowcode only knows about one, the source clock rate in this case.
The clock driving the Timer 2 is a multiple of this clock if the PLL is used (depending upon how the various multipliers and dividers are setup) hence the timer parameters (rollover etc) need to be calculated manually instead.
There has been a suggestion requesting that the clock figure in this dialog is made editable for this reason.
See https://www.flowcode.co.uk/forums/viewt ... 453#p21453
The edited value would probably need to also be stored in the project.
A tooltip explaining this STM anomaly might also help (similarly for the clock speed in Project Options)?
(Any chance Steve?
)
The issue is with the Timer Interrupt calculation dialog.
STM devices have numerous clocks, Flowcode only knows about one, the source clock rate in this case.
The clock driving the Timer 2 is a multiple of this clock if the PLL is used (depending upon how the various multipliers and dividers are setup) hence the timer parameters (rollover etc) need to be calculated manually instead.
There has been a suggestion requesting that the clock figure in this dialog is made editable for this reason.
See https://www.flowcode.co.uk/forums/viewt ... 453#p21453
The edited value would probably need to also be stored in the project.
A tooltip explaining this STM anomaly might also help (similarly for the clock speed in Project Options)?
(Any chance Steve?

-
- Matrix Staff
- Posts: 1606
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 223 times
- Been thanked: 379 times
Re: TIMER2 STM32F411 BLACKPILL
Ok,
thanks everyone for the replies. Setting RCC_SYSCLK_SRC in HSI keeps the maximum frequency at 16 MHz. We're waiting for the calculation update.
Thanks.
thanks everyone for the replies. Setting RCC_SYSCLK_SRC in HSI keeps the maximum frequency at 16 MHz. We're waiting for the calculation update.
Thanks.