TIM Linux driver

来自百问网嵌入式Linux wiki
Zhouyuebiao讨论 | 贡献2020年5月6日 (三) 23:28的版本 (创建页面,内容为“== Article purpose == This article introduces the TIM Linux<sup>®</sup> driver for the TIM internal peripheral<ref name="TIM internal peripheral">TIM internal…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

Article purpose

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

  • Which TIM 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 TIM[1] Linux driver (kernel space) is based on the PWM and IIO frameworks. It provides several functionalities:

MFD driver:

  • handles registers, clock and DMA[2] resources
  • detects the TIM counter resolution, e.g. 16 or 32 bits.

PWM driver:

  • detects the number of TIM channels.
  • handles PWM output channels.
  • handles PWM capture channels (input). Note that the PWM capture relies on DMA, which is handled by the MFD core.

IIO driver:

  • handles hardware trigger sources (synchronously with PWM) for other internal peripherals such as ADC[3], DAC[4], DFSDM[5].
  • handles the quadrature encoder interface[6].

Configuration

Kernel configuration

Activate the TIM[1] Linux driver in the kernel configuration using the Linux Menuconfig tool: Menuconfig or how to configure kernel.

Enable the following configurations (and their dependencies):

  • CONFIG_MFD_STM32_TIMERS
  • CONFIG_PWM_STM32
  • CONFIG_IIO_STM32_TIMER_TRIGGER
Device Drivers  --->
  -> Multifunction device drivers  --->
     <*> Support for STM32 Timers
  -> Pulse-width modulation (PWM) support  --->
     <*> STMicroelectronics STM32 PWM
  -> Industrial I/O support  --->
     -> Triggers - standalone  --->
        <*> STM32 timer trigger

Device tree

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

How to trace and debug

The TIM[1] Linux driver can access the timer registers through REGMAP.

It comes with debugfs[7] entries, which allow dumping registers:

$ cd /sys/kernel/debug/regmap
$ ls
40004000.timer  44000000.timer

$ cd 44000000.timer
$ cat registers
000: 00000081
004: 00000000
008: 00000000
00c: 00000000
...

It also comes with tracepoints[8]:

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

Source code location

The TIM Linux driver source code is composed of:

References

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