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

来自百问网嵌入式Linux wiki
 
(未显示同一用户的3个中间版本)
第17行: 第17行:
  
 
== 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'''可用于生成板卡设备树。有关更多详细信息,请参考[[#How_to_configure_the_DT_using_STM32CubeMX|How to configure the DT using STM32CubeMX]]
'''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.
 
  
 
===DT configuration (STM32 level) ===
 
===DT configuration (STM32 level) ===
At device level, each SPI controller is declared as follows:
+
在设备级别,每个SPI控制器的声明如下:
 
<pre>
 
<pre>
 
spi1: spi@44004000 {
 
spi1: spi@44004000 {
第39行: 第38行:
 
};
 
};
 
</pre>
 
</pre>
{{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微处理器有关。 它必须保持原样,而不能由最终用户修改。}}
  
Refer to the DTS file: stm32mp157c.dtsi<ref name=DTS>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi}}</ref>
+
请参阅DTS文件:stm32mp157c.dtsi<ref name=DTS>{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi}}</ref>
  
 
=== DT configuration (board level) ===
 
=== DT configuration (board level) ===
{{ReviewsComments|W1935: ABO: The properties #addess-cells and #size-cells are not required in the spi device. They are mandatory in the spi controller node, and in fact they are correctly present in stm32mp157c.dtsi, but not in the spi device. This is described in Documentation/devicetree/bindings/spi/spi-bus.txt }}
+
 
 
<pre>
 
<pre>
 
&spi1 {
 
&spi1 {
第64行: 第63行:
 
</pre>
 
</pre>
  
There are two levels of configuration:
+
有两个级别的配置:
* Configuration of the SPI bus properties:
+
* SPI总线属性的配置:
** '''{{highlight|pinctrl-0&1}}''' configuration depends on hardware board configuration and on how the SPI devices are connected to MOSI, MISO and Clk pins.<br/> More details about pin configuration are available here: [[Pinctrl device tree configuration]]  
+
** '''{{highlight|pinctrl-0&1}}''' 配置取决于硬件板配置以及SPI设备如何连接至MOSI,MISO和Clk引脚。<br/>有关引脚配置的更多详细信息,请参见:[[Pinctrl device tree configuration]]  
** '''{{highlight|cs-gpios}}''' represents the list of GPIOs used as chip selects. Native controller chip select defined by a NULL value is not supported by STM32MP1 SPI driver.<br/>More details about GPIO configuration are available here: [[GPIO device tree configuration]]
+
** '''{{highlight|cs-gpios}}''' 代表用作芯片选择的GPIO列表。STM32MP1 SPI驱动程序不支持由NULL值定义的本机控制器芯片选择。<br/>此处提供有关GPIO配置的更多详细信息:[[GPIO device tree configuration]]
** '''{{highlight|dmas}}''': by default, DMAs are specified for all SPI instances. This is up to the user to '''remove''' them if they are not needed. ''{{highlight|/delete-property/}}'' is used to remove DMA usage for SPI. Both '''{{highlight|/delete-property/dma-names}}''' and '''{{highlight|/delete-property/dma}}''' have to be inserted to get rid of DMAs.
+
** '''{{highlight|dmas}}''':默认情况下,为所有SPI实例指定DMA。 如果不需要,则由用户决定“删除”。 ''{{highlight|/delete-property/}}''用于删除SPI的DMA使用。 必须插入  '''{{highlight|/delete-property/dma-names}}''''''{{highlight|/delete-property/dma}}''' 来摆脱DMA。
  
* Configuration of the properties of the SPI device connected on the bus:
+
* 总线上连接的SPI设备的属性的配置:
** '''{{highlight|compatible }}''' represents the name of the SPI device driver.
+
** '''{{highlight|compatible }}''' 表示SPI设备驱动程序的名称。
** '''{{highlight|reg}}''' represents the index of the gpio chip select associated to this SPI device.
+
** '''{{highlight|reg}}''' 表示与此SPI设备关联的GPIO芯片选择的索引。
** '''{{highlight|spi-max-frequency}}''' represents the maximum SPI clocking speed for the device (in Hz).
+
** '''{{highlight|spi-max-frequency}}''' 表示设备的最大SPI时钟速度(以Hz为单位)。
  
For more information about SPI bus and SPI device bindings, please refer to spi-bus.txt<ref name="spi-bus.txt"/>
+
有关SPI总线和SPI设备绑定的更多信息,请参考spi-bus.txt。<ref name="spi-bus.txt"/>
  
 
=== DT configuration example ===
 
=== DT configuration example ===
'''Example:''' of an external TPM device:
+
'''示例:'''外部TPM设备:
 
  &spi1 {
 
  &spi1 {
 
  pinctrl-names = "default", "sleep";
 
  pinctrl-names = "default", "sleep";
第95行: 第94行:
 
  };
 
  };
  
The above example registers a TPM device on spi1 bus, selected by chip select 0 also known as GPIO-Z3. This instance is compatible with the driver registered with the same compatible property (st,st33htpm-spi).<br/>
+
上面的示例在spi1总线上注册了TPM设备,该设备由芯片选择0(也称为GPIO-Z3)选择。 该实例与使用相同的兼容属性(st,st33htpm-spi)注册的驱动程序兼容。<br/>
  
 
==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 />

2020年11月8日 (日) 15:27的最新版本

Article purpose

本文介绍了如何配置“SPI内部外设”[1] 将外围设备分配给® 操作系统时, 特别是:

  • 如何配置STM32 SPI外设
  • 如何配置板上或硬件扩展上存在的STM32外部SPI器件。

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

它由STM32 SPI Linux® 驱动程序使用,该驱动程序在SPI 框架中注册相关信息。

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

DT bindings documentation

SPI总线及其关联的设备表示为:

  • SPI总线的通用设备树绑定[3]
  • STM32 SPI控制器设备树绑定[4]

DT configuration

该硬件描述是STM32微处理器设备树文件(扩展名为.dtsi)和板子设备树文件(扩展名为.dts)的组合。有关设备树文件分割的说明,请参见Device treeSTM32CubeMX可用于生成板卡设备树。有关更多详细信息,请参考How to configure the DT using STM32CubeMX

DT configuration (STM32 level)

在设备级别,每个SPI控制器的声明如下:

spi1: spi@44004000 {
	#address-cells = <1>;
	#size-cells = <0>;
	compatible = "st,stm32h7-spi";
	reg = <0x44004000 0x400>;
	interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&rcc SPI1_K>;
	resets = <&rcc SPI1_R>;
	dmas = <&dmamux1 37 0x400 0x05>,
	       <&dmamux1 38 0x400 0x05>;
	dma-names = "rx", "tx";
	power-domains = <&pd_core>;
	status = "disabled";
};
Warning.png 该设备树部分与STM32微处理器有关。 它必须保持原样,而不能由最终用户修改。

请参阅DTS文件:stm32mp157c.dtsi[5]

DT configuration (board level)

&spi1 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi1_pins_a>;
	pinctrl-1 = <&spi1_sleep_pins_a>;
	cs-gpios = <&gpioz 3 0>;
	status = "okay";

        foo@0 {
                compatible = "spi-foo";
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0>; /* CS #0 */
                spi-max-frequency = <10000000>;
        };
};

有两个级别的配置:

  • SPI总线属性的配置:
    • pinctrl-0&1 配置取决于硬件板配置以及SPI设备如何连接至MOSI,MISO和Clk引脚。
      有关引脚配置的更多详细信息,请参见:Pinctrl device tree configuration
    • cs-gpios 代表用作芯片选择的GPIO列表。STM32MP1 SPI驱动程序不支持由NULL值定义的本机控制器芯片选择。
      此处提供有关GPIO配置的更多详细信息:GPIO device tree configuration
    • dmas:默认情况下,为所有SPI实例指定DMA。 如果不需要,则由用户决定“删除”。 /delete-property/用于删除SPI的DMA使用。 必须插入 /delete-property/dma-names/delete-property/dma 来摆脱DMA。
  • 总线上连接的SPI设备的属性的配置:
    • compatible 表示SPI设备驱动程序的名称。
    • reg 表示与此SPI设备关联的GPIO芯片选择的索引。
    • spi-max-frequency 表示设备的最大SPI时钟速度(以Hz为单位)。

有关SPI总线和SPI设备绑定的更多信息,请参考spi-bus.txt。[3]

DT configuration example

示例:外部TPM设备:

&spi1 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi1_pins_a>;
	pinctrl-1 = <&spi1_sleep_pins_a>;
	cs-gpios = <&gpioz 3 0>;
	status = "okay";

	st33zp24@0 {
		compatible = "st,st33htpm-spi";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0>; /* CS #0 */
		spi-max-frequency = <10000000>;
	};
};

上面的示例在spi1总线上注册了TPM设备,该设备由芯片选择0(也称为GPIO-Z3)选择。 该实例与使用相同的兼容属性(st,st33htpm-spi)注册的驱动程序兼容。

How to configure the DT using STM32CubeMX

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