I am trying to set up TIM4 in Encoder Mode in Nucleo F767ZI. I used STM32CubeMX to set up the Timer. The TIM->CNT value oscillates between two values. On checking further, I found the DIR bit to be oscillating between 0 and 1. If I read the values of both the channels and do an external counting, it works fine. I am reading both edges on both the channels.