STM32 timer interrupt

Post here first, or if you can't find a relevant section!
Post Reply
STM23
Posts: 2
Joined: Wed May 05, 2021 3:52 pm

STM32 timer interrupt

Post by STM23 »

I'm using this core https://github.com/stm32duino/Arduino_Core_STM32
Any library where I can implement timer interrupts?
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: STM32 timer interrupt

Post by mlundin »

Well timer interrupts are tricky stuff ... but reading the documentation surely helps ...

https://github.com/stm32duino/wiki/wiki ... er-library
AndrewBCN
Posts: 105
Joined: Sun Apr 25, 2021 3:50 pm
Answers: 1
Location: Strasbourg, France

Re: STM32 timer interrupt

Post by AndrewBCN »

As mlundin wrote, check the examples in the HardwareTimer library. The input capture example implements both rollover interrupt and input capture interrupt service routines ("callbacks").
https://github.com/stm32duino/STM32Exam ... putCapture

And again as mlundin wrote, be careful with interrupts, they are more complex to use than non-interrupt code.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: STM32 timer interrupt

Post by khoih-prog »

You can try to use my STM32_TimerInterrupt Library to see if OK for you.
RobertoBerner
Posts: 36
Joined: Tue May 09, 2023 10:45 pm

Re: STM32 timer interrupt

Post by RobertoBerner »

khoih-prog I will always take a look at your advices. But my problem is how to register an interrupt vector or pointer from an interrupt event generated by the timer, in my case F1 TIM! or TIM2.

I already tested your library, but it was slow for my purposes and need to have some more control. Maybe because of my own ignorance on this new core, my testing was insufficient, so I will give it a try again. Thank you.

I am working hard to keep it CMSIS coding before I jump to plain C, direct access to registers. HAL is to heavy for my taste.

This is the step I don't know how to solve, It can't be that difficult, but I am not receiving the precise info.
I need a 5 KHz PWM interrupt event generated by the TIM1 or TIM2, with output signal on a pin, say PA8, and an interrupt handler because I need to count pulses on every PWM cycle.
The examples you are kindly giving are mostly based based in an F4 or something similar machine (correct me if I'm wrong) , while it takes time to convert and figure out how to adapt your code to the F1 BluePill, with the risk that on top one could do something wrong in the translation. If your library has a simple, straightforward example of a timer interrupting and clearly explaining the method to attach an interrupt handler, I'm going that way and solve the problem.

If not, I will switch back to STM32CubeIDE, that I have been using some time ago when I bought my BluePills and ST-Link, and despite the HAL method, I don't have to fight against Arduino IDE, not knowing what resources it is taking for its own purposes, meaning timers for delay(), etc. or if it is still necessary to use AttachInterrupt(), interrupts(), or all of this doesn't work if STM32 is working on the IDE.

I will first will take a look at your library and be back to report. In the meantime, could you please check if there is a grose error I don't see in my code? I would very much apprciate that.

Thank you !
Roberto
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: STM32 timer interrupt

Post by GonzoG »

STM32 examples for timers are for STM32 core, not for a specific MCU. You don't have to adapt anything.
jacobli
Posts: 42
Joined: Fri Jun 11, 2021 3:40 am

Re: STM32 timer interrupt

Post by jacobli »

Simplify all interrupt programs and reduce the time consumed by interrupt programs.
Post Reply

Return to “General discussion”