简体   繁体   English

Raspberry Pi-SPI设备树更改

[英]Raspberry Pi - SPI device tree changes

I trying to move the SPI bus on a Raspberry Pi 3. I would like to move it from GPIO 7-11 to GPIO pins 22-26. 我试图在Raspberry Pi 3上移动SPI总线。我想将其从GPIO 7-11移动到GPIO引脚22-26。 The file "bcm2708_common.dtsi" contains the node for the spi0 bus: 文件“ bcm2708_common.dtsi”包含spi0总线的节点:

spi0: spi@7e204000 {
    compatible = "brcm,bcm2835-spi";
    reg = <0x7e204000 0x1000>;
    interrupts = <2 22>;
    clocks = <&clk_core>;
    #address-cells = <1>;
    #size-cells = <0>;
    status = "disabled";
    /* the dma channels */
    dmas = <&dma 6>, <&dma 7>;
    dma-names = "tx", "rx";
    /* the chipselects used - <0> means native GPIO
     * add more gpios if necessary as <&gpio 6 1>
     * (but do not forget to make them output!)
     */
    cs-gpios = <0>, <0>;
};

The spi is configured in the top-level dts file "bcm2710-rpi-3-b.dts": 在顶级dts文件“ bcm2710-rpi-3-b.dts”中配置了spi:

&gpio {
    spi0_pins: spi0_pins {
        brcm,pins = <7 8 9 10 11>;
        brcm,function = <4>; /* alt0 */
    };
};

&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins>;
    cs-gpios = <0 0>;

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

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

Is reconfiguring the spi pins as simple as changing the gpio entry to this or is there something more that I need to do? 重新配置spi引脚是否像更改gpio条目一样简单,还是需要做更多事情?

&gpio {
    spi0_pins: spi0_pins {
        brcm,pins = <22 23 24 25 26>;
        brcm,function = <4>; /* alt0 */
    };
};

No. you can not just change the pin numbers in DTSI and get it to change. 不可以。您不仅可以更改DTSI中的引脚号并进行更改。

Long answer: The brcm,pins field is just information for driver to refer to, if hardware does not support the pins you write there, you can not get it to work. 长答案: brcm,pins字段仅供驱动程序参考,如果硬件不支持您在此处编写的引脚,则无法使其正常工作。 On the Rpi 3b, pins 7,8,9,10,11 are supported as SPI ie they can be multiplexed as SPI (the field brcm,function tells which multiplex mode to set pins in). 在Rpi 3b上,将引脚7,8,9,10,11支持为SPI,即可以将其复用为SPI(字段brcm,function指示将引脚设置为哪种复用模式)。

Now, also if you search for BCM2835 ARM peripheral you will find on page 152 the following: 现在,如果您还在搜索BCM2835 ARM外设,您也会在第152页找到以下内容:

The BCM2835 devices has only one SPI interface of this type . BCM2835器件只有一个这种类型的SPI接口 It is referred to in all the documentation as SPI0. 在所有文档中将其称为SPI0。 It has two additional mini SPI interfaces (SPI1 and SPI2). 它具有两个附加的微型SPI接口(SPI1和SPI2)。 The specifiation of those can be found under 2.3 Universal SPI Master (2x). 可以在2.3 Universal SPI Master(2x)下找到这些说明。

So, the SoC on Rpi itself does not support other spi on any other pin. 因此,Rpi上的SoC本身不支持任何其他引脚上的其他spi。

Now for the second sentence of the above quote 现在针对上述引用的第二句话

It has two additional mini SPI interfaces (SPI1 and SPI2). 它具有两个附加的微型SPI接口(SPI1和SPI2)。 The specifiation of those > can be found under 2.3 Universal SPI Master (2x). 可以在2.3 Universal SPI Master(2x)下找到这些规范。

If you dig in to bcm283x.dtsi, you will find that both those mini spis are named SPI1 and SPI2. 如果您深入研究bcm283x.dtsi,您会发现这两个微型spis都被命名为SPI1和SPI2。 gpio pins assigned for them are given as spi1_gpio16 and spi2_gpio40 which use pins : 分配给它们的gpio引脚分别为spi1_gpio16spi2_gpio40 ,它们使用的引脚是:

spi1_gpio16: spi1_gpio16 {
brcm,pins = <16 17 18 19 20 21>;
brcm,function = <BCM2835_FSEL_ALT4>;
};
spi2_gpio40: spi2_gpio40 {
brcm,pins = <40 41 42 43 44 45>;
brcm,function = <BCM2835_FSEL_ALT4>;
};

so again not the pins you want to use. 所以再次不是您要使用的引脚。

You may go for bit banging spi if you are really really in a fix and can not use anything else 如果您确实确实在修理中并且不能使用其他任何东西,则可能会遇到一些麻烦的spi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM