STM32 gotchas
251. While switching peripheral clock source in 'H7, both clocks before and after switch must be present

In the 'H7 family - as in many if not all newer STM32 families - many peripherals' kernel clock can be selected from several clock sources using multiplexors in RCC. However, during switching, both the original clock source and the new clock source must be present, otherwise the switch fails and the peripheral may be left without a kernel clock, leading to surprising behaviour.

As register accesses are not clocked by the kernel clock, such peripheral may still appear to be working from the software point of view, except that the core functionality itself is broken.

This is documented in the 'H7 RM, including the fact that while the switching is synchronous, a two-cycle delay of the new clock is inserted.

The reset default of most such multiplexors is a clock, which is always present, such as the peripheral-related APB bus clock (rcc_pclkX); and if the user desires to use a different clock for some peripheral, usually it is started up as part of the clock tree bringup before switching the multiplexors, so this issue usually does not apply for most of the usual cases. As an example where this issue resulted in not working peripheral, user ESawa.1 used a non-default clock source for UART in a bootloader, switching off this clock source when transitioning from bootloader to application, and then attempting to switch the UART to a different clock source in the application 1.

It's not clear, whether this limitation pertains also to other STM32 families, which do have selectable kernel clocks for their peripherals.


1. This might have been further complicated by the fact that the internal kernel clock mux are not reset by NRST, only by power-on reset.