“TIM device tree configuration”的版本间的差异

来自百问网嵌入式Linux wiki
(创建页面,内容为“== Article purpose == The purpose of this article is to explain how to configure the ''timer (TIM)''<ref name="TIM internal peripheral"> TIM internal peripheral…”)
 
 
(未显示同一用户的8个中间版本)
第1行: 第1行:
 
==  Article purpose ==
 
==  Article purpose ==
The purpose of this article is to explain how to configure the ''timer (TIM)''<ref name="TIM internal peripheral"> [[TIM internal peripheral]]</ref> ''' when the peripheral is assigned to Linux<sup>&reg;</sup> OS''':
+
本文的目的是解释'''在将外围设备分配给 Linux<sup>&reg;</sup> OS'',如何配置“Timer(Tim)<ref name="TIM internal peripheral"> [[TIM internal peripheral]]</ref> ':
  
* Configuring the timer '''peripheral''' to enable PWM, trigger or quadrature encoder.
+
* 配置定时器'''peripheral'''以启用PWM,触发或正交编码器。
* Configuring the '''board''', e.g. TIM pins.
+
* 配置'''board''',例如 TIM引脚。
  
The configuration is performed using the '''device tree mechanism'''<ref> [[Device tree]]</ref>.
+
使用'''设备树机制'''<ref> [[Device tree]]</ref>执行配置。
  
It is used by the [[TIM Linux driver]] that registers relevant information in [[PWM overview|PWM]] and [[IIO overview|IIO]] frameworks.
+
[[TIM Linux driver]] 使用它在[[PWM overview|PWM]] [[IIO overview|IIO]] 框架中注册相关信息。
  
If the peripheral is assigned to another execution context, refer to [[How to assign an internal peripheral to a runtime context]] article for guidelines on peripheral assignment and configuration.
+
如果外围设备已分配给另一个执行上下文,请参阅 [[How to assign an internal peripheral to a runtime context]] 文章,以获取有关外围设备分配和配置的准则。
  
 
== DT bindings documentation ==
 
== DT bindings documentation ==
The ''TIM internal peripheral''<ref name="TIM internal peripheral"/> is a multifunction device (MFD).
+
“ TIM内部外围设备”<ref name="TIM internal peripheral"/> 是多功能设备(MFD)。
  
Each function is represented by a separate DT binding document:
+
每个功能由单独的DT绑定文档表示:
* ''STM32 TIM MFD device tree bindings''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/mfd/stm32-timers.txt | Documentation/devicetree/bindings/mfd/stm32-timers.txt}}, STM32 TIM MFD device tree bindings</ref> document deals with core resources (e.g. registers, clock, DMAs)
+
* ''STM32 TIM MFD设备树绑定''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/mfd/stm32-timers.txt | Documentation/devicetree/bindings/mfd/stm32-timers.txt}}, STM32 TIM MFD device tree bindings</ref> 文档涉及核心资源(例如寄存器,时钟,DMA)
  
* ''STM32 TIM PWM device tree bindings''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pwm/pwm-stm32.txt | Documentation/devicetree/bindings/pwm/pwm-stm32.txt}}, STM32 TIM PWM device tree bindings</ref> document deals with PWM resources (e.g. PWM input/output pins)
+
* ''STM32 TIM PWM设备树绑定''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/pwm/pwm-stm32.txt | Documentation/devicetree/bindings/pwm/pwm-stm32.txt}}, STM32 TIM PWM device tree bindings</ref> 文档涉及PWM资源(例如PWM输入/输出引脚)
 
+
* ''STM32 TIM IIO触发器/编码器设备树绑定''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt | Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt}}, STM32 TIM trigger/encoder device tree bindings</ref>文档涉及其他内部外设触发和正交编码器资源
* ''STM32 TIM IIO trigger/encoder device tree bindings''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt | Documentation/devicetree/bindings/iio/timer/stm32-timer-trigger.txt}}, STM32 TIM trigger/encoder device tree bindings</ref> document deals with other internal peripheral triggering and quadrature encoder resources
 
  
 
== DT configuration ==
 
== DT configuration ==
This hardware description is a combination of both STM32 microprocessor and board device tree files. Refer to [[Device tree]] for more explanations about device tree file split.
+
该硬件描述是STM32微处理器和电路板设备树文件的组合。 有关设备树文件分割的更多说明,请参见[[Device tree]].
 
+
'''STM32CubeMX'''可用于生成板卡设备树。 请参阅[[#How_to_configure_the_DT_using
The '''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.
+
_STM32CubeMX|How to configure the DT using STM32CubeMX]].
  
 
=== DT configuration (STM32 level) ===
 
