STM32 gotchas
303. HSE/HSI/MSI/LSE/LSI the oscillator naming conundrum

In the (quite distant now) past, early microprocessors had to be fed by a clock signal 1 for them to work. However, with the advent of microcontrollers, users wished to have an all-in-one solution, and manufacturers provided that by integrating an oscillator circuit onto the chip. This was essentially a linear amplifier, which together with an externally attached crystal and required capacitors formed a crystal oscillator, providing precise clock to the mcu. In lower-demanding lower-cost applications, the crystal could be replaced by ceramic resonator (usually integrating the capacitors within the package, thus more compact, cheaper, but also way less precise and stable). In some mcus the oscillator could run even with an attached simple RC circuit, if a very low precision and stability was not a problem for given application.

With increasing integration mcu manufacturers realized, that they could integrate an RC oscillator (or similar, e.g. gate-ring oscillator) onto the chip, providing an always-available known-good, although not very precise clock. This allowed controlled operation upon startup, and also potentially freeing up pins, which are often a valuable asset for a mcu.

In STM32, such internal "RC" oscillators were also implemented from the very beginning. A relatively high speed internal oscillator, called HSI (High-Speed Internal), provides a 8MHz clock for the inital operation of the mcu, and also as a cheap source of clock for less demanding applications. It can be used as source for the built-in PLL to provide up to the tens of MHz of maximum operational speed of given STM32 model. In some higher-end STM32 families, HSI runs at 16MHz.

HSI is trimmable and is also factory-trimmed to a certain precision given in DS (usually 1% at room temperature, allowing crystall-less UART; although within the whole operating temperature range the precision may not be sufficient for such usage). The trimming step and range is individual for each STM32 family. In some STM32 families, there are additional HSI oscillators for specialized functions, e.g. the HSI48, featuring a hardware auto-trim to lock to USB signals (or to LSE), providing crystall-less USB operation.

In some low-power STM32, the role of initial clock is delegated to a Mid-Speed Internal oscillator - MSI. This usually provides a range of output frequencies switchable from 100kHz up to 48MHz, with 4MHz being the default. This too can be trimmed, and in some STM32 families auto-trimmed to LSE.

The third kind of internal oscillator in STM32 is the Low-Speed Internal oscillator, LSI. This can provide a clock for certain low-power low-speed peripherals such as RTC 2 or LPTIM, running during low-power operational modes (Sleep, Stop, Standby). Another purpose of LSI is to provide a reliable clock for the Independent Watchdog (IWDG). In fact, this is the primary purpose of LSI, so its design - precision and power consumption - is somewhat worse than optimal, to prioritize its reliability.

STM32 of course also provide the oscillator amplifier needed for forming a crystal oscillator. As the crystal is connected externally - and also as a contrast to the "internal" oscillators - these are called "external" oscillators. And therein lies the confusion: in the usual setup, only the crystal (and its surrounding "burden" capacitors) are external to the chip, the oscillator amplifier is internal. However, in all cases of these "external" oscillators it is also possible to connect a truly and entirely external oscillator (or any other clock source) to one of the pins, where normally the crystal would be connected (this also requires to set a "bypass" bit in the respective controlling register for given oscillator).

Such "true" external oscillators are manufactured by seeveral manufacturers, traditionally as an amplifier and crystal in one package, but in the recent years increasingly in the form of a MEMS integrated circuit. These provide guaranteed oscillation stability and startup time, in contrast to using "bare" crystal to form the oscillator, where the responsibility to get these things right lies upon the hardware/PCB designer.

In STM32, generally, there are two 3 such "external" oscillators. The High-Speed External oscillator - HSE - allows to attach crystals generally in range of 4MHz-32MHz (exact range depends on STM32 family/model). The Low-Speed External oscillator - LSE is dedicated to run with the ubiquitous 32.768kHz "watch crystal", is primarily intended to provide clock for the Real-Time Clock (RTC) module, and as such, is in the VBAT-power domain and its design is optimized for ultra-low power operation.


1. Sometimes these were quite complex multi-phase clocks, as was for example the case of the venerable 8080, for which even a specialized companion clock IC, the 8224, was produced.

2. LSI is very imprecise thus not suitable for true real-time clock. The intention here is to provide a low-power wakeup source in timing-insensitive but power-sensitive applications, utilizing RTC's low power consumption and alarm/wakeup capabilities. Another reason why LSI is not suitable for maintaining real time is, that it is in the VDD power domain i.e. not running in VBAT mode.

3. In some pin-constrained STM32 models in small packages, not both LSE and HSE are available (they may be available in higher-pin-count package of the same STM32 model, though). In some models, only one of LSE/HSE is available; in others only the xSE_IN pin is available, enabling external clock source but not crystal oscillator operation.