I think what should you do is leave the timer channel running, e.g. not call
HAL_TIM_PWM_Stop(&htim17, TIM_CHANNEL_1);
which in turn calls TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
and stops the channel completely. What worked for me was setting the output always low by setting appropriate bits in the OC1M
field in the CCMR1
register. Something like
htim4.Instance->CCMR1 = (TIM_CCMR1_OC1M_2);
which effectively sets the channel to mode always low. If you want to, you can stop the counter using __HAL_TIM_DISABLE()
macro. Don't forget to start it again when you resume operation. When you want to resume the PWM, revert the bits to your wanted values accordingly.
I think that the Idle state setting applies only when you first start the channel and it is running.
Other thing to note is that output compare channel remembers its state even after completely resetting the peripheral.