=== DT configuration (STM32 level) ===
TIM nodes are declared in stm32mp157c.dtsi<ref name="stm32mp157c.dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi | stm32mp157c.dtsi}}, STM32.dtsi file</ref>.
+
TIM节点在stm32mp157c.dtsi <ref name="stm32mp157c.dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi | stm32mp157c.dtsi}}, STM32.dtsi file</ref>.
  
'''DT root node''' (e.g. timers1...) and '''DT child nodes''' describe the [[TIM internal peripheral#Features|TIM features]] such as:
+
''DT根节点''(例如timers1 ...)和'''DT子节点'''描述了[[TIM internal peripheral#Features|TIM features]] ,例如:
* PWM
+
* 触发和正交编码器
* trigger and quadrature encoder
 
  
They also describe hardware parameters such as registers address, clock and DMA.
+
它们还描述了硬件参数,例如寄存器地址,时钟和DMA。
 
  timers1: timer@address {
 
  timers1: timer@address {
 
  {{highlight|/* timer common resources */}}
 
  {{highlight|/* timer common resources */}}
第49行: 第47行:
 
  };
 
  };
 
  };
 
  };
{{Warning|This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.}}
+
{{Warning|该设备树部分与STM32微处理器有关。 它必须保持原样,而不能由最终用户修改。}}
  
 
=== DT configuration (board level) ===
 
=== DT configuration (board level) ===
This part is used to configure and enable the TIM hardware used on the board:
+
该部分用于配置和启用板上使用的TIM硬件
* Enabling '''DT root node''' for the TIM instances in use (e.g timers1...) by setting '''{{highlight|<nowiki>status = "okay";</nowiki>}}'''
+
* 通过设置为正在使用的TIM实例(例如timers1 ...)启用'''DT根节点''''''{{highlight|<nowiki>status = "okay";</nowiki>}}'''
* Enabling '''DT child node(s)''' for the feature(s) in use (PWM input/output, trigger and quadrature encoder) by setting '''{{highlight|<nowiki>status = "okay";</nowiki>}}'''
+
* 通过设置 '''{{highlight|<nowiki>status = "okay"'''为使用中的功能(PWM输入/输出,触发和正交编码器)启用'''DT子节点'''。;</nowiki>}}
* Configuring pins in use via [[Pinctrl overview|pinctrl]] through '''{{highlight|pinctrl-0}}''', '''{{highlight|pinctrl-1}}''' and '''{{highlight|pinctrl-names}}'''.
+
* 通过[[Pinctrl overview|pinctrl]] '''{{highlight|pinctrl-0}}''', '''{{highlight|pinctrl-1}}''' '''{{highlight|pinctrl-names}}'''.
To enable PWM capture on the board (optional), DMA must be configured:
+
要在板上启用PWM捕获(可选),必须配置DMA:
* Enable DMA channel(s) corresponding to the PWM input(s) by setting '''{{highlight|<nowiki>dmas = <...>, <...>;</nowiki>}}''' and matching '''{{highlight|<nowiki>dma-names = "ch1", "ch3";</nowiki>}}'''.
+
* 通过设置'''{{highlight|<nowiki>dmas = <...>, <...>;</nowiki>}}''' 启用与PWM输入对应的DMA通道 匹配 '''{{highlight|<nowiki>dma-names = "ch1", "ch3";</nowiki>}}'''.
When PWM capture isn't used, it's recommended to disable DMA channels by default, to spare them for other usage:
+
不使用PWM捕获时,建议默认情况下禁用DMA通道,以将其备用以用于其他用途:
* Disable DMA channels by setting '''{{highlight|/delete-property/dmas}}''' and '''{{highlight|/delete-property/dma-names}}'''
+
* 通过设置'''{{highlight|/delete-property/dmas}}''' '''{{highlight|/delete-property/dma-names}}'''来禁用DMA通道
 +
 
 
=== DT configuration examples ===
 
=== DT configuration examples ===
 
==== TIM configured in PWM mode====
 
