“Serial TTY device tree configuration”的版本间的差异

来自百问网嵌入式Linux wiki
第19行: 第19行:
 
==DT configuration==
 
==DT configuration==
  
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 split.
+
该硬件描述是“''STM32微处理器”''设备树文件(扩展名为.dtsi)和“''板子”设备树文件(扩展名为.dts)的组合。有关设备树文件分割的说明,请参见[[Device tree]]
  
'''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|How to configure the DT using STM32CubeMX]]
  
 
===DT configuration (STM32 level)===
 
===DT configuration (STM32 level)===
  
All STM32 USART nodes (excepted USART1, secure instance under [[ETZPC_internal_peripheral|ETZPC]] control) are described in microprocessor device tree (ex: stm32mp157c.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi | arch/arm/boot/dts/stm32mp157c.dtsi}}, STM32MP157C device tree file</ref>) with default parameters and disabled status.<br/>
+
所有STM32 USART节点(USART1除外, [[ETZPC_internal_peripheral|ETZPC]] control) 控制下的安全实例)在微处理器设备树 (ex: stm32mp157c.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi | arch/arm/boot/dts/stm32mp157c.dtsi}}, STM32MP157C device tree file</ref>)中进行了描述,具有默认参数和禁用状态。<br/>
The required and optional properties are fully described in the [[Serial TTY device tree configuration#DT_bindings_documentation|bindings files]].
+
必需属性和可选属性在[[Serial TTY device tree configuration#DT_bindings_documentation|bindings files]]中进行了完整描述。
  
{{Warning|This device tree configuration related to the STM32 should be kept as is, without being modified by the customer.}}
+
{{Warning|与STM32相关的设备树配置应保持原样,而无需客户修改。}}
  
 
===DT configuration (Board level)===
 
===DT configuration (Board level)===
  
Part of the [[Device tree|device tree]] is used to describe the USART hardware used on a given board:
+
Part of the [[Device tree|device tree]] 的一部分用于描述给定板上使用的USART硬件:
  
* Which USART instances are enabled (by setting status to "okay")
+
* 启用了哪些USART实例(通过将状态设置为“确定”)
* Which features are used (such as DMA transfer or direct transfer, transfer speed or parity)
+
* 使用哪些功能(例如DMA传输或直接传输,传输速度或奇偶校验)
* Which pins are configured via [[Pinctrl device tree configuration|pinctrl]].
+
* 哪些引脚通过[[Pinctrl device tree configuration|pinctrl]]进行配置。
* Which serial aliases are linked to UART instances. Please check the alias already used in other device tree files to avoid alias conflicts. The alias defines the index of the ttySTMx instance linked the UART.
+
* 哪些串行别名链接到UART实例。 请检查其他设备树文件中已经使用的别名,以避免别名冲突。 别名定义链接到UART的ttySTMx实例的索引。
  
Note:
+
注意:
* As the pin configuration can be different for each board, several DT configurations can be defined for each UART instance.
+
* 由于每个板的引脚配置可能不同,因此可以为每个UART实例定义几种DT配置。
* The pin configuration is described in board datasheet. Each new pin configuration described in boards datasheet needs to be defined in device tree.<br/>
+
* 引脚配置在板数据表中进行了描述。 板数据表中描述的每个新引脚配置都需要在设备树中定义。<br/>
 
<br/>
 
<br/>
Four device tree configurations can be defined for each pin muxing configuration:
+
可以为每个引脚复用配置定义四个设备树配置:
* Default: for standard usage (mandatory)
+
* 默认值:用于标准用法(强制性)
* "sleep": for Sleep mode, when the UART instance is not a wake up source (mandatory)
+
* "sleep":对于睡眠模式,当UART实例不是唤醒源时(强制性)
* "idle": for Sleep mode, when the UART instance is a wake up source (optional)
+
* "idle": 对于睡眠模式,当UART实例是唤醒源时(可选)
* "no_console_suspend": when the UART instance is used for the console, and no_console_suspend mode is activated (optional).
+
* "no_console_suspend": 当将UART实例用于控制台时,并且激活了no_console_suspend模式(可选)。
  
 
===DT configuration examples===
 
===DT configuration examples===
 
====Activation of a USART or UART instance====
 
====Activation of a USART or UART instance====
{{Info|Some UART pins are available on GPIO expansion and Arduino connectors (depending on the connectors available on the board).
+
{{Info|GPIO扩展和Arduino连接器上提供了一些UART引脚(取决于板上可用的连接器)。
 
* [[STM32MP157C-EV1 - hardware description#MB1262-CN21|STM32MP157C-EV1 Evaluation board GPIO expansion connector]]
 
* [[STM32MP157C-EV1 - hardware description#MB1262-CN21|STM32MP157C-EV1 Evaluation board GPIO expansion connector]]
 
* [[STM32MP157X-DKX - hardware description#MB1272-CN2|STM32MP157X-DKX Discovery kit GPIO expansion connector]]
 
* [[STM32MP157X-DKX - hardware description#MB1272-CN2|STM32MP157X-DKX Discovery kit GPIO expansion connector]]
 
}}{{UpdateNeededForNewBoard|Point to the USART connectors}}
 
}}{{UpdateNeededForNewBoard|Point to the USART connectors}}
To communicate with a UART instance, an RS232 card must be plugged on the UART pins. <br/>
+
要与UART实例通信,必须在UART引脚上插入RS232卡。<br/>
 
<br/>
 
<br/>
The example below shows how to configure and enable a UART instance at board level, based on STM32MP157C-EV1 board USART3 example.<br/>
+
下面的示例基于STM32MP157C-EV1板USART3示例,展示了如何在板级配置和启用UART实例。<br/>
Note: For STM32 boards, the configuration is already defined in the device tree. Only the device activation is needed.<br/>
+
注意:对于STM32板,配置已在设备树中定义。 仅需要激活设备。<br/>
 
<br/>
 
<br/>
To activate a UART instance, please follow steps below:
+
要激活UART实例,请按照以下步骤操作:
* Define the instance pin configuration (ex: stm32mp157-pinctrl.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157-pinctrl.dtsi | arch/arm/boot/dts/stm32mp157-pinctrl.dtsi}}, STM32MP157 pinctrl device tree file</ref>).
+
* 定义实例引脚配置 (ex: stm32mp157-pinctrl.dtsi <ref>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157-pinctrl.dtsi | arch/arm/boot/dts/stm32mp157-pinctrl.dtsi}}, STM32MP157 pinctrl device tree file</ref>).
 
  usart3_pins_a: usart3-0 {
 
  usart3_pins_a: usart3-0 {
 
  pins1 {
 
  pins1 {
第103行: 第103行:
 
  };
 
  };
  
* Define the serial alias for this instance at board level (ex: stm32mp157c-ev1.dts <ref name="stm32mp157c-ev1.dts">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c-ev1.dts | arch/arm/boot/dts/stm32mp157c-ev1.dts}}, STM32MP157c ev1 board device tree file</ref>).
+
* 在主板级别 (ex: stm32mp157c-ev1.dts <ref name="stm32mp157c-ev1.dts">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c-ev1.dts | arch/arm/boot/dts/stm32mp157c-ev1.dts}}, STM32MP157c ev1 board device tree file</ref>)定义此实例的串行别名。
 
  aliases {
 
  aliases {
 
  {{highlight|/* Serial1 alias (ie ttySTM1) assigned to usart3 */}}
 
  {{highlight|/* Serial1 alias (ie ttySTM1) assigned to usart3 */}}
第110行: 第110行:
 
  };
 
  };
  
* Configure and activate the instance at board level (ex: stm32mp157c-ev1.dts <ref name="stm32mp157c-ev1.dts"/>).
+
* 在板级配置和激活实例 (ex: stm32mp157c-ev1.dts <ref name="stm32mp157c-ev1.dts"/>).
  
 
  &usart3 {
 
  &usart3 {
第120行: 第120行:
 
  };
 
  };
  
Note: The pin configuration selected has to be aligned with the pin configuration described in the board datasheet.
+
注:所选的引脚配置必须与电路板数据手册中所述的引脚配置对齐。
  
 
==How to configure the DT using STM32CubeMX==
 
==How to configure the DT using STM32CubeMX==

2020年11月9日 (一) 10:34的版本

Article Purpose

本文介绍了将USART 分配给 Linux® OS后如何配置。 在那种情况下,它由 Serial and TTY 框架控制。

使用device tree 机制执行配置,该机制提供了stm32-usart Linux驱动程序使用的USART外设的硬件描述。

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

DT bindings documentation

USART是多功能设备。

每个函数都由一个单独的绑定文档表示:

  • 通用UART绑定[1] 由UART框架使用。
  • STM32-USART驱动程序使用的STM32 USART驱动程序绑定[2]。 该绑定文档说明了如何为STM32 USART编写设备树文件。

DT configuration

该硬件描述是“STM32微处理器”设备树文件(扩展名为.dtsi)和“板子”设备树文件(扩展名为.dts)的组合。有关设备树文件分割的说明,请参见Device tree

“STM32CubeMX”可用于生成板设备树。有关更多详细信息,请参考How to configure the DT using STM32CubeMX

DT configuration (STM32 level)

所有STM32 USART节点(USART1除外, ETZPC control) 控制下的安全实例)在微处理器设备树 (ex: stm32mp157c.dtsi [3])中进行了描述,具有默认参数和禁用状态。
必需属性和可选属性在bindings files中进行了完整描述。

Warning.png 与STM32相关的设备树配置应保持原样,而无需客户修改。

DT configuration (Board level)

Part of the device tree 的一部分用于描述给定板上使用的USART硬件:

  • 启用了哪些USART实例(通过将状态设置为“确定”)
  • 使用哪些功能(例如DMA传输或直接传输,传输速度或奇偶校验)
  • 哪些引脚通过pinctrl进行配置。
  • 哪些串行别名链接到UART实例。 请检查其他设备树文件中已经使用的别名,以避免别名冲突。 别名定义链接到UART的ttySTMx实例的索引。

注意:

  • 由于每个板的引脚配置可能不同,因此可以为每个UART实例定义几种DT配置。
  • 引脚配置在板数据表中进行了描述。 板数据表中描述的每个新引脚配置都需要在设备树中定义。


可以为每个引脚复用配置定义四个设备树配置:

  • 默认值:用于标准用法(强制性)
  • "sleep":对于睡眠模式,当UART实例不是唤醒源时(强制性)
  • "idle": 对于睡眠模式,当UART实例是唤醒源时(可选)
  • "no_console_suspend": 当将UART实例用于控制台时,并且激活了no_console_suspend模式(可选)。

DT configuration examples

Activation of a USART or UART instance

Info.png GPIO扩展和Arduino连接器上提供了一些UART引脚(取决于板上可用的连接器)。

要与UART实例通信,必须在UART引脚上插入RS232卡。

下面的示例基于STM32MP157C-EV1板USART3示例,展示了如何在板级配置和启用UART实例。
注意:对于STM32板,配置已在设备树中定义。 仅需要激活设备。

要激活UART实例,请按照以下步骤操作:

  • 定义实例引脚配置 (ex: stm32mp157-pinctrl.dtsi [4]).
usart3_pins_a: usart3-0 {
	pins1 {
		/* USART3 TX and RTS pins activation for default mode */
		pinmux = <STM32_PINMUX('B', 10, AF7)>, /* USART3_TX */
			 <STM32_PINMUX('G', 8, AF8)>; /* USART3_RTS */
		bias-disable;
		drive-push-pull;
		slew-rate = <0>;
	};
	pins2 {
		/* USART3 RX and CTS_NSS pins activation for default mode */
		pinmux = <STM32_PINMUX('B', 12, AF8)>, /* USART3_RX */
			 <STM32_PINMUX('I', 10, AF8)>; /* USART3_CTS_NSS */
		bias-disable;
	};
};

usart3_idle_pins_a: usart3-idle-0 {
	pins1 {
		/* USART3 TX, RTS, and CTS_NSS pins deactivation for sleep mode */
		pinmux = <STM32_PINMUX('B', 10, ANALOG)>, /* USART3_TX */
			 <STM32_PINMUX('G', 8, ANALOG)>, /* USART3_RTS */
			 <STM32_PINMUX('I', 10, ANALOG)>; /* USART3_CTS_NSS */      
	};
	pins2 {
		/* USART3_RX pin still active for wake up */
		pinmux = <STM32_PINMUX('B', 12, AF8)>; /* USART3_RX */
		bias-disable;
	};
};

usart3_sleep_pins_a: usart3-sleep-0 {
	pins {
		/* USART3_TX, RTS, CTS_NSS, and RX pins deactivation for sleep mode */
		pinmux = <STM32_PINMUX('B', 10, ANALOG)>, /* USART3_TX */
			 <STM32_PINMUX('G', 8, ANALOG)>, /* USART3_RTS */
			 <STM32_PINMUX('I', 10, ANALOG)>, /* USART3_CTS_NSS */
			 <STM32_PINMUX('B', 12, ANALOG)>; /* USART3_RX */
	};
};
  • 在主板级别 (ex: stm32mp157c-ev1.dts [5])定义此实例的串行别名。
aliases {
	/* Serial1 alias (ie ttySTM1) assigned to usart3 */
	serial1 = &usart3;
	ethernet0 = &ethernet0;
};
  • 在板级配置和激活实例 (ex: stm32mp157c-ev1.dts [5]).
&usart3 {
	pinctrl-names = "default", "sleep", "idle";	/* pin configurations definition */
	pinctrl-0 = <&usart3_pins_a>;			/* default pin configuration selection */
	pinctrl-1 = <&usart3_sleep_pins_a>;		/* sleep pin configuration selection */
	pinctrl-2 = <&usart3_idle_pins_a>;		/* idle pin configuration selection */
	status = "okay";				/* device activation */
};

注:所选的引脚配置必须与电路板数据手册中所述的引脚配置对齐。

How to configure the DT using STM32CubeMX

The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
The STM32CubeMX may not support all the properties described 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.