Last edited one week ago

LPTIM OpenSTLinux drivers

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP21x lines, STM32MP23x lines, STM32MP25x lines

1. Article purpose[edit | edit source]

This article introduces the Linux® and OP-TEE drivers for the LPTIM internal peripheral. It addresses the following questions:

  • Which LPTIM features are supported by the drivers,
  • How to configure, use and debug the drivers,
  • What are the drivers structures, and where the source code is located.

2. Short description[edit | edit source]

The LPTIM internal peripheral is supported in Linux and OP-TEE software components through dedicated drivers. Refer to the LPTIM internal peripheral to understand how a LPTIM particular instance is actually supported, depending on STM32 MPU device and execution context (here OP-TEE or Linux context).

2.1. OP-TEE driver[edit | edit source]

This chapter is only applicable for STM32MP13x lines More info.png and STM32MP2 series.

The LPTIM OP-TEE driver purpose is to allow HSE clock monitoring.

For instance, the LPTIM "Timeout function" is used to monitor HSE over-frequency:

  • the LPTIM is configured with a threshold,
  • the LPTIM counts on the HSE clock,
  • the LPTIM counter is cleared periodically on an external trigger event (based on divided HSI clock).

In case the HSE counter reaches the threshold, which means an over frequency condition has been detected, the interrupt line can be used to:

  • trigger a TAMPER directly,
  • execute an interrupt sub routine to notify the user (through a callback).

It implements the necessary API, such as: counter start, stop, get value, set threshold, set ceiling, enable or disable_event (threshold or overflow), set or release configuration (e.g. input selection). Based on interrupts, a callback routine can be registered, so the user gets notified when the configured event occurs.

2.2. Linux kernel driver[edit | edit source]

The LPTIM Linux driver (kernel space) is based on the PWM, IIO and counter frameworks. It provides several functionalities:

MFD driver:

  • handles common resources (registers, clock)

PWM driver:

  • handles the PWM output channel (single channel)

IIO hardware trigger driver:

  • handles hardware trigger sources (synchronously with PWM) for other internal peripherals such as ADC, DAC, DFSDM

Counter driver:

  • handles the quadrature encoder interface[1] as well as the external event counter.

Clockevent driver:

3. Configuration[edit | edit source]

3.1. OP-TEE driver[edit | edit source]

This chapter is only applicable for STM32MP13x lines More info.png and STM32MP2 series.

The LPTIM OP-TEE driver can be activated by enabling the build directives CFG_COUNTER_DRIVER (counter framework) and CFG_STM32_LPTIMER (STM32 LPTIM driver).

Refer to How to configure OP-TEE article for details on OP-TEE configuration.

3.2. Linux Kernel configuration[edit | edit source]

The LPTIM drivers are activated by default in ST deliveries, as a modules. Nevertheless, if a specific configuration is needed, this section indicates how the LPTIM drivers can be activated or deactivated in the kernel.

Activate the LPTIM Linux driver in the kernel configuration using the Linux Menuconfig tool: Menuconfig or how to configure kernel.

Enable the following configurations (as well as their dependencies):

  • CONFIG_MFD_STM32_LPTIMER
  • CONFIG_PWM_STM32_LP
  • CONFIG_IIO_STM32_LPTIMER_TRIGGER
  • CONFIG_STM32_LPTIMER_CNT
  • CONFIG_CLKSRC_STM32_LP
Device Drivers  --->
   -> Multifunction device drivers  --->
      <*> Support for STM32 Low-Power Timer
   -> Pulse-width modulation (PWM) support  --->
      <*> STMicroelectronics STM32 PWM LP
   -> Industrial I/O support  --->
      -> Triggers - standalone  --->
         <*> STM32 Low-Power Timer Trigger
   -> Counter support  --->
      <*> STM32 LP Timer encoder counter driver
   -> Clock Source drivers  --->
      <*> Low power clocksource for STM32 SoCs

3.3. Device tree[edit | edit source]

4. How to use[edit | edit source]

4.1. OP-TEE driver[edit | edit source]

Examples can be found (look for stm32_hse_monitoring) in:

4.2. Linux kernel driver[edit | edit source]

How to use PWM with sysfs interface

How to set up a TIM or LPTIM trigger using the sysfs interface

How to use the quadrature encoder with the sysfs interface

LPTIM clocksource driver can be used as the Linux scheduling-clock during the low power modes, see timer documentation for details.

5. How to trace and debug[edit | edit source]

5.1. In OP-TEE[edit | edit source]

Refer to How to debug OP-TEE for details about debug means in OP-TEE.

5.2. In Linux kernel[edit | edit source]

The LPTIM Linux driver can access LPTIM registers through REGMAP.

It comes with debugfs entries, which allow dumping registers:

cd /sys/kernel/debug/regmap
ls
40004000.timer  40009000.timer

cd 40009000.timer
cat registers
000: 00000003
004: 00000000
008: 00000000
...

It also comes with tracepoints using ftrace:

cd /sys/kernel/debug/tracing
cat available_events | grep regmap
...
regmap:regmap_reg_read
regmap:regmap_reg_write

6. Source code location[edit | edit source]

6.1. OP-TEE[edit | edit source]

This chapter is only applicable for STM32MP13x lines More info.png and STM32MP2 series.

The LPTIM source code is composed of:

6.2. Linux kernel[edit | edit source]

The LPTIM Linux driver is composed of:

7. References[edit | edit source]