Generate a fixed number of pulses on the STM32F4 PWM
Enable capture compare interrupt with setting CCxIE bit in TIMx_DIER register(fill x's with your timer and cc channel). this enables an interrupt processed whenever a pulse is completed. In your isr you can check TIMx_CNT register to double check.

Enable pwm, start counting your pulses in isr, when you reach the desired number of pulse disable pwm.