STM32 gotchas
293. In Up-Down (Center-Aligned) mode, Update event occurs at both Overflow and Underflow, making TIMx_CCRx update somewhat tricky

In the STM32 Timers, for channels set as Output Compare, their respective TIMx_CCRx registers determine the point within the timer's period, where the output has to change. If this point has to change during timer operation - e.g. a PWM output's duty cycle has to change "on the fly" - the best practice is to use CCR preload, to avoid various strange/errorneous "transient" pulses to appear during those changes. If such preload is enabled, the "acting" TIMx_CCRx is loaded from the "written" register at the next Update event, i.e. at the very beginning of the next timer period.

If the new TIMx_CCRx value is written upon a previous Update event - i.e. either in Update interrupt, or using DMA triggered by Update - this also provides the maximum time window for consistent change of compare point in every timer cycle (or every N cycles). This maximum time window is beneficial also when several channels are to be changed simultaneously (and/or the period has to be adjusted by writing into TIMx_ARR, too), e.g. through the TIMx_DMAR/DCR "burst" mechanism (or just through "manually" writing all the registers in program, if the time window is long enough and the potential complexity of DMA is desired to be avoided).

In the Up-Down (Center-Aligned) mode, the Update event occurs twice per timer period: once at Overflow, and once at Underflow (more precisely, just before Overflow/Underflow). In the scenario outlined above this means, that TIMx_CCRx can be adjusted for both the upgoing and downgoing leg of the timer period, allowing for asymmetric waveforms even in timers of older STM32 models which don't have the Asymmetric mode built in.

On the other hand, one must be aware of this fact - and also of the "lag" caused by the newly written TIMx_CCRx value to be "acting" only after the next update - when writing interrupt code. That code must be aware of the current direction of counting - either by reading TIMx_CR1.DIR bit, or just maintaining a toggling variable - and if symmetrical waveform is to be generated, it must update TIMx_CCRx only while counting down.

Similarly, DMA has to be set up and started in a way which ensures consistency between the values transferred from a RAM/FLASH array to the TIMx_CCRx register(s); and if symmetrical waveform is desired, the values in the table have to be present twice - one for each leg of the timer period.