STM32 gotchas
305. LSE pins left floating but LSE enabled, may or may not generate enough pulses from noise to set LSERDY (maybe for HSE this applies, too)

LSE - the low-power external oscillator intended to be used with a 32.768kHz crystal - after enabled, indicates oscillations by setting the RCC_BDCR.LSERDY flag. However, this indication is based on a simple counter, with no discrimination for the input frequency/pulse width 1. The LSERDY flag is set, as soon as there are 2N pulses counted 2 after enabling the oscillator.

Due to the low-power nature of the LSE oscillator, if its pins are left open (e.g. the crystal is not populated e.g. for cost reasons), it may pick up noise and/or start to oscillate spuriously. Such pulses are counted by the counter, too, and eventually the LSERDY flag may get set.

The gotcha lies in the fact, that if the developer does not account for the missing crystal, a loop waiting for the LSERDY flag may remain in place, and due to spurious pulses result in seemingly "working" application. However - as witnessed by user OpusOne - this mechanism is not reliable and some products then may appear to be "not starting" properly.

Similar mechanism may apply to HSE, too.


1. Some newer STM32 do have a LSE-clock security system (LSECSS) sub-module, which, if enabled, compares the LSE oscillator's frequency to the internal LSI oscillator (or some other, possibly dedicated, internal oscillator). When they differ significantly, it invokes some sort of interrupt. However, this does not influence the LSERDY mechanism during the initial LSE startup.

2. This is not documented explicitly, although there are hints to this, e.g. the 'F0 RM states that HSEON is set after 512 pulses are seen.