==== TIM configured in PWM mode====
The example below shows how to configure '''TIM1 channel 1''' to act as:
+
下面的示例显示了如何配置'''TIM1通道1'''作为:
* '''PWM output on PE9''', e.g. TIM1_CH1 ([[Pinctrl_device_tree_configuration|See pinctrl device tree configuration]] and [[GPIO internal peripheral]])
+
* '''PE9上的PWM输出''',例如 TIM1_CH1([[Pinctrl_device_tree_configuration|See pinctrl device tree configuration]] and [[GPIO internal peripheral]])
* PWM device tree provider (e.g. TIM1_CH1) used by a device tree consumer (e.g. like "pwm-leds"<ref name="pwm-leds">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/leds/leds-pwm.txt}}, PWM LEDs device tree bindings</ref>). This is available since {{EcosystemRelease | revision=1.1.0 | range=and after}}  
+
* 设备树使用者(例如“ pwm-leds”<ref name="pwm-leds">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/leds/leds-pwm.txt}}, PWM LEDs device tree bindings</ref>).这是从 {{EcosystemRelease | revision=1.1.0 | range=and after}} 开始提供的
  
 
  {{highlight|/* select TIM1_CH1 alternate function 1 on 'PE9' */}}
 
  {{highlight|/* select TIM1_CH1 alternate function 1 on 'PE9' */}}
