STM32 gotchas
42.First TIM Update ("PeriodElapsed") interrupt fires immediately after configuration, when using Cube/SPL

As the timer register prescaler is unconditionally preloaded, libraries such as Cube/HAL, Cube/LL or SPL, when initializing a timer, they invariably set the EGR.UG bit to generate an Update event which would force loading the preloaded values of PSC and RCR into the respective "working" registers. As a consequence, after performing such initialization and enabling Update interrupt (sometimes renamed to "PeriodElapsed" or similarly), this interrupt "fires" immediately, sometimes puzzling the users.

The remedy is easy - after the timer initialization and before enabling the respective interrupt in NVIC, TIM_SR.UIF has to be cleared.