One way to generate such waveform involves using DMA to change the period+duty. While examples generate complex waveforms from many PWM periods to generate e.g. a sinewave, you'd need only two PWM periods, but DMA would need to change both period (TIMx_ARR) and duty (TIMx_CCR) in one cycle, using the TIMx_DMAR/DCR mechanism (in Cube it's called "burst"). This example may be a good point to start; you'd need to modify it so that the DMA is circular, and that there are two sets of values in the array from which DMA transfers them to TIMx registers.