Can I share the pin (PA0) between timers TIM2 & TIM5 (GPTIMs)?

Timers 2 and 5 can both use PA0 as an input, conveniently on ch1. Is there any issue with configuring both of them to use PA0 as ch1 in that I have not considered. The reason for this is the calculate both speed and angle from a rotary encoder. TIM2 is configured in PWM input mode to calculate speed (and acceleration). TIM5 is configured in Encoder mode (x4, TI1 & TI2)

Encoder_A -> PA0 ->TIM5_CH1 & TIM2_CH1 Encoder_B -> PH11 -> TIM5_CH2 Encoder_Z -> PA8 -> EXTI interrupt (secondary question: is there a HW way of resetting the Encoder timer such as through ETR or does this have to be done with an ISR? Related question)

I am working with the ST32H747 (Arduino portenta H7) and the portenta breakout board:

The encoder is a 1024 pulse quadrature encoder with mechanical z-index with 6 outputs (A, B, C(z), ¬A, ¬B, ¬C)

Edit: I should probably add a link to the RM: Reference manual the timers in question are described from page 1781 onwards


1 Answer 1


Only one TIM can be connected to the pin at the same time. Peripheral selected to the pin is configured using GPIOx_AFRL/GPIOx_AFRH registers and these allows select only one alternate function (peripheral) to the pin.

One possible easy way to solve your problem is wiring the same signal to two pins.

  • \$\begingroup\$ That is the currently planned solution \$\endgroup\$
    – L Selter
    Commented Oct 25, 2023 at 15:36
  • \$\begingroup\$ While this solution would work, there's another way. You can configure your TIM5 as a master to output TIM5_CH1 (or TIM5_CH2) on TRGO internally. You can then set up TIM2 in slave mode to measure TIM5_TRGO in PWM input mode. Relevant registers: TIMx_CR2[MMS] for master, TIMx_SMCR[SMS] for slave, TIMx_SMCR[MSM], TIMx_SMCR[TS]. \$\endgroup\$ Commented Mar 19 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.