So I'm trying to set up a very simple periodic interrupt on my STM32VL-Discovery board using the libopencm3 libraries on linux. I've looked at the documentation and I just want to verify with somebody that I understand what's going on.

My understanding is that the prescaler register scales the internal clock to another frequency/clock that the timer actually sees. i.e. you set the timer prescaler register to 24Mhz/DesiredHz to get the timer to operate at the desired frequency. Is this correct?

Assuming that's correct, say I want to generate an interrupt on every timer clock cycle. I didn't see anything in the docs that would allow me to do that besides setting the period register to 1. This would generate an overflow interrupt every clock correct?

  • 1
    \$\begingroup\$ That sounds approximately right, but the difficulty is always in the details, including remembering to power on and clock enable everything first. The STM32 series peripheral libraries come with a lot of examples, you might look for a timer interrupt example first. If not there, you might check elsewhere in the STM32 series as the overall methods tend to be comparable though the specific registers, calls, and peripheral bus assignments differ between families. \$\endgroup\$ Mar 14, 2013 at 19:23
  • \$\begingroup\$ See (somewhat) related on setting the clocks in the STM32: electronics.stackexchange.com/questions/58863/… \$\endgroup\$ Mar 15, 2013 at 14:54
  • \$\begingroup\$ Thanks guys. What I did worked. I just wanted to understand it better and you both enabled me to do that. \$\endgroup\$
    – Caustic
    Mar 15, 2013 at 22:10

1 Answer 1


If you just set the period register to 1, this won't automatically enable interrupt generation. You will need to do 2 additional steps:

  1. Enable the 'update' interrupt for your timer using the TIM_ITConfig() function.
  2. Enable the timer interrupt source in the interrupt controller by calling NVIC_Init() with appropriate parameters.

Of course, you should not forget to enable clocking of your timer peripheral using the APB1PeriphClockCmd().

There's a detailed example on configuring timers on STM32F4-Discovery here: http://visualgdb.com/tutorials/arm/stm32/timers/

STM32VL-Discovery is a bit different, however the main steps are the same.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.