Registered User No edit summary |
Registered User |
||
(25 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude>{{ApplicableFor | |||
|MPUs list=STM32MP13x, STM32MP15x, STM32MP25x | |||
|MPUs checklist=STM32MP13x,STM32MP15x, STM32MP25x | |||
}}</noinclude> | |||
== Article purpose == | == Article purpose == | ||
The purpose of this article is to explain how to configure the | The purpose of this article is to explain how to configure the [[LPTIM internal peripheral]] using the [[Device tree|device tree]] mechanism, relying on the bindings documentation, that is the description of the required and optional device-tree properties. | ||
* how | |||
When the peripheral is assigned to Linux<sup>®</sup> OS, it explains: | |||
* how to enable PWM, trigger, event counter and quadrature encoder | |||
* how to configure the '''board''', e.g. LPTIM input/output pins | * how to configure the '''board''', e.g. LPTIM input/output pins | ||
It | It can be used by the [[LPTIM Linux driver]] that registers relevant information in [[PWM overview|PWM]], [[IIO overview|IIO]] and <span style="color: {{STLightBlue}};">counter</span> frameworks, or by the {{CodeSource | OP-TEE_OS | core/drivers/counter/stm32_lptimer.c |OP-TEE LPTIM counter driver}}. | ||
The peripheral can be assigned to different contexts/software components, depending on the final product needs. Refer to [[How to assign an internal peripheral to an execution context]] for guidelines on this configuration. | |||
{{ReviewsComments|-- NathalieS , Fabrice G<br />Article to be updated to be compliant with ecosystem v2.1.0 (BZ 95795), some example on ''clock event'' must be added}} | |||
== DT bindings documentation == | == DT bindings documentation == | ||
The device tree binding documents are stored in the Linux kernel repository for: | |||
* OP-TEE and Linux<sup>®</sup> OS : {{CodeSource | Linux kernel | Documentation/devicetree/bindings/mfd/st,stm32-lptimer.yaml | Documentation/devicetree/bindings/mfd/st,stm32-lptimer.yaml}} | |||
The LPTIM<ref name="LPTIM internal peripheral"/> is a multifunction device (MFD) | The LPTIM<ref name="LPTIM internal peripheral"> [[LPTIM internal peripheral]]</ref> is a multifunction device (MFD), providing the following functions: | ||
* '' | * ''st,stm32-timers'' deals with core resources (e.g. registers, clock) | ||
* ''st,stm32-pwm'' deals with '''PWM''' interface resources (e.g. PWM pins) | |||
* '' | * ''st,stm32-timer-trigger'' deals with '''LPTIM triggers''' resources (e.g. trigger output connected to other STM32 internal peripherals) | ||
* ''st,stm32-timer-counter'' deals with '''LPTIM counter and quadrature encoder''' resources (e.g. counter/encoder IN[1..2] pins) | |||
* "st,stm32-timer-timer" deals with "clock events"<ref>{{CodeSource | Linux kernel | Documentation/timers/timekeeping.rst | Documentation/timers/timekeeping.rst}}</ref> for the kernel. | |||
== DT configuration == | == DT configuration == | ||
This hardware description is a combination of STM32 microprocessor and board device tree files. See [[Device tree]] for | This hardware description is a combination of the '''STM32 microprocessor''' device tree files (''.dtsi'' extension) and '''board''' device tree files (''.dts'' extension). See the [[Device tree]] for an explanation of the device-tree file organization. | ||
'''STM32CubeMX''' can be used to generate the board device tree. Refer to [[#How_to_configure_the_DT_using_STM32CubeMX|How to configure the DT using STM32CubeMX]] for more details. | |||
{{ | {{ | ||
ImageMap|Image:LPTIM DT configuration.png {{!}} thumb {{!}} 800px {{!}} center{{!}} LPTIM DT configuration | ImageMap|Image:LPTIM DT configuration.png {{!}} thumb {{!}} 800px {{!}} center{{!}} LPTIM DT configuration | ||
rect | rect 312 199 434 246 [[#LPTIM2_configured_as_counter_and_quadrature_encoder|LPTIM configured as event counter and quadrature encoder]] | ||
rect | rect 462 199 585 246 [[#LPTIM1_configured_as_PWM_and_trigger_source|LPTIM configured as PWM and trigger source]] | ||
rect | rect 613 199 735 246 [[#LPTIM1_configured_as_PWM_and_trigger_source|LPTIM configured as PWM and trigger source]] | ||
}} | }} | ||
=== DT configuration (STM32 level) === | === DT configuration (STM32 level) === | ||
'''DT root node''' (aka lptimer1, ..., lptimer5) and '''DT child nodes''' describe the [[LPTIM internal peripheral|LPTIM features]] such as: | |||
'''DT root node''' (aka lptimer1, ..., lptimer5) and '''DT child nodes''' describe the [[LPTIM internal peripheral | |||
* PWM | * PWM | ||
* trigger | * trigger | ||
Line 43: | Line 46: | ||
They also describe hardware parameters such as register addresses and clock. | They also describe hardware parameters such as register addresses and clock. | ||
====On {{MicroprocessorDevice | device=1}}==== | |||
LPTIM nodes are declared in stm32mp131.dtsi<ref name="stm32mp131_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp131.dtsi | STM32MP131 device tree file}}</ref> on {{MicroprocessorDevice | device=13}}. | |||
LPTIM nodes are declared in stm32mp151.dtsi<ref name="stm32mp151_dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi | STM32MP151 device tree file}}</ref> on {{MicroprocessorDevice | device=15}}. | |||
lptimer1: timer@40009000 { | lptimer1: timer@40009000 { | ||
compatible = "st,stm32-lptimer"; {{highlight|/* lptimer's common resources */}} | compatible = "st,stm32-lptimer"; {{highlight|/* lptimer's common resources */}} | ||
Line 57: | Line 65: | ||
}; | }; | ||
}; | }; | ||
{{Warning|This device tree part is related to STM32 microprocessors. It | {{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}} | ||
====On {{MicroprocessorDevice | device=2}}==== | |||
LPTIM nodes are declared in stm32mp251.dtsi<ref name="stm32mp251_dtsi">{{CodeSource | Linux kernel | arch/arm64/boot/dts/st/stm32mp251.dtsi | STM32MP251 device tree file}}</ref> on {{MicroprocessorDevice | device=25}}. | |||
lptimer1: timer@40090000 { | |||
compatible = "st,stm32mp25-lptimer"; {{highlight|/* lptimer's common resources */}} | |||
... | |||
counter { | |||
compatible = "st,stm32mp25-lptimer-counter"; {{highlight|/* quadrature encoder & event counter part of LPTIM */}} | |||
}; | |||
pwm { | |||
compatible = "st,stm32mp25-pwm-lp"; {{highlight|/* PWM part of LPTIM */}} | |||
}; | |||
timer { | |||
compatible = "st,stm32mp25-lptimer-timer"; {{highlight|/* clkevent part of LPTIM */}} | |||
}; | |||
trigger@'''0''' { | |||
compatible = "st,stm32mp25-lptimer-trigger"; {{highlight|/* trigger part of LPTIM */}} | |||
reg = <'''0'''>; {{highlight|/* trigger identifier (e.g. 0 for LPTIM1 trigger, 1 for LPTIM2... */}} | |||
}; | |||
}; | |||
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}} | |||
=== DT configuration (board level) === | === DT configuration (board level) === | ||
The objective of this chapter is to explain how to enable and configure the LPTIM DT nodes for a board: | |||
* Enable '''DT root node''' for the LPTIM instance in use (e.g lptimer1, ..., lptimer5), with '''status = "okay";''' | * Enable '''DT root node''' for the LPTIM instance in use (e.g lptimer1, ..., lptimer5), with '''status = "okay";''' | ||
* Enable '''DT child node(s)''' for the feature(s) in use (PWM output, trigger, event counter and quadrature encoder), with '''status = "okay";''' | * Enable '''DT child node(s)''' for the feature(s) in use (PWM output, trigger, event counter and quadrature encoder), with '''status = "okay";''' | ||
* Configure the pins in use via [[Pinctrl overview|pinctrl]], with '''pinctrl-0''', '''pinctrl-1''' and '''pinctrl-names'''. | * Configure the pins in use via [[Pinctrl overview|pinctrl]], with '''pinctrl-0''', '''pinctrl-1''' and '''pinctrl-names'''. | ||
Peripheral configuration should be done in specific board device tree files (board dts file and [[Pinctrl device tree configuration|pinctrl dtsi file]]). | |||
=== DT configuration examples === | === DT configuration examples === | ||
==== LPTIM1 configured as PWM and trigger source ==== | ==== LPTIM1 configured as PWM and trigger source ==== | ||
Line 127: | Line 156: | ||
==How to configure the DT using STM32CubeMX== | ==How to configure the DT using STM32CubeMX== | ||
The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree# | The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree#STM32_MPU|platform configuration device tree]] files.<br /> | ||
STM32CubeMX may not support all the properties described in DT binding files listed in the above [[#DT bindings documentation|DT bindings documentation]] paragraph. If so, the tool inserts '''user sections''' in the generated device tree. These sections can then be edited to add some properties, and they are preserved from one generation to another. Refer to [[STM32CubeMX]] user manual for further information. | |||
==References== | ==References== | ||
Refer to the following links for additional information: | |||
<references /> | <references /> | ||
Line 140: | Line 169: | ||
{{PublicationRequestId | 8438 | 2018-08-02 | AnneJ}} | {{PublicationRequestId | 8438 | 2018-08-02 | AnneJ}} | ||
{{ArticleBasedOnModel | Peripheral or framework device tree configuration model}} | {{ArticleBasedOnModel | Peripheral or framework device tree configuration model}} | ||
</noinclude> | </noinclude> |
Latest revision as of 11:51, 22 November 2023
1. Article purpose[edit | edit source]
The purpose of this article is to explain how to configure the LPTIM internal peripheral using the device tree mechanism, relying on the bindings documentation, that is the description of the required and optional device-tree properties.
When the peripheral is assigned to Linux® OS, it explains:
- how to enable PWM, trigger, event counter and quadrature encoder
- how to configure the board, e.g. LPTIM input/output pins
It can be used by the LPTIM Linux driver that registers relevant information in PWM, IIO and counter frameworks, or by the OP-TEE LPTIM counter driver .
The peripheral can be assigned to different contexts/software components, depending on the final product needs. Refer to How to assign an internal peripheral to an execution context for guidelines on this configuration.
2. DT bindings documentation[edit | edit source]
The device tree binding documents are stored in the Linux kernel repository for:
- OP-TEE and Linux® OS : Documentation/devicetree/bindings/mfd/st,stm32-lptimer.yaml
The LPTIM[1] is a multifunction device (MFD), providing the following functions:
- st,stm32-timers deals with core resources (e.g. registers, clock)
- st,stm32-pwm deals with PWM interface resources (e.g. PWM pins)
- st,stm32-timer-trigger deals with LPTIM triggers resources (e.g. trigger output connected to other STM32 internal peripherals)
- st,stm32-timer-counter deals with LPTIM counter and quadrature encoder resources (e.g. counter/encoder IN[1..2] pins)
- "st,stm32-timer-timer" deals with "clock events"[2] for the kernel.
3. DT configuration[edit | edit source]
This hardware description is a combination of the STM32 microprocessor device tree files (.dtsi extension) and board device tree files (.dts extension). See the Device tree for an explanation of the device-tree file organization.
STM32CubeMX can be used to generate the board device tree. Refer to How to configure the DT using STM32CubeMX for more details.
3.1. DT configuration (STM32 level)[edit | edit source]
DT root node (aka lptimer1, ..., lptimer5) and DT child nodes describe the LPTIM features such as:
- PWM
- trigger
- event counter and quadrature encoder.
They also describe hardware parameters such as register addresses and clock.
3.1.1. On STM32MP1 series[edit | edit source]
LPTIM nodes are declared in stm32mp131.dtsi[3] on STM32MP13x lines .
LPTIM nodes are declared in stm32mp151.dtsi[4] on STM32MP15x lines .
/* lptimer's common resources */ ... pwm { compatible = "st,stm32-pwm-lp"; /* PWM part of LPTIM */ }; trigger@0 { compatible = "st,stm32-lptimer-trigger"; /* trigger part of LPTIM */ reg = <0>; /* trigger identifier (e.g. 0 for LPTIM1 trigger, 1 for LPTIM2... */ }; counter { compatible = "st,stm32-lptimer-counter"; /* quadrature encoder & event counter part of LPTIM */ }; };lptimer1: timer@40009000 { compatible = "st,stm32-lptimer";
3.1.2. On STM32MP2 series[edit | edit source]
LPTIM nodes are declared in stm32mp251.dtsi[5] on STM32MP25x lines .
/* lptimer's common resources */ ... counter { compatible = "st,stm32mp25-lptimer-counter"; /* quadrature encoder & event counter part of LPTIM */ }; pwm { compatible = "st,stm32mp25-pwm-lp"; /* PWM part of LPTIM */ }; timer { compatible = "st,stm32mp25-lptimer-timer"; /* clkevent part of LPTIM */ }; trigger@0 { compatible = "st,stm32mp25-lptimer-trigger"; /* trigger part of LPTIM */ reg = <0>; /* trigger identifier (e.g. 0 for LPTIM1 trigger, 1 for LPTIM2... */ }; };lptimer1: timer@40090000 { compatible = "st,stm32mp25-lptimer";
3.2. DT configuration (board level)[edit | edit source]
The objective of this chapter is to explain how to enable and configure the LPTIM DT nodes for a board:
- Enable DT root node for the LPTIM instance in use (e.g lptimer1, ..., lptimer5), with status = "okay";
- Enable DT child node(s) for the feature(s) in use (PWM output, trigger, event counter and quadrature encoder), with status = "okay";
- Configure the pins in use via pinctrl, with pinctrl-0, pinctrl-1 and pinctrl-names.
Peripheral configuration should be done in specific board device tree files (board dts file and pinctrl dtsi file).
3.3. DT configuration examples[edit | edit source]
3.3.1. LPTIM1 configured as PWM and trigger source[edit | edit source]
The example below shows how to configure LPTIM1 to act as:
- PWM output on PG13 (See pinctrl device tree configuration and GPIO internal peripheral)
- trigger source (in Synchronous mode with PWM) for other internal peripherals such as ADC[6], DAC[7], and DFSDM[8]
/* configure 'PG13' as alternate 1 for LPTIM1_OUT mode of operation */ bias-pull-down; drive-push-pull; slew-rate = <0>; }; }; lppwm1_sleep_pins_a: lppwm1-sleep-0 { pins { pinmux = <STM32_PINMUX('G', 13, ANALOG)>; /* configure 'PG13' as analog for low power mode */ }; };lppwm1_pins_a: lppwm1-0 { pins { pinmux = <STM32_PINMUX('G', 13, AF1)>;
okay"; pwm { pinctrl-0 = <&lppwm1_pins_a>; /* configure PWM on LPTIM1_OUT */ pinctrl-1 = <&lppwm1_sleep_pins_a>; pinctrl-names = "default", "sleep"; status = "okay"; /* enable PWM on LPTIM1 */ }; trigger@0 { status = "okay"; /* enable LPTIM1_OUT trigger source */ }; };&lptimer1 { status = "
3.3.2. LPTIM2 configured as counter and quadrature encoder[edit | edit source]
The example below shows how to configure LPTIM2 to act as counter and/or quadrature encoder, with LPTIM2_IN1 and LPTIM2_IN2 pins configured as inputs on PD12 and PD11, respectively (See pinctrl device tree configuration and GPIO internal peripheral)
# part of pin-controller dt node
lptim2_in_pins_a: lptim2-in-pins-0 {
pins {
pinmux = <STM32_PINMUX('D', 12, AF3)>, /* LPTIM2_IN1 */
<STM32_PINMUX('D', 11, AF3)>; /* LPTIM2_IN2 */
bias-disabled;
};
};
lptim2_sleep_in_pins_a: lptim2-sleep-in-pins-0 {
pins {
pinmux = <STM32_PINMUX('D', 12, ANALOG)>, /* LPTIM2_IN1 */
<STM32_PINMUX('D', 11, ANALOG)>; /* LPTIM2_IN2 */
};
};
okay"; counter { pinctrl-0 = <&lptim2_in_pins_a>; /* configure LPTIM2 counter/encoder pins */ pinctrl-1 = <&lptim2_sleep_in_pins_a>; pinctrl-names = "default", "sleep"; status = "okay"; /* enable counter/encoder on LPTIM2 */ }; };&lptimer2 { status = "
4. How to configure the DT using STM32CubeMX[edit | edit source]
The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
STM32CubeMX may not support all the properties described in DT binding files listed in the above DT bindings documentation paragraph. If so, the tool inserts user sections in the generated device tree. These sections can then be edited to add some properties, and they are preserved from one generation to another. Refer to STM32CubeMX user manual for further information.
5. References[edit | edit source]
Refer to the following links for additional information: