TIMER2 STM32F411 BLACKPILL

For general Flowcode discussion that does not belong in the other sections.
Post Reply
max.tisc
Posts: 127
http://meble-kuchenne.info.pl
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 10 times

Flowcode v10 TIMER2 STM32F411 BLACKPILL

Post by max.tisc »

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
Attachments
led.fcfx
(18.58 KiB) Downloaded 6 times
Screenshot 2025-10-21 190941.png
Screenshot 2025-10-21 190941.png (228.21 KiB) Viewed 87 times

medelec35
Matrix Staff
Posts: 2147
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 662 times
Been thanked: 724 times

Re: TIMER2 STM32F411 BLACKPILL

Post by medelec35 »

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.
Martin

LeighM
Valued Contributor
Posts: 503
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 88 times
Been thanked: 269 times

Re: TIMER2 STM32F411 BLACKPILL

Post by LeighM »

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? :) )

Steve-Matrix
Matrix Staff
Posts: 1606
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 223 times
Been thanked: 379 times

Re: TIMER2 STM32F411 BLACKPILL

Post by Steve-Matrix »

Thanks for that info, Leigh.
LeighM wrote:
Wed Oct 22, 2025 4:20 pm
A tooltip explaining this STM anomaly might also help (similarly for the clock speed in Project Options)?
(Any chance Steve? :) )

Added to the list. :)

max.tisc
Posts: 127
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 10 times

Re: TIMER2 STM32F411 BLACKPILL

Post by max.tisc »

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.

Post Reply