How to activate HSI and CSI oscillators calibration

Revision as of 10:37, 23 June 2022 by Registered User

Applicable for STM32MP13x lines, STM32MP15x lines

1 Article purpose[edit]

The purpose of this article is to explain how to calibrate the HSI and CSI oscillators in the RCC, by using the OP-TEE Calibration PTA. The Linux client application, periodically called by a systemd[1] service. This systemd service is linked to a systemd timer, which defines when to call the application.

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 that 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.

2 Linux Daemon[edit]

The Linux calibration client relies on the fact that STM32MPU boards supports the systemd suite that starts the system. This suite handles daemons execution with a huge quantity of settings.

Regarding clock calibration: a service, responsible for executing the client calibration binary is linked to a timer.

You can change the timer settings by editing the Timer section in the stm32mp-calibration.timer file. By default, the timer trigger is set to 1 minute with an accuracy of 5 seconds, using the systemd timer OnCalendar and AccuracySec settings:

   [Timer]
   Unit=stm32mp-calibration.service
   OnBootSec=1min
   OnCalendar=*-*-* *:*:00
   AccuracySec=5sec

The Unit setting is used to specify which service should be called when the timer is triggered. The OnBootSec setting specifies the time after boot at which the timer should start.

This daemon is part of a specific OP-TEE add-ons repository: stm32mp-calibration/scripts/

3 OP-TEE PTA[edit]

The calibration binary is a Client Application (CA) connected to the OP-TEE Calibration PTA.

4 TF-A SP_MIN[edit]

This is only applicable on STM32MP15x lines More info.png and deprecated, OP-TEE calibration service must be used.

4.1 Configuring the timers[edit]

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>;
  };

4.2 Enabling and configuring the calibration service[edit]

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

  &rcc {
               st,hsi-cal;                   // Enable HSI calbration
               st,csi-cal;                   // Enable CSI calbration
               st,cal-sec = <60>;     // Timeout to start calibration
  };

5 References[edit]

  1. https://optee.readthedocs.io/en/latest/architecture/trusted_applications.html
  2. https://systemd.io/
  3. https://optee.readthedocs.io/en/latest/architecture/globalplatform_api.html