STM32 gotchas
93.Timers don't support DIR/STEP encoders (except in 'G4) - but a trick may exist

Timers in STM32 support quadrature encoders - and they count up/down as expected, according to the order of edges in the two quadrature signals. Not all timers support this, and those which do (usually TIM1 to TIM5, TIM8 and TIM20), cannot be used for any other useful purpose, as their slave-mode controller and the single counting element is used for this feature; and only CH1 and CH2 can be used as inputs of quadrature signals. Nonetheless, this still is a very useful and sought after feature.

However, there are also other types of encoder out there, which don't output quadrature signal, rather, they output one signal determining direction, and second signal pulsing upon each step. Such encoder is not supported by most STM32, as there is no direct way to change the direction of counting (indicated by TIMx_CR1.DIR bit) from a pin. The newest STM32G4xx line is the exception, as the timers there have been enhanced and they support DIR/STEP style encoders directly in hardware.

However, on older STM32 models, there may be a trick available, as described by berendi on the STM32 forum. The trick is based on generating a signal from DIR/STEP, which together with STEP behaves similarly than quadrature signal, by XORing DIR and STEP together and delaying it slightly.

For XOR, the internal XOR of timer is used. As this XOR uses 3 inputs - CH1, CH2 and CH3 - one of the inputs has to be kept on an unchanging level. For this purpose, either one pin has to be tied to GND or VCC externally, or the undocumented property that unconnected peripheral pad is at steady 0 level, can be used.

As an adjustable delay, the filtering feature of timer channel input can be used. This then determines the maximum clock rate of STEP signal.