STM32F0, stopping timer at the end of the counting period
Have you checked the Timer One-Pulse mode? It can be used to run the timer for asingle period. As far as I understand your question this could solve your problem.
Another posssibility would be the break function.
It will set the TIM output module back to reset state based on different sources. Most of them are internal failure detection events but you can also use a comparator input.