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

来自百问网嵌入式Linux wiki
第43行: 第43行:
  
 
=== DT configuration (board level) ===
 
=== DT configuration (board level) ===
{{ReviewsComments|W1935: ABO: spi设备中不需要属性#addess-cells和#size-cells。 它们在spi控制器节点中是必需的,实际上它们正确存在于stm32mp157c.dtsi中,但在spi设备中却不存在。 在文档/devicetree/bindings/spi/spi-bus.txt中对此进行了描述 }}
+
 
 
<pre>
 
<pre>
 
&spi1 {
 
&spi1 {

2020年11月8日 (日) 15:26的版本

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

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.