Electronic – HSI and MSI – Applications of two Internal RC OSC in Microcontroller

clock-speedmicroprocessorstm32

In a ST microcontroller I'm using there are two OSC's that can be routed to exactly the same hardware and I'm wondering when you would use each one.enter image description here

Link to part documentation
STM32L496ZG

Excerpt from the data sheet about the two OSC's –

-16 MHz high-speed internal RC oscillator (HSI16), trimmable by software, that can supply a PLL

– Multispeed internal RC oscillator
(MSI), trimmable by software, able to generate 12 frequencies from
100 kHz to 48 MHz. When a 32.768 kHz clock source is available in the
system (LSE), the MSI frequency can be automatically trimmed by
hardware to reach better than ±0.25% accuracy. In this mode the MSI
can feed the USB device, saving the need of an external high-speed
crystal (HSE). The MSI can supply a PLL.

ST AN4555 Application Note explains

HSI16 clock

The HSI16 clock signal is generated from an internal 16 MHz RC Oscillator.
The HSI16 RC oscillator has the advantage of providing a clock source at low cost (no
external components). It also has a faster startup time than the HSE crystal oscillator
however, even with calibration the frequency is less accurate than an external crystal
oscillator or ceramic resonator.
The HSI16 signal can also be used as a backup source (Auxiliary clock) if the HSE crystal
oscillator fails. Refer to reference manual section: Clock security system (CSS).

3.3 MSI clock
The MSI clock signal is generated from an internal RC oscillator. Its frequency range can be
adjusted by software by using the MSIRANGE[3:0] bits in the Clock control register
(RCC_CR). Twelve frequency ranges are available: 100 kHz, 200 kHz, 400 kHz, 800 kHz,
1 MHz, 2 MHz, 4 MHz (default value), 8 MHz, 16 MHz, 24 MHz, 32 MHz and 48 MHz.
The MSI RC oscillator has the advantage of providing a low-cost (no external components)
low-power clock source. In addition, when trimmed by the 32.768 kHz external oscillator
(LSE), the MSI can provide the USB device with very accurate clock removing the need for
an external high speed crystal (HSE).

My problem

I've been pulling my hair out as the STLINK LPUART was adding an extra zero in the middle of each byte that I sent to the PC from the micro controller. I put it down to timing and I realised that I had assigned HSI as the LPUART clock. When I assigned MSI the error disappeared. I assume I'll need to trim the HSI as it must need calibration.

But this got me wondering, as I can use the MSI for just about anything, why do they include both clocks in the single chip?

Best Answer

HSI is way more accurate, while being less flexible.

Looking at the highlighted values in the datasheet, MSI frequency becomes extremely unreliable at the lower ends of the temperature and the supply voltage range, while HSI would barely notice VDD dropping from 3.6V to 1.8V.

Therefore it is quite surprising that you were having problems with HSI as a clock source. Adding a bit in the middle would mean about 20% clock drift. That's a magnitude worse than the theoretical worst case accuracy of the HSI. There must be some other issue still lurking.

It is also worth noting that HSI16 can run in the STOP modes, but MSI can't.

HSI16 MSI-1 MSI-2