- Last edited 6 months ago ago
TIM Linux driver
1 Article purpose
This article introduces the TIM Linux® driver for the TIM internal peripheral:
- 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.
2 Short description
- handles registers, clock and DMA resources
- detects the TIM counter resolution, e.g. 16 or 32 bits.
- 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.
- handles hardware trigger sources (synchronously with PWM) for other internal peripherals such as ADC, DAC, DFSDM.
- handles the quadrature encoder interface.
3.1 Kernel configuration
Enable the following configurations (and their dependencies):
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 -> Counter support ---> <*> STM32 Timer encoder counter driver
3.2 Device tree
Refer to the TIM device tree configuration article when configuring the TIM Linux kernel driver.
4 How to use
5 How to trace and debug
The TIM Linux driver can access the timer registers through REGMAP.
It comes with debugfs 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:
$ cd /sys/kernel/debug/tracing $ cat available_events | grep regmap ... regmap:regmap_reg_read regmap:regmap_reg_write
6 Source code location
The TIM Linux driver source code is composed of:
- stm32-timers.c MFD driver to handle common resources: registers, clock, dmas.
- pwm-stm32.c PWM driver to handle PWM channel(s).
- stm32-timer-trigger.c IIO driver to handle trigger source for other internal peripherals.
- stm32-timer-cnt.c counter driver to handle the quadrature encoder interface.
- include/linux/mfd/stm32-timers.h and include/linux/iio/timer/stm32-timer-trigger.h header files