Page 1 of 1

TIMER2 STM32F411 BLACKPILL

Posted: Tue Oct 21, 2025 8:28 pm
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

Re: TIMER2 STM32F411 BLACKPILL

Posted: Wed Oct 22, 2025 8:03 am
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.

Re: TIMER2 STM32F411 BLACKPILL

Posted: Wed Oct 22, 2025 4:20 pm
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? :) )

Re: TIMER2 STM32F411 BLACKPILL

Posted: Wed Oct 22, 2025 4:30 pm
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. :)

Re: TIMER2 STM32F411 BLACKPILL

Posted: Wed Oct 22, 2025 5:22 pm
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.