Time2 interrupt code: normal for example ,run with bug when add the loop and tim.deinit()

Hi, you are deiniting the timer in the callback and dynamically reiniting the timer not necessarily with a deinit. I can’t say what will happen when doing this. You should set a flag (after checking if it was not set) in the callback and then deinit the timer in the main loop if the flag was set (and then clear the flag). Also, only reinit the timer if it was deinited.