“SPI device tree configuration”的版本间的差异
第1行: | 第1行: | ||
== Article purpose == | == Article purpose == | ||
− | + | 本文介绍了如何配置“SPI内部外设”<ref name="SPI internal peripheral"> [[SPI internal peripheral]] </ref> ''' 将外围设备分配给<sup>®</sup> 操作系统时''', 特别是: | |
− | * | + | * 如何配置STM32 SPI外设 |
− | * | + | * 如何配置板上或硬件扩展上存在的STM32外部SPI器件。 |
− | + | 使用 '''设备树机制'''执行配置<ref> [[Device tree]]</ref>. | |
− | + | 它由''STM32 SPI Linux<sup>®</sup> 驱动程序''使用,该驱动程序在[[SPI overview|SPI]] 框架中注册相关信息。 | |
− | + | 如果将外围设备分配给另一个执行上下文,请参阅[ [[How to assign an internal peripheral to a runtime context]] 文章,以获取有关外围设备分配和配置的准则。 | |
== DT bindings documentation == | == DT bindings documentation == |
2020年11月8日 (日) 15:18的版本
目录
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
The SPI bus and its associated device are represented by:
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.
STM32CubeMX can be used to generate the board device tree. Refer to How to configure the DT using STM32CubeMX for more details.
DT configuration (STM32 level)
At device level, each SPI controller is declared as follows:
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"; };
This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user. |
Refer to the DTS file: stm32mp157c.dtsi[5]
DT configuration (board level)
<securetransclude src="ProtectedTemplate:ReviewsComments" params="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"></securetransclude>{{#set:Has reviews comments=true}}
&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>; }; };
There are two levels of configuration:
- Configuration of the SPI bus properties:
-
pinctrl-0&1 configuration depends on hardware board configuration and on how the SPI devices are connected to MOSI, MISO and Clk pins.
More details about pin configuration are available here: Pinctrl device tree configuration -
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.
More details about GPIO configuration are available here: GPIO device tree configuration - dmas: by default, DMAs are specified for all SPI instances. This is up to the user to remove them if they are not needed. /delete-property/ is used to remove DMA usage for SPI. Both /delete-property/dma-names and /delete-property/dma have to be inserted to get rid of DMAs.
-
pinctrl-0&1 configuration depends on hardware board configuration and on how the SPI devices are connected to MOSI, MISO and Clk pins.
- Configuration of the properties of the SPI device connected on the bus:
- compatible represents the name of the SPI device driver.
- reg represents the index of the gpio chip select associated to this SPI device.
- spi-max-frequency represents the maximum SPI clocking speed for the device (in Hz).
For more information about SPI bus and SPI device bindings, please refer to spi-bus.txt[3]
DT configuration example
Example: of an external TPM device:
&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>; }; };
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).
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.
References
Please refer to the following links for additional information:
- ↑ SPI internal peripheral
- ↑ Device tree
- ↑ 3.03.1 Documentation/devicetree/bindings/spi/spi-bus.txt| |}} Documentation/devicetree/bindings/spi/spi-bus.txt , Generic device tree bindings for SPI buses
- ↑ Documentation/devicetree/bindings/spi/spi-stm32.txt| |}} Documentation/devicetree/bindings/spi/spi-stm32.txt
- ↑ arch/arm/boot/dts/stm32mp157c.dtsi| |}} arch/arm/boot/dts/stm32mp157c.dtsi