How to generate timer on STM32F4 Discovery Board?

How to generate timer on STM32F4 Discovery Board?

In this tutorial, I will share how to generate interrupt every given interval using timer on STM32F4 Discovery board. For example project, we will make orange LED toggle every 500ms interval using TIM2. In the main program we will toggle blue LED every 2500ms (blue LED toggling will not using timer interrupt, but just use delay function).

How to blink a green LED in STM32?

In this example the void BSP_LED_Init (Led_TypeDef Led) and the void BSP_LED_Toggle (Led_TypeDef Led) functions will be used from the stm32f4_discovery.c file to blink the green LED, which is LED4. To decide which LED is which use the schematics of the Discovery kit.

What is the clock time of the STM32F4?

By default the configuration uses the internal RC oscillator which provides a system clock time of 16MHz. This can be configured as high as 168MHz. To easily configure the clock configuration you can use an excel file that was created by ST.

How to set TIM2 clock to 84mhz?

There is an ST page with instructions, but it isn’t as clear as some of the other tutorials. If you do this, the APB1 bus, the one that TIM2 is on, will run at 42MHz max, giving you an 84MHz TIM2 clock (it’s doubled by PLL).

How are LEDs connected to PWM in STM32F4?

Leds are connected to pins PD12 to PD15, what give us timer TIM4 with Output channels 1 to 4. Here we will initialize timer, for our PWM frequency. We have to set prescaler and period for how fast will it count and how much it will count for specific PWM frequency.

How does the timer and interrupt work on TIM3?

In it’s current state I have the timer and interrupt working so that when TIM3 finishes counting up it’s period, it throws an interrupt which I have a handler written for. I can then blink an LED or do whatever I need to in this handler.

How to write code for a timer clock?

This is the block diagram for configuring the timer clock: After that, we must write code for interrupt handler that will be call every timer interrupt (500ms). In this handler, we write code for toggle orange LED. Finally, in the main function we can write code for toggle blue LED using delay function. The blue LED will toggle every 2500ms.

How to control STM32 hardware timers with interrupts?

Run the program and notice how the LED blinking pattern has changed. Now instead of polling the timer value constantly and switching the LED on and off on certain threshold values we simply wait for the TIM_IT_Update interrupt and toggle the LED once it arrives.

How many external interrupts does the STM32F4 have?

Each STM32F4 device has 23 external interrupt or event sources. They are split into 2 sections. First interrupt section is for external pins (P0 to P15) on each port, and other section is for other events, like RTC interrupt, Ethernet interrupt, USB interrupt and so on. October 1, 2014: Added external interrupts library.

Can you use two pins at the same time in STM32F4?

They are multiplexed to one line. IMPORTANT: You can not use two pins on one line simultaneously: PA0 and PB0 and PC0 and so on, are connected to Line0, so you can use only one pin at one time to handle interrupt from there. PA0 and PA5 are connected to different lines, they can be used at the same time.

How are PA0 and pb0 connected in STM32F4?

PA0 and PB0 and PC0 and so on, are connected to Line0, so you can use only one pin at one time to handle interrupt from there. PA0 and PA5 are connected to different lines, they can be used at the same time. Each line can trigger an interrupt on rising, falling or rising_falling enge on signal.