Showing results for 
Search instead for 
Did you mean: 

Triggering the input PWM or output PWMs using the HRTIM on STMG4

Associate II


I'm currently using the HRTimer (on a STM32G474) for duplicating a input PWM signal. That means that in my case, I have one PWM input coming on 2 events (1 for the rising edge, 1 for the falling edge) and the outputs of the HRTimer B, will be set and resets according to those events. So at the 2 outputs of the HRTimer B, I have 2 PWMs that are identical to the input one.

I want to have the possibility to trigger a "flag" whenever I'm receiving an input PWM. It could also be triggered on the output since they are duplicating the analog signal. 

For that, I'm seeking for some kind of callback function or interrupt function to use to trigger my flag. I've found out that we have the functions HAL_HRTIM_OutputxSetCallback and HAL_HRTIM_OutputxResetCallback to trigger on the outputs but unfortunately, I'm not able to make them work, it never enter in those functions.

Does it exist any solutions to my issue ?

Thanks for your returns,


ST Employee

Hello Chris @Sidius,

Thank you for your question!

Here some questions/points :

  • First, can you tell me more about your application ?
  • Why are you using the HRTIM for "duplicating a input PWM signal" ? The HRTIM generate signals with highly accurate timings. Wouldn't a simple TIM be enough resolution for your application? 
  • HAL_HRTIM_Output1SetCallback() is invoked when the timer 1 output 1 is set. No problem appears to me by setting your flag here and clearing it in the Reset callback.
  • The NVIC part related to the HRTIM is programmed in the HAL_HRTIM_MspInit() function. By default, after the HAL_HRTIM_Init() and when the state is HAL_HRTIM_STATE_RESET all callbacks are set to the corresponding weak functions. Callbacks can be registered/unregistered in HAL_HRTIM_STATE_READY state only. When the compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration is not available and all callbacks are set to the corresponding weak functions. 14 interrupts can be generated by each timing unit including counter reset, output 1 set/reset, capture, compare, repetition... (see the table 241 of RM0440 and check if the control bit is enable)

Best Regards,


To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Associate II

It was just the fact that I was not using the DMA with the HRTIM, so all the callback functions were not enable.
Thanks for the RM file, it will be very useful.

Kind regards,