各位好:
目前使用spi_test.c编译好的测试程序测试spi的时候,输出全是0xFF,查阅资料,说是没有写入数据。请各位帮忙看下问题在哪儿。在此先谢了。
SPI FLASH硬件连接没有问题,在u-boot下可以使用sf命令读/写/擦除数据。
版本:ti-processor-sdk-linux-am335x-evm-01.00.00.03-Linux-x86-Install.bin
SPI FLASH芯片:N25Q128 16M大小
SPI驱动修改:
am33xx.dtsi中增加红色部分的配置:
spi0: spi@48030000 {
compatible = "ti,omap4-mcspi";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x48030000 0x400>;
interrupts = <65>;
ti,spi-num-cs = <2>;
ti,hwmods = "spi0";
dmas = <&edma 16
&edma 17
&edma 18
&edma 19>;
dma-names = "tx0", "rx0", "tx1", "rx1";
status = "disabled";
spidev@0{
spi-max-frequency = <0x800000>;
reg = <0>;
compatible = "rohm,dh2228fv";
};
};
在am335x-evmsk.dts中,增加spi引脚设置:
spi0_pins: pinmux_spi0_pins {
pinctrl-single,pins = <
0x150 (PIN_INPUT_PULLUP | MUX_MODE0) /* spi0_sclk.spi0_sclk */
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 */ >;
};
&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins>;
status = "okay";
};
内核代码未做修改,程序启动后,设备信息如下:
root@am335x-evm:~# ls -l /dev/spi*
crw——- 1 root root 153, 0 Jan 1 1970 /dev/spidev1.0
相关的驱动信息如下:
root@am335x-evm:~# find / -name *spi*
/proc/device-tree/ocp/spi@48030000
/proc/device-tree/ocp/spi@48030000/ti,spi-num-cs
/proc/device-tree/ocp/spi@48030000/spidev@0
/proc/device-tree/ocp/spi@48030000/spidev@0/spi-max-frequency
/proc/device-tree/ocp/spinlock@480ca000
/proc/device-tree/pinmux@44e10800/pinmux_spi0_pins
/proc/device-tree/aliases/spi0
/djspitest
/sys/bus/spi
/sys/bus/spi/devices/spi1.0
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/spi1.0
/sys/bus/platform/devices/48030000.spi
/sys/bus/platform/devices/480ca000.spinlock
/sys/bus/platform/drivers/spi_gpio
/sys/bus/platform/drivers/spi_oc_tiny
/sys/bus/platform/drivers/omap_hwspinlock
/sys/bus/platform/drivers/omap_hwspinlock/480ca000.spinlock
/sys/bus/platform/drivers/omap2_mcspi
/sys/bus/platform/drivers/omap2_mcspi/48030000.spi
/sys/devices/ocp/48030000.spi
/sys/devices/ocp/48030000.spi/spi_master
/sys/devices/ocp/48030000.spi/spi_master/spi1
/sys/devices/ocp/48030000.spi/spi_master/spi1/spi1.0
/sys/devices/ocp/48030000.spi/spi_master/spi1/spi1.0/spidev
/sys/devices/ocp/48030000.spi/spi_master/spi1/spi1.0/spidev/spidev1.0
/sys/devices/ocp/480ca000.spinlock
/sys/class/spi_master
/sys/class/spi_master/spi1
/sys/class/spidev
/sys/class/spidev/spidev1.0
/sys/kernel/debug/tracing/events/spi
/sys/kernel/debug/tracing/events/spi/spi_master_idle
/sys/kernel/debug/tracing/events/spi/spi_master_busy
/sys/kernel/debug/tracing/events/spi/spi_message_submit
/sys/kernel/debug/tracing/events/spi/spi_message_start
/sys/kernel/debug/tracing/events/spi/spi_message_done
/sys/kernel/debug/tracing/events/spi/spi_transfer_start
/sys/kernel/debug/tracing/events/spi/spi_transfer_stop
/sys/module/spidev
/etc/ssl/certs/spi-cacert-2008.pem
/dev/spidev1.0
/usr/share/terminfo/s/spinwriter
/usr/share/ca-certificates/spi-inc.org
/usr/share/ca-certificates/spi-inc.org/spi-cacert-2008.crt
/lib/udev/keymaps/acer-aspire_8930
/lib/udev/keymaps/acer-aspire_6920
/lib/udev/keymaps/acer-aspire_5920g
/lib/udev/keymaps/acer-aspire_5720
使用系统自带的spi_test.c,编译成可执行程序,在ARM板上执行结果如下:
[ 228.960947] spidev_open
[ 228.963486] spidev_ioctl
[ 228.966240] spidev spi1.0: setup: speed 375000, sample leading edge, clk normal
[ 228.973600] setup mode 0, 8 bits/w, 500000 Hz max –> 0
[ 228.978873] spidev spi1.0: setup mode 0, 8 bits/w, 500000 Hz max –> 0
[ 228.985446] spidev spi1.0: spi mode 00
[ 228.989857] spidev_ioctl
[ 228.992417] spidev_ioctl
[ 228.994976] spidev spi1.0: setup: speed 375000, sample leading edge, clk normal
[ 229.002378] setup mode 0, 8 bits/w, 500000 Hz max –> 0
[ 229.007645] spidev spi1.0: setup mode 0, 8 bits/w, 500000 Hz max –> 0
[ 229.014203] spidev spi1.0: 8 bits per word
[ 229.019463] spidev_ioctl
[ 229.022014] spidev_ioctl
[ 229.024569] spidev spi1.0: setup: speed 375000, sample leading edge, clk normal
[ 229.031952] setup mode 0, 8 bits/w, 500000 Hz max –> 0
[ 229.037219] spidev spi1.0: setup mode 0, 8 bits/w, 500000 Hz max –> 0
[ 229.043777] spidev spi1.0: 500000 Hz (max)
[ 229.048047] spidev_ioctl
spi mode: 0[ 229.050987] spidev_ioctl
bits per word: 8
max speed: 500000 Hz (500 KHz)
[ 229.054494] spidev spi1.0: setup: speed 375000, sample leading edge, clk normal
[ 229.066321] >>>> omap2_mcspi_txrx_pio >>>>
[ 229.071354] spidev spi1.0: setup: speed 375000, sample leading edge, clk normal
FF FF FF FF FF FFFF FF FF FF FF FFFF FF FF FF FF FFFF FF FF FF FF FFFF FF FF FF FF FFFF FF FF FF FF FFFF FF
Mark Liao:
我用的是micron的芯片,是否应该把"ompatible ""修改为:“micron,n25q128a13"