cancel
Showing results for 
Search instead for 
Did you mean: 

Callback on Timer Triggered

CN123
Associate II

Hi,

I've got a timer in One Pulse Mode, triggered by a pulse on a GPIO pin.

Can I set it up to also get a callback in my application code when I receive that pulse? (i.e. when the timer starts)

Is this even possible or do I need to wire the signal to another GPIO pin as well?

Thanks

4 REPLIES 4
TDK
Guru

What chip?

You can generally have EXTI enabled on a pin that is still acting as a timer. Setting up an EXTI trigger for a rising edge on that pin would give you what you want.

If you feel a post has answered your question, please click "Accept as Solution".
CN123
Associate II

Thanks for replying.

it's a STM32F303CBT6.

Is it possible to set this up through STM32CubeMX or do I need to write to the registers directly?

TDK
Guru

If you right-click a pin in CubeMX and select "Pin Stacking" you can then assign both functions (TIM and EXTI) to the pin. In theory this should work, but I did not test it.

Please mark one of my replies as the solution if you find that it answered the question, it helps close it out and lets others find it more easily.

If you feel a post has answered your question, please click "Accept as Solution".
CN123
Associate II

Doesn't quite work. I can set the trigger in the timer's Mode panel, but when I do that the interrupt function has "no mode" and it doesn't seem to generate the code for the interrupt callback to work. If select the EXTI function again to fix that, the trigger is unset from the timer.

Alternatively I have found that I can call HAL_GPIO_Init twice: first to set the pin as an interrupt, then again to set it to the alternate function for the timer. That works, presumably because it's setting different registers each time; it feels hacky though because I guess a future HAL revision could "fix" this function to make sure all registers are set to a specific value every time, rather being than ignored.