“How to use SPI”的版本间的差异

来自百问网嵌入式Linux wiki
 
(未显示同一用户的6个中间版本)
第1行: 第1行:
 
__TOC__
 
__TOC__
 
<br />
 
<br />
{{ReviewsComments|W1938 FGA: Maybe rename the article:
+
或许可以给这篇文章改个名字:
* precise it's for Linux ?
+
* 准确地说,这是针对Linux的 ?
* How to use SPI from userland? (Uses "spidev": SPI devices userspace API)
+
* 如何从userland使用SPI?(使用 "spidev": SPI设备用户空间API)
Do we need a summary?}}
+
我们需要总结一下吗?
 
==Purpose==
 
==Purpose==
This article describes how to use SPI. The SPI overview is described in [[SPI overview]] article. <br/>
+
本文介绍如何使用SPI。[[SPI overview]] 文章中描述了SPI概述。 <br/>
{{ReviewsComments|W1938 FGA: This article describes how to use the SPI when the peripheral is assigned to Linux<sup>&reg;</sup>
+
本文介绍了将外围设备分配给Linux<sup>&reg;</sup>时如何使用SPI
* How to configure a SPI device via the board device tree (example using "spidev")
+
* 如何通过板设备树配置SPI设备(使用“ spidev”的示例)
* How to perform data transfers in userland
+
* 如何在用户区中执行数据传输
Maybe refine to TOC:
+
也许可以细化为TOC
* 1 Purpose
+
* 1 目的
* 2 Configuration (DT, kernel, board connection
+
* 2 配置(DT,内核,板卡连接)
* 3 Data transfert in user land
+
* 3 用户领域的数据传输
}}
 
  
 
== SPI Loop between MOSI and MISO ==
 
== SPI Loop between MOSI and MISO ==
{{ReviewsComments|W1931: ADE: Maybe add few lines here to explain the interest of a SPI Loop}}
+
也许在这里添加几行来说明SPI循环的重要性
{{ReviewsComments|W1938: FGA: Agreed, looks like that's for the example here, but valid for custom SPI user land uage? To elaborate...<br/>
+
同意,看起来像是这里的示例,但对自定义SPI用户登陆有效吗? 详细说明...<br/>
W1938: FGA: Also may be moved before [[#Simple data transfer]]}}
+
也可以在 [[#Simple data transfer]]之前移动
Short-circuit the MISO and MOSI lines of SPI bus to create a loopback allows the bus to receive the same data it is sending. This is interesting to execute quickly basic tests and to execute performance tests.
+
短路SPI总线的MISO和MOSI线以建立环回,使总线可以接收其发送的相同数据。 快速执行基本测试和执行性能测试很有趣。
  
 
=== Board connections ===
 
=== Board connections ===
{{ReviewsComments|W1938: FGA: Merge this into previsous description? Redundant with above Connect the MISO and MOSI lines...}}
+
合并到以前的描述? 以上冗余连接MISO和MOSI线...
A wire has to be added to connect MISO and MOSI pins (D12 et D11 pins on STM32MP157X-DKX ARDUINO connector)
+
必须添加一根导线来连接MISO和MOSI引脚(STM32MP157X-DKX ARDUINO连接器上的D12和D11引脚)
{{ReviewsComments|W1938: FGA: Maybe add level2 "Configuration" chapter as pre-requisite:
+
可能需要添加level2“配置”一章作为前提:
* DT config board
+
* DT配置板
* kernel menuconfig (SPI_SPIDEV), link to [[#Kernel configuration]] or mention here:
+
* 内核menuconfig(SPI_SPIDEV),链接到[[#Kernel configuration]]或在此处提及:
 
  Device Drivers --->
 
  Device Drivers --->
 
     SPI support --->
 
     SPI support --->
 
         <*>  User mode SPI device driver support
 
         <*>  User mode SPI device driver support
}}
+
 
 
=== DT configuration (board level) ===
 
=== DT configuration (board level) ===
[https://wiki.st.com/stm32mpu/wiki/SPI_device_tree_configuration Board DT configuration] has to be updated to:
+
[[https://wiki.st.com/stm32mpu/wiki/SPI_device_tree_configuration Board DT configuration]] 必须更新为:
* configure cs-gpios and activate spi4 node
+
* 配置cs-gpios并激活spi4节点
* add [https://wiki.st.com/stm32mpu/wiki/SPI_overview#spidev spidev] configuration to spi4 node
+
* 将[[https://wiki.st.com/stm32mpu/wiki/SPI_overview#spidev spidev]] 配置添加到spi4节点
  
{{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 }}
+
spi设备中不需要属性#addess-cells和#size-cells。它们在spi控制器节点中是必需的,实际上它们正确存在于stm32mp157c.dtsi中,但在spi设备中却不存在。 在Documentation/ devicetree / bindings / spi / spi-bus中对此进行了描述。
{{ReviewsComments|W1938 FGA: Don't understand why you copy/paste the example already provided in [[SPI_device_tree_configuration#DT_configuration_-28board_level-29]]. There's no additional information here...
+
不明白为什么要复制/粘贴[[SPI_device_tree_configuration#DT_configuration_-28board_level-29]]中已经提供的示例。 这里没有更多的信息。
Or maybe need to add better explanation on why it has to be updated for loopback testing ?
+
还是需要对为何必须对其进行回送测试进行更新进行更好的解释?
* Configure the PE11 GPIO as the chip select by using '''cs-gpios ...'''
+
* 通过使用'''cs-gpios ...'''将PE11 GPIO配置为芯片选择
* Configure the SPI MOSI/MISO/... pin as alternate function via [[Pinctrl_overview|pinctrl]] through pinctrl-0, pinctrl-1 and pinctrl-names
+
* 通过pinctrl-0,pinctrl-1和pinctrl名称,通过[[Pinctrl_overview|pinctrl]]将SPI MOSI / MISO / ...引脚配置为备用功能
* Activate SPI controller by setting status "okay"
+
* 通过将状态设置为“ okay”激活SPI控制器
* Add a spidev child node
+
* 添加一个spidev子节点
** Enable spidev by adding compatible  "spidev";
+
** 通过添加兼容的“ spidev”来启用spidev;
** Configure speed by setting ...
+
** 通过设置配置速度...
 
** Also a note on unit-address (@0) / reg  <0> / cs-gpio index/number?;
 
** Also a note on unit-address (@0) / reg  <0> / cs-gpio index/number?;
}}
+
 
  
 
  &spi4 {
 
  &spi4 {
第68行: 第67行:
 
  {{Board$}} echo -ne "\xAA\xBB" > /dev/spidev0.0
 
  {{Board$}} echo -ne "\xAA\xBB" > /dev/spidev0.0
 
  {{Board$}} more /dev/spidev0.0
 
  {{Board$}} more /dev/spidev0.0
{{ReviewsComments|W1938 FGA: command result ? How to check it matches spi4 instance ?}}
 
  
 
=== Data transfer with spidev_test ===
 
=== Data transfer with spidev_test ===
The spidev_test tool, from the Linux<sup>&reg;</sup> kernel, provides a test tool for [https://wiki.st.com/stm32mpu/wiki/SPI_overview#spidev spidev].
+
来自 Linux<sup>&reg;</sup>内核的spidev_test工具为[https://wiki.st.com/stm32mpu/wiki/SPI_overview#spidev spidev]提供了一种测试工具。
 
 
 
==== Source code location ====
 
==== Source code location ====
The Linux<sup>&reg;</sup> kernel spidev_test tool source code can be found under tools/spi<ref name="spidev_test source">{{CodeSource | Linux kernel | tools/spi}}, Linux<sup>&reg;</sup> spi source code directory</ref>.
+
The Linux<sup>&reg;</sup> 内核spidev_test工具源代码可以在 tools/spi<ref name="spidev_test source">{{CodeSource | Linux kernel | tools/spi}}, Linux<sup>&reg;</sup> spi源代码目录</ref>.
  
 
==== spidev_test compilation ====
 
==== spidev_test compilation ====
This tool is not compiled by default when compiling the Linux kernel for the target board. It can be compiled independently: [[How to build Linux kernel user space tools]] and then installed on the target.
+
在为目标板编译Linux内核时,默认情况下不编译此工具。 它可以独立编译: [[How to build Linux kernel user space tools]] 然后安装在目标上。
 
 
 
==== List the spidev options ====
 
==== List the spidev options ====
The ''spidev_test'' tool options can be listed:
+
可以列出“ spidev_test”工具选项:
  
 
  {{Board$}} spidev_test -h
 
  {{Board$}} spidev_test -h

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


或许可以给这篇文章改个名字:

  • 准确地说,这是针对Linux的 ?
  • 如何从userland使用SPI?(使用 "spidev": SPI设备用户空间API)

我们需要总结一下吗?

Purpose

本文介绍如何使用SPI。SPI overview 文章中描述了SPI概述。

本文介绍了将外围设备分配给Linux®时如何使用SPI
  • 如何通过板设备树配置SPI设备(使用“ spidev”的示例)
  • 如何在用户区中执行数据传输

也许可以细化为TOC

  • 1 目的
  • 2 配置(DT,内核,板卡连接)
  • 3 用户领域的数据传输

SPI Loop between MOSI and MISO

也许在这里添加几行来说明SPI循环的重要性 同意,看起来像是这里的示例,但对自定义SPI用户登陆有效吗? 详细说明...
也可以在 #Simple data transfer之前移动 短路SPI总线的MISO和MOSI线以建立环回,使总线可以接收其发送的相同数据。 快速执行基本测试和执行性能测试很有趣。

Board connections

合并到以前的描述? 以上冗余连接MISO和MOSI线... 必须添加一根导线来连接MISO和MOSI引脚(STM32MP157X-DKX ARDUINO连接器上的D12和D11引脚) 可能需要添加level2“配置”一章作为前提:

Device Drivers --->
   SPI support --->
       <*>   User mode SPI device driver support

DT configuration (board level)

[Board DT configuration] 必须更新为:

  • 配置cs-gpios并激活spi4节点
  • 将[spidev] 配置添加到spi4节点

spi设备中不需要属性#addess-cells和#size-cells。它们在spi控制器节点中是必需的,实际上它们正确存在于stm32mp157c.dtsi中,但在spi设备中却不存在。 在Documentation/ devicetree / bindings / spi / spi-bus中对此进行了描述。 不明白为什么要复制/粘贴SPI_device_tree_configuration#DT_configuration_-28board_level-29中已经提供的示例。 这里没有更多的信息。 还是需要对为何必须对其进行回送测试进行更新进行更好的解释?

  • 通过使用cs-gpios ...将PE11 GPIO配置为芯片选择
  • 通过pinctrl-0,pinctrl-1和pinctrl名称,通过pinctrl将SPI MOSI / MISO / ...引脚配置为备用功能
  • 通过将状态设置为“ okay”激活SPI控制器
  • 添加一个spidev子节点
    • 通过添加兼容的“ spidev”来启用spidev;
    • 通过设置配置速度...
    • Also a note on unit-address (@0) / reg <0> / cs-gpio index/number?;


&spi4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi4_pins_a>;
	pinctrl-1 = <&spi4_sleep_pins_a>;
	status = "okay";
	cs-gpios = <&gpioe 11 0>;

	spidev@0{
		compatible = "spidev";
		reg = <0>;
		spi-max-frequency = <4000000>;
		#address-cells = <1>;
		#size-cells = <0>;
	};
};

Simple data transfer

Board $> echo -ne "\xAA\xBB" > /dev/spidev0.0
Board $> more /dev/spidev0.0

Data transfer with spidev_test

来自 Linux®内核的spidev_test工具为spidev提供了一种测试工具。

Source code location

The Linux® 内核spidev_test工具源代码可以在 tools/spi[1].

spidev_test compilation

在为目标板编译Linux内核时,默认情况下不编译此工具。 它可以独立编译: 如何构建Linux内核用户空间工具 然后安装在目标上。

List the spidev options

可以列出“ spidev_test”工具选项:

Board $> spidev_test -h
Usage: spidev_test [-DsbdlHOLC3vpNR24SItx]
  -D --device   device to use (default /dev/spidev1.1)
  -s --speed    max speed (Hz)
  -d --delay    delay (usec)
  -b --bpw      bits per word
  -i --input    input data from a file (e.g. "test.bin")
  -o --output   output data to a file (e.g. "results.bin")
  -l --loop     loopback
  -H --cpha     clock phase
  -O --cpol     clock polarity
  -L --lsb      least significant bit first
  -C --cs-high  chip select active high
  -3 --3wire    SI/SO signals shared
  -v --verbose  Verbose (show tx buffer)
  -p            Send data (e.g. "1234\xde\xad")
  -N --no-cs    no chip select
  -R --ready    slave pulls low to pause
  -2 --dual     dual transfer
  -4 --quad     quad transfer
  -S --size     transfer size
  -I --iter     iterations
  -t --txonly   simplex tx transfer
  -r --rxonly   simplex rx transfer

Example to transfer 32 bytes in full-duplex

Board $> spidev_test -D /dev/spidev0.0 -v
			spi mode: 0x0
			bits per word: 8
			max speed: 500000 Hz (500 KHz)
			TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@.... .................. .
			RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@.... .................. .

References

  1. tools/spi| |}} tools/spi , Linux® spi源代码目录