Can you measure the frequency via interrupts when the pins are used by an encoder? SMT32F4
Did some more testing and reading and found the solution:


Instead of HAL_TIM_Encoder_Start() use HAL_TIM_Encoder_Start_IT(). Both execute the same code except the latter prepares for interrupts as well.
Enable the interrupt: HAL_NVIC_SetPriority(TIM5_IRQn, 0, 1); HAL_NVIC_EnableIRQ(TIM5_IRQn);
Implement the void TIM5_IRQHandler(void) { HAL_TIM_IRQHandler(&amp;htim5); } so that there is a interrupt handler forwarding the interrupt to the HAL layer.
Implement (or extend) the void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) callback function and add your code.


In my case the code is

if (htim-&gt;Instance == TIM5)
  {
    last_possensortick = HAL_GetTick();
    possensorduration = last_possensortick - possensortick_old;
    possensortick_old = last_possensortick;
  }


So I store the time between two interrupts and speed = 1/time. Almost. Only almost because the interrupt fires on a single pin only and the the time has to be between identical events, hence fires on a rising flank only.

The encoder on the other hand is configured as X4 encoder (sConfig.EncoderMode = TIM_ENCODERMODE_TI12;), so the position is updated on both flanks and on both channels.
see page 29 at AN4013

Therefore the speed = 4/time instead of 1/time.

And some additional logic is needed if the time=0 and if the interrupt does not fire because the wheel does not move at all. That is the reason I store both, the duration and the lasttick. If lasttick > 2000 then speed = 0;

Above logic works for low speeds only. At high speeds the millisecond resolution and the interrupt execution timing creates more and more errors. Therefore I will use both speed inputs, the speed=old_pos-current_pos; and the speed=4/duration;