第82行: 第81行:
 
  };
 
  };
 
  };
 
  };
{{Info|The PWM output doesn't require any DMA channel. Disable them if they are configured by default in the .dtsi file.}}
+
{{Info|PWM输出不需要任何DMA通道。 如果它们在.dtsi文件中默认配置,请禁用它们。}}
 
  {{highlight|/* PWM DT provider on TIM1: "pwm1" */}}
 
  {{highlight|/* PWM DT provider on TIM1: "pwm1" */}}
 
  &timers1 {
 
  &timers1 {
第100行: 第99行:
 
  };
 
  };
  
PWM DT user example below is available since  {{EcosystemRelease | revision=1.1.0 | range=and after}}
+
以下的PWM DT用户示例来自{{EcosystemRelease | revision=1.1.0 | range=and after}}
{{Info| The TIM PWM DT user specifier encodes 3 cells:
+
{{Info| TIM PWM DT用户说明符编码3个单元:
 
* PWM '''number''' (0 for CH1, 1 for CH2 and so on)
 
* PWM '''number''' (0 for CH1, 1 for CH2 and so on)
 
* PWM '''period''' in nanoseconds
 
* PWM '''period''' in nanoseconds
第199行: 第198行:
 
{{Info|DMA channels 1 and/or 3 for each TIM can be picked from the '''"dmas"''' list in stm32mp157c.dtsi<ref name="stm32mp157c.dtsi"/> file}}
 
{{Info|DMA channels 1 and/or 3 for each TIM can be picked from the '''"dmas"''' list in stm32mp157c.dtsi<ref name="stm32mp157c.dtsi"/> file}}
 
==== TIM configured as quadrature encoder interface ====
 
==== TIM configured as quadrature encoder interface ====
The example below shows how to configure '''TIM1''' to interface with a quadrature encoder:
+
下面的示例显示了如何配置'''TIM1'''以与正交编码器接口:
* '''Configure PE9 and PJ11 as encoder input pins''', e.g. TIM1_CH1, TIM1_CH2 ([[Pinctrl_device_tree_configuration|see pinctrl device tree configuration]] and [[GPIO internal peripheral]])
+
* '''将PE9和PJ11配置为编码器输入引脚''',例如 TIM1_CH1,TIM1_CH2([[Pinctrl_device_tree_configuration|see pinctrl device tree configuration]] and [[GPIO internal peripheral]])
  
 
  tim1_in_pins_a: tim1-in-pins-0 {
 
  tim1_in_pins_a: tim1-in-pins-0 {
第230行: 第229行:
  
 
==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#STM32|platform configuration device tree]] files.<br />
+
[[STM32CubeMX]] 工具可用于配置STM32MPU设备并获取相应的[[Device_tree#STM32|platform configuration device tree]] 文件<br />
The STM32CubeMX may not support all the properties described 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.
+
STM32CubeMX可能不支持以上[[#DT bindings documentation|DT bindings documentation]] 段中描述的所有属性。 如果是这样,该工具会在生成的设备树中插入“''用户部分”''。 然后可以编辑这些部分以添加一些属性,并将它们一代一代地保留下来。 有关更多信息,请参见[[STM32CubeMX]] 用户手册。
  
 
==References==
 
==References==
Please refer to the following links for additional information:
+
请参考以下链接以获取更多信息:
 
<references />
 
<references />
 
<noinclude>
 
[[Category:Device tree configuration]]
 
[[Category:IIO]]
 
[[Category:Timers]]
 
{{PublicationRequestId | 8783 | 2018-09-20 | AnneJ}}
 
{{ArticleBasedOnModel|Peripheral_or_framework_device_tree_configuration_model}}
 
{{ReviewsComments|JCT 1840: alignment needed with the last version of the model<br>
 
[[Category:ToBeAlignedWithModel]]
 
}}
 
</noinclude>
 

2020年11月10日 (二) 10:24的最新版本

Article purpose

本文的目的是解释'在将外围设备分配给 Linux® OS,如何配置“Timer(Tim)”[1] ':

  • 配置定时器peripheral以启用PWM,触发或正交编码器。
  • 配置board,例如 TIM引脚。

使用设备树机制[2]执行配置。

TIM Linux driver 使用它在PWMIIO 框架中注册相关信息。

如果外围设备已分配给另一个执行上下文,请参阅 How to assign an internal peripheral to a runtime context 文章,以获取有关外围设备分配和配置的准则。

DT bindings documentation

“ TIM内部外围设备”[1] 是多功能设备(MFD)。

每个功能由单独的DT绑定文档表示:

  • STM32 TIM MFD设备树绑定[3] 文档涉及核心资源(例如寄存器,时钟,DMA)
  • STM32 TIM PWM设备树绑定[4] 文档涉及PWM资源(例如PWM输入/输出引脚)
  • STM32 TIM IIO触发器/编码器设备树绑定[5]文档涉及其他内部外设触发和正交编码器资源

DT configuration

该硬件描述是STM32微处理器和电路板设备树文件的组合。 有关设备树文件分割的更多说明,请参见Device tree. STM32CubeMX可用于生成板卡设备树。 请参阅[[#How_to_configure_the_DT_using _STM32CubeMX|How to configure the DT using STM32CubeMX]].

DT configuration (STM32 level)

TIM节点在stm32mp157c.dtsi [6].

DT根节点(例如timers1 ...)和DT子节点描述了TIM features ,例如:

  • 触发和正交编码器

它们还描述了硬件参数,例如寄存器地址,时钟和DMA。

timers1: timer@address {
	/* timer common resources */
	compatible = "st,stm32-timers";
	...
	pwm {
		/* PWM*/
		compatible = "st,stm32-pwm";
	};
	timer@0 {
		/* trigger and quadrature encoder */
		compatible = "st,stm32h7-timer-trigger";
		/* trigger identifier (e.g. 0 for TIM1 triggers, 1 for TIM2... */
		reg = <0>;
	};
};
Warning.png 该设备树部分与STM32微处理器有关。 它必须保持原样,而不能由最终用户修改。

DT configuration (board level)

该部分用于配置和启用板上使用的TIM硬件

  • 通过设置为正在使用的TIM实例(例如timers1 ...)启用'DT根节点'status = "okay";
  • 通过设置 status = "okay"'''为使用中的功能(PWM输入/输出,触发和正交编码器)启用'''DT子节点'''。;
  • 通过pinctrlpinctrl-0, pinctrl-1pinctrl-names.

要在板上启用PWM捕获(可选),必须配置DMA:

  • 通过设置dmas = <...>, <...>; 启用与PWM输入对应的DMA通道 匹配 dma-names = "ch1", "ch3";.

不使用PWM捕获时,建议默认情况下禁用DMA通道,以将其备用以用于其他用途:

  • 通过设置/delete-property/dmas/delete-property/dma-names来禁用DMA通道

DT configuration examples

TIM configured in PWM mode

下面的示例显示了如何配置TIM1通道1作为:

/* select TIM1_CH1 alternate function 1 on 'PE9' */
pwm1_pins_a: pwm1-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, AF1)>;
		bias-pull-down;
		drive-push-pull;
		slew-rate = <0>;
	};
};

/* configure 'PE9' as analog input in low-power mode */
pwm1_sleep_pins_a: pwm1-sleep-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, ANALOG)>;
	};
};
Info.png PWM输出不需要任何DMA通道。 如果它们在.dtsi文件中默认配置,请禁用它们。
/* PWM DT provider on TIM1: "pwm1" */
&timers1 {
	status = "okay";
	/* spare all DMA channels since they are not needed for PWM output */
	/delete-property/dmas;
	/delete-property/dma-names;
	/* define pwm1 label */
	pwm1: pwm {
		/* configure PWM pins on TIM1_CH1 */
		pinctrl-0 = <&pwm1_pins_a>;
		pinctrl-1 = <&pwm1_sleep_pins_a>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";
	};
};

以下的PWM DT用户示例来自ecosystem release ≥ v1.1.0{{#set:Ecosystem release=revision of a previous flow 1.1.0}}

Info.png TIM PWM DT用户说明符编码3个单元:
  • PWM number (0 for CH1, 1 for CH2 and so on)
  • PWM period in nanoseconds
  • PWM polarity (0 for normal polarity or PWM_POLARITY_INVERTED)
/ {
	...
	/* PWM DT user on TIM1_CH1: "pwm1", example with "pwm-leds"[7] */
	pwmleds {
		compatible = "pwm-leds";
		example {
			label = "stm32-pwm-leds-example";
			/* Use pwm1 channel 0 (e.g. TIM1_CH1) */
			/* period in nanoseconds (500000), normal polarity (0) */
			pwms = <&pwm1 0 500000 0>;
			max-brightness = <127>;
		};
	};
};

TIM configured in PWM mode and trigger source

The example below shows how to configure TIM1 channel 1 to act as:

/* select TIM1_CH1 alternate function 1 on 'PE9' */
pwm1_pins_a: pwm1-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, AF1)>;
		bias-pull-down;
		drive-push-pull;
		slew-rate = <0>;
	};
};

/* configure 'PE9' as analog input in low-power mode */
pwm1_sleep_pins_a: pwm1-sleep-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, ANALOG)>;
	};
};
Info.png The PWM output doesn't require any DMA channel. Disable them if they are configured by default in the .dtsi file.
&timers1 {
	status = "okay";
	/* spare all DMA channels since they are not needed for PWM output */
	/delete-property/dmas;
	/delete-property/dma-names;
	pwm {
		/* configure PWM on TIM1_CH1 */
		pinctrl-0 = <&pwm1_pins_a>;          
		pinctrl-1 = <&pwm1_sleep_pins_a>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";
	};
	timer@0 {
		/* enable trigger on TIM1 */
		status = "okay";
	};
};

TIM configured in PWM input capture mode

The example below shows how to configure TIM1 channel 1 in PWM input capture mode (e.g. period and duty cycle):

/* select TIM1_CH1 alternate function 1 on 'PE9' */
pwm1_in_pins_a: pwm1-in-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, AF1)>;
		bias-disable;
	};
};

/* configure 'PE9' as analog input in low-power mode */
pwm1_in_sleep_pins_a: pwm1-in-sleep-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, ANALOG)>;
	};
};

A DMA channel is required and must be configured depending on the PWM input channel:

  • Select DMA channel 1, "ch1", to capture PWM input channel 1 and/or 2
  • Select DMA channel 3, "ch3", to capture PWM input channel 3 and/or 4
  • Select both "ch1" and "ch3" dmas to enable capture on all PWM input channels
&timers1 {
	status = "okay";
	/* Enable DMA "ch1" for PWM input on TIM1_CH1 */
	dmas = <&dmamux1 11 0x400 0x5>;
	dma-names = "ch1";
	pwm {
		/* configure PWM input pins, e.g. TIM1_CH1 */
		pinctrl-0 = <&pwm1_in_pins_a>;
		pinctrl-1 = <&pwm1_in_sleep_pins_a>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";
	};
};
Info.png DMA channels 1 and/or 3 for each TIM can be picked from the "dmas" list in stm32mp157c.dtsi[6] file

TIM configured as quadrature encoder interface

下面的示例显示了如何配置TIM1以与正交编码器接口:

tim1_in_pins_a: tim1-in-pins-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, AF1)>, /* TIM1_CH1 */
			 <STM32_PINMUX('J', 11, AF1)>; /* TIM1_CH2 */
		bias-disable;
	};
};

tim1_in_pins_sleep_a: tim1-in-pins-sleep-0 {
	pins {
		pinmux = <STM32_PINMUX('E', 9, ANALOG)>, /* TIM1_CH1 */
			 <STM32_PINMUX('J', 11, ANALOG)>; /* TIM1_CH2 */
	};
};
&timers1 {
	status = "okay";
	/delete-property/dmas;                       /* spare all DMA channels since they are not required for quadrature encoder interface */
	/delete-property/dma-names;
	timer@0 {
		pinctrl-0 = <&tim1_in_pins_a>;       /* configure TIM1_CH1 and TIM1_CH2 as encoder input pins */
		pinctrl-1 = <&tim1_in_pins_sleep_a>;
		pinctrl-names = "default", "sleep";
		status = "okay";                     /* enable Encoder interface mode on TIM1 */
	};
};

How to configure the DT using STM32CubeMX

STM32CubeMX 工具可用于配置STM32MPU设备并获取相应的platform configuration device tree 文件
STM32CubeMX可能不支持以上DT bindings documentation 段中描述的所有属性。 如果是这样,该工具会在生成的设备树中插入“用户部分”。 然后可以编辑这些部分以添加一些属性,并将它们一代一代地保留下来。 有关更多信息,请参见STM32CubeMX 用户手册。