Beware of the STM32 LSI: Its tolerance is up to ±47%

The STM32 LSI oscillator might seem like an attractive choice for RTC, IWDG Watchdog etc - without external components and

But one fact is often overlooked: Since it is internally a RC oscillator, it has an extremely high tolerance.

By looking at the STM32F407 datasheet, for example, we can see that its tolerance is ±47% In other words, the LSI clock can run half as slow or 1.5 times as fast as expected. ±47% is equivalent to ±470 000 ppm whereas any normal crystal has a tolerance of ±20 ppm.

More recent STM32 families like the STM32H747XI have improved LSI accuracy:

This amounts to a tolerance of ±1.875 % which is equivalent to ±18 750 ppm - still orders of magnitude more than any crystal or even ceramic resonator.

Can you tune out the difference by RTC digital tuning?

The STM32 digital tuning only has a range of -487.1 ppm to +488.5 ppm - but even for the much more accurate STM32H747XI, you would need a tuning range of at least ±20 000 ppm in order to compensate for initial inaccuracies and temperature coefficient.

What can you do to get better accuracy?

Typically, I recommend to just use a crystal for the RTC - or use an external RTC altogether.

Regarding the IWDG, you have no choice but to use the LSI. Typically you can just select a longer reset interval to avoid unintended watchdog resets if your LSI is running much faster than the standard 32 kHz, or you can just reset the watchdog more often. If you reset your watchdog in an interrupt, you should consider using a higher priority interrupt - and do global interrupt disables less frequently and try to avoid having periods where interrupts are disabled globally for a long time continously.