Timer Compare Interrupt

Is it possible create interrupt service routines for timers and if so, are there some examples? I would like to be able to directly:

enable a timer
set a timer prescale value
set a timer compare value
enable an interrupt on the timer compare value
read a timer interrupt flag value
create an ISR for the interrupt
read a timer value

I have done this with other processors and am fine with writing directly to registers or using a HAL library.

You may want to have a look at the links provided in this post

Thanks. Reading the material you referenced was very helpful. Looks like I can trust that the SparkIntervalTimer library will take care of some basic timing interrupt needs though I still have a few questions.

  1. How do you recommend reading the value of a timer in the particle environment? Looking at the Standard Peripheral Library, it looks like the following would work. unsigned long count = TIM_GetCounter(TIM3); Is this correct?

  2. Does Particle support the STM32 Standard Peripheral Library as referenced in ST document UM1061? If so, should I just use common sense regarding what register values to set, so as not to stomp on a critical running process in the Particle Photon?

  3. Is the HAL library an updated version of the STDPeriph. Is the HAL library supported by Particle?

The STM32 Standard Peripheral library is accessible from user firmware. In general most of the functions work. The major exception is interrupt handling. System firmware tends to take over all interrupt vectors so it’s takes some care to deal with that. But certainly setting timers, ADCs, etc. all work great using the STM32 Standard Peripheral Library directly.

In my photonAudio example project that ScruffR linked to, the audio3 example uses the STM32 standard peripheral library directly to manage the ADC.

If you’re doing something that has an exported HAL function, that’s usually the safest because it’s an abstraction of the hardware, not tied specifically to the STM32 so theoretically at least it might work on other platforms.

1 Like