Proper way to turn off PWM channel on STM32
This is what the Break functionality is for, as the reference below says

Break input to put the timer’s output signals in reset state or in a known state.
The break can be generated by the BRK input which has a programmable polarity and an
enable bit BKE in the TIMx_BDTR Register.
There are two solutions to generate a break:
• By using the BRK input which has a programmable polarity and an enable bit BKE in
the TIMx_BDTR register
• By software through the BG bit of the TIMx_EGR register.

See 17.3.12 of the reference manual RM0090