How to activate HSI and CSI oscillators calibration

Revision as of 14:21, 20 November 2021 by Registered User (Initial MP13 work)

1. Article purpose[edit source]

The purpose of this article is to explain how to calibrate the HSI and CSI oscillators in the RCC, by using the TIM internal peripheral TIM12 and/or TIM15 assigned to the secure monitor: TF-A (Only on STM32MP15x lines More info.png) or OP-TEE.


These clocks are internal oscillators whose frequency can be affected by temperature and voltage variations. To achieve a good clock accuracy, it is important to provide a mechanism to compensate the effects of these variations.


The clock calibration algorithm is based on the comparison of a timer (fed by HSI or CSI) and a clock is derived from the HSE clock that is considered as always accurate.

Refer to STM32MP13 reference manuals or STM32MP15 reference manuals for detailed information on the timer channels that can be used for HSI or CSI calibration input.

The algorithm is implemented in the secure monitor. It compares both clocks and programs a correction factor in the RCC peripheral. There are various ways to trigger this service:

- periodically by the secure monitor itself

- upon kernel request through a dedicated SMC

- upon Arm® Cortex®-M4 request through a SEV (Only on STM32MP15x lines More info.png)

2. How to activate the calibration[edit source]

This is done in the secure monitor device tree.

2.1. OP-TEE[edit source]

HSI and CSI calibration are both enabled by default and defined at Device tree SoC level Link to OPTEE file.

At board level, it is possible to :

  • Customize the calibration period
  • Disable total or part of the calibration
  • Update timer used to calibrate HSI and CSI

Example at board level:

  &osc_calibration {
          sec = ...
   }

2.1. TF-A SP_MIN[edit source]

This is only applicable on STM32MP15x lines More info.png

2.1.1. Configuring the timers[edit source]

The timers used for calibration must be assigned to the secure context.

Example: timer12-input1 is used for HSI and timer12-input2 for CSI

  &timers12 {
             secure-status = "okay";
             st,hsi-cal-input = <1>;
             st,csi_cal-input = <2>;
  };
  &timers15 {
             secure-status = "disabled";
             st,hsi-cal-input = <7>;
             st,csi_cal-input = <8>;
  };

2.1.2. Enabling and configuring the calibration service[edit source]

This can be done by enabling options inside the clock device tree section