I am trying to implement a simple interrupt routine, blinky led using a timer on the stm32f103 "blue pill" board.
I have been reading the datasheet, reference manual, timer cookbooks and all but I'm not able to figure this part out.
I'm using the gnu-arm cross compiler and was successful in getting a timer a started and was able to blink an led by continuously checking the 'update event' bit inside the TIMx_SR register.
Up till now, I had a look at the NVIC section in reference manual but I can't figure out exactly how to work with the vector table…
Any suggestions or resources are welcome.
Best Answer
I will attempt to answer this fairly vague question by listing the high level steps to set up a timer interrupt, to help point you in the right direction.
DIER
. You will likely want to set theUIE
bit in this register, however don't take my word for it. You should read the whole section of the manual to understand how the timer works and how to set it up.IRQ
in theNVIC
. This hardware (the NVIC) is not specific to STM32, but is common to all ARM microcontrollers. Each interrupt line on the chip (there may be one dedicated to the timer you are using, or it might be shared by several peripherals) is referred to by an integer. I usually look in the device header file for this information, and I recommend getting comfortable with looking through the vendor code for answers about the chip you're working with.UIE
bit, you will need to then clear the correspondingUIF
bit in the status register. This is the only way the peripheral knows that the interrupt has been handled. If you don't do this, the chip will lock up because it is continuously entering the interrupt handler.Other general advice: the book "The Definitive Guide To ARM Cortex-M3 and Cortex-M4 Processors" helped me understand a lot of this stuff, but not as much as closely reading the chip manual and vendor-provided code.