LPTIM Linux driver

来自百问网嵌入式Linux wiki

Article purpose

This article introduces the LPTIM Linux® driver for the LPTIM internal peripheral[1]:

  • Which LPTIM features are supported by the driver
  • How to configure, use and debug the driver
  • What is the driver structure, and where the source code can be found.

Short description

The LPTIM[1] Linux driver (kernel space) is based on the PWM and IIO 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[2], DAC[3], DFSDM[4]

IIO counter driver:

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

Configuration

Kernel configuration

Activate the LPTIM[1] 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
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
      -> Counters  --->
         <*> STM32 low-power timer encoder counter driver

Device tree

Refer to the LPTIM device tree configuration article when configuring the LPTIM Linux kernel driver.

How to trace and debug

The LPTIM Linux driver can access LPTIM registers through REGMAP.

It comes with debugfs[6] 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[7]:

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

References

<securetransclude src="ProtectedTemplate:PublicationRequestId" params="9230 | 2018-10-16 | AnneJ"></securetransclude> <securetransclude src="ProtectedTemplate:ArticleBasedOnModel" params="Linux driver article model"></securetransclude>