问题描述
我们其中一块板上的Arm处理器具有一个spi端口,该端口带有两条芯片选择线.处理器的数据表中提到它最多可以控制两个spi设备.
The Arm processor on one of our boards has an spi port with two chip select lines.It is mentioned in the processor's datasheet that it can control upto two spi devices.
是否可以将GPIO用作其他SPI设备的从选择?如何修改现有的库/设备驱动程序以支持此更改?
Is it possible to use a GPIO as a slave select for an additional spi device?How to modify the existing libraries/device drivers to support this change?
到目前为止,我已经在内核的源代码中找到了一个文件,其中包含SPI端口引脚的地址.谁能告诉我应该朝哪个方向前进?
So far i've found a file in the kernel's source which contains the addresses of SPI port pins. Can anyone plz tell in which direction should i proceed?
推荐答案
您没有提到它是什么处理器.您有三种可能.
You don't mention what processor it is. You have three possibilities.
- 如果处理器具有
i/o mux
功能,请关闭SPI芯片选择功能. SPI控制器会认为它已声明该线路,但不会进入外部. - 不要连接一个SPI芯片选择.使用上拉/下拉保护ESD.
- 按照 Joachim Isaksson
- If the processor has an
i/o mux
capabilities, turn off the SPI chip select functionality. The SPI controller will think it has asserted the line, but it won't go external. - Don't connect one SPI chip select. Use a pull-up/down for ESD protection.
- Multiplex the
chip select
as per Joachim Isaksson
在前两种情况下,将GPIO
连接到另一设备的芯片选择.在运行spi_write()
等之前手动切换GPIO
.这将允许SPI
控制器以比位敲打更高的速率传输.这是一种更好的系统设计.即,更低的功耗,更低的CPU使用率,更快的数据速率等.如果外围设备仅用于设置/引导,那么 bit banging 就很简单了.但是,如果您的主要操作取决于SPI总线,则可以考虑使用此解决方案.
In first two cases, connect GPIO
s to the additional device's chip select. Toggle the GPIO
manually before running spi_write()
, etc. This will allow the SPI
controller to transfer at higher rates than are possible with bit banging and is a better system design. Ie, lower power consumption, lower CPU use, faster data rates, etc. If the peripheral is just for setup/boot, then the bit banging makes sense for simplicity. However, if your main operation depends on the SPI bus, you could consider this solution.
如果只有一个外设需要SPI进行设置 AND ,并且您具有i/o mux
,则可以在设置过程中使用GPIO选择 setup 来禁用芯片选择功能. >外围设备,然后在 standard 系统操作期间为另一个外围设备重新启用spi chip select
.
If only one peripheral needs the SPI for setup AND you have the i/o mux
, you can disable the chip select functionality during setup, using a GPIO to select the setup peripheral and then re-enable the spi chip select
during standard system operation for the other peripheral.
使用GPIO
不需要用户空间干预.驱动程序可以在使用时提供call backs
来设置GPIO,因此可以缓冲/排队SPI
命令,并且这些解决方案仍然有效.例如, IMX SPI
驱动程序通过传递负片选号来表示GPIO ID,从而支持GPIO切换.
Using a GPIO
doesn't require user space intervention. Drivers can provide call backs
to set the GPIO when in use, so SPI
commands can be buffered/queued and these solutions still work. For instance, the IMX SPI
driver supports GPIO toggle by passing a negative chip select number to denote a GPIO id.
注意:某些SPI设备可能需要chip select
在words
之间切换; word
适用于该设备.传输多个字时,某些控制器可能会保留chip select
断言.如果您使用GPIO手动选择设备,则需要正确设置.我确定有一些标准定义了这一点,但是肯定有些设备没有遵循该标准.
Note: Some SPI devices may require the chip select
to toggle between words
; what ever a word
is for the device. Some controller may leave the chip select
asserted when transferring multiple words. You need to get this right if you use a GPIO to manually select devices. I am sure some standard defines this, but definitely some device don't follow the standard.
附录:大多数驱动程序都支持GPIO
芯片选择.通过负的芯片选择值.他们将调用Linux GPIO
函数.编写一个进行解复用的GPIO
处理程序.无需更改SPI
驱动程序.
Addendum: Most drivers support a GPIO
chip select; via a negative chip select value. They will call Linux GPIO
functions. Write a GPIO
handler that does the de-multiplexing. No need to alter the SPI
drivers.
这篇关于一块仅支持两个的Arm板上的两个以上SPI设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!