This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ti-processor-sdk-linux-am335x-evm-02.00.00.00下的SPI



大家好,我想问下我用的是ti-processor-sdk-linux-am335x-evm-02.00.00.00的SDK,硬件是beaglebone black,我修改了arch/arm/boot/dts/am33xx.dtsi,将spi使能

git diff arch/arm/boot/dts/am33xx.dtsi
diff --git a/arch/arm/boot/dts/am33xx.dtsi b/arch/arm/boot/dts/am33xx.dtsi
index 3a74c2d..4ea748d 100644
--- a/arch/arm/boot/dts/am33xx.dtsi
+++ b/arch/arm/boot/dts/am33xx.dtsi
@@ -483,7 +483,7 @@
                                &edma 18
                                &edma 19>;
                        dma-names = "tx0", "rx0", "tx1", "rx1";
-                       status = "disabled";
+                       status = "okay";
                };
 
                spi1: spi@481a0000 {
@@ -499,7 +499,7 @@
                                &edma 44
                                &edma 45>;
                        dma-names = "tx0", "rx0", "tx1", "rx1";
-                       status = "disabled";
+                       status = "okay";
                };
 
                usb: usb@47400000 {

启动后在/sys/bus/platform/drivers/omap2_mcspi下都有看到SPI的文件,但是在/dev下没有spi*.*

想问下如何修改?

  • 建议先参考下GPEVM的dts文件中的SPI FLASH写法。

  • 你说的GPEVM指的是什么?

  • 请参考:

    http://processors.wiki.ti.com/index.php/Linux_Core_SPI_User%27s_Guide

  • 感谢回复,我是新加了一个

    static struct spi_board_info spi_board_info_array[] = {
        {
        .modalias = "spidev",
        .max_speed_hz = 10000000,
        .bus_num = 1,
        .mode    = SPI_MODE_0,
        },
    };
    

    然后调用spi_register_board_info

    现在是可以在/dev/下生成/dev/spidev1.0设备,我也用Documentation/spi/spidev_test.c程序进行测试,但是接收到的数据全部为0,并且通过示波器去抓取SCLK管脚未发现时钟。

    打印如下(我在内核中加了一些打印):

    ./spidev_test -D /dev/spidev1.0 
    spi mode: 0x0[  606.942403] spidev_message 230
    
    bits per word: 8
    max speed: 500000 Hz (500 KHz)
    [  606.946578] omap2_mcspi_transfer_one_message 1222 1 fa1a0100 481a0100
    [  606.957600] --omap2_mcspi_work 1158 0 32
    RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  | ................................
    

    驱动最终是进入omap2_mcspi_txrx_pio函数。操作寄存器的基地址是0x481a0100,是SPI1的地址

  • 是否需要配置SPI1对应的GPIO管脚复用功能,如果需要,那是在ti-processor-sdk-linux-am335x-evm-02.00.00.00中的哪里进行修改?

  • 我在设备树里添加了管脚配置

    		pinctrl-single,pins = <
    		    0x190 ( PIN_OUTPUT | MUX_MODE3 ) /* (A13) mcasp0_aclkx.spi1_sclk */
    		    0x194 ( PIN_INPUT | MUX_MODE3 ) /* (B13) mcasp0_fsx.spi1_d0 */
    		    0x198 ( PIN_OUTPUT | MUX_MODE3 ) /* (D12) mcasp0_axr0.spi1_d1 */
    		    0x19c ( PIN_OUTPUT | MUX_MODE3 ) /* (C12) mcasp0_ahclkr.spi1_cs0 */
    		>;

    现在SPI1_SCK、SPI1_CS0、SPI1_D1、都有数据。

    我将SPI1_D1和SPI1_D0短路,然后用spidev_test测试读出来的数据与发送的数据不一样,读出来的数据全为0,就算我将SPI1_D0接到高电平,读出来的数据依然为0。

    我哪个地方配置错误?

  • 写数据时内核打印信息如下

    [   15.721310] 0x481a0114 = 0x00000001
    [   15.724826] 0x481a0124 = 0x00000000
    [   15.728324] 0x481a0128 = 0x00000001
    [   15.731839] 0x481a012c = 0x201103fc
    [   15.735337] 0x481a0130 = 0x00000002
    [   15.738834] 0x481a0134 = 0x00000501
    [   15.750035] write-8 ff
    [   15.752428] read-8 00
    [   15.754705] write-8 ff
    [   15.757086] read-8 00
    [   15.759363] write-8 ff
    [   15.761747] read-8 00
    [   15.764024] write-8 ff
    [   15.766405] read-8 00
    [   15.768682] write-8 ff
    [   15.771063] read-8 00
    [   15.773378] write-8 ff
    [   15.775760] read-8 00
    [   15.778037] write-8 40
    [   15.780418] read-8 00
    [   15.782709] write-8 00
    [   15.785091] read-8 00
    [   15.787367] write-8 00
    [   15.789748] read-8 00
    [   15.792077] write-8 00
    [   15.794460] read-8 00
    [   15.796830] write-8 00
    [   15.799214] read-8 00
    [   15.801491] write-8 95
    [   15.803894] read-8 00
    [   15.806173] write-8 ff
    [   15.808553] read-8 00
    [   15.810830] write-8 ff
    [   15.813223] read-8 00
    [   15.815501] write-8 ff
    [   15.817882] read-8 00
    [   15.820159] write-8 ff
    [   15.822551] read-8 00
    [   15.824828] write-8 ff
    [   15.827209] read-8 00
    [   15.829486] write-8 ff
    [   15.831877] read-8 00
    [   15.834155] write-8 ff
    [   15.836536] read-8 00
    [   15.838812] write-8 ff
    [   15.841193] read-8 00
    [   15.843483] write-8 ff
    [   15.845864] read-8 00
    [   15.848141] write-8 ff
    [   15.850522] read-8 00
    [   15.852809] write-8 ff
    [   15.855191] read-8 00
    [   15.857468] write-8 ff
    [   15.859848] read-8 00
    [   15.862136] write-8 ff
    [   15.864517] read-8 00
    [   15.866794] write-8 ff
    [   15.869174] read-8 00
    [   15.871450] write-8 ff
    [   15.873842] read-8 00
    [   15.876119] write-8 ff
    [   15.878500] read-8 00
    [   15.880776] write-8 ff
    [   15.883168] read-8 00
    [   15.885446] write-8 ff
    [   15.887827] read-8 00
    [   15.890103] write-8 f0
    [   15.892495] read-8 00
    [   15.894773] write-8 0d
    [   15.897153] read-8 00
    

    写入数据是没有问题,读出来的数据都是为0,SPI寄存器的值我也打印出来了

  • 我看3.12的dts文件里面,SPI的pin设置成了:

    spi0_pins: pinmux_spi0_pins {
    pinctrl-single,pins = <
    0x150 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_clk.spi0_clk */
    0x154 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_d0.spi0_d0 */
    0x158 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_d1.spi0_d1 */
    0x15c (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_cs0.spi0_cs0 */
    >;
    };

    你改成这个试一下

  • SDK 2.00.01.07 折腾了下,

    搞好了:

    1:先配置好TI的默认配置

    2:make ARCH=arm CROSS_COMPLIE=arm-linux-gnueabihf- menuconfig

    依次选择
    Device Drivers --->
    SPI support --->
    <*>McSPI driver for OMAP
    <*>User mode SPI device driver support

    然后编译新的内核,

    设备树 加入:

    &spi1 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&spi1_pins_s0>;
    spidev@1 {
    spi-max-frequency = <24000000>;
    reg = <0>;
    compatible = "rohm,dh2228fv";
    };
    };

    spi1_pins_s0 是引脚的定义,compatible = "rohm,dh2228fv"; 为啥这么奇怪的名字,我也不晓得,反正写错了就没有spidev1.0

    然后系统里就有/dev/spidev1.0了