全志R16平台SPI0接口的验证(分色排版)

移动开发 waitig 578℃ 百度已收录 0评论

全志R16平台SPI0接口的验证

2017/10/20 14:20

版本:V1.0

 

 

1、确定driver的name为spidev:

Q:\r16_tinav2.1\spi_csdn_tinav2.1\lichee\linux-3.4\drivers\spi\spidev.c

static struct spi_driver spidev_spi_driver = {

.driver = {

.name ="spidev",

.owner = THIS_MODULE,

},

.probe = spidev_probe,

.remove = __devexit_p(spidev_remove),

 

/* NOTE:  suspend/resume methods are not necessary here.

 * We don’t do anything except pass the requests to/from

 * the underlying controller.  The refrigerator handles

 * most issues; the controller driver handles the rest.

 */

};

 

 

 

 

2、打开spi0,定义spi_dev_num的数量大于1,定义spi_board0的modalias为spidev(必须和驱动保持一致):

Q:\r16_tinav2.1\spi_csdn_tinav2.1\target\allwinner\astar-parrot\configs\sys_config.fex

;———————————————————————————-

;SPI controller configuration

;spi_used       = SPIx enable

;spi_cs_bitmap  = SPI bit mapping

;———————————————————————————-

[spi0]

spi_used       = 1

spi_cs_bitmap  = 1

spi_mosi       = port:PC00<3><default><default><default>

spi_miso       = port:PC01<3><default><default><default>

spi_sclk       = port:PC02<3><default><default><default>

spi_cs0        = port:PC03<3><1><default><default>

 

[spi1]

spi_used       = 0

spi_cs_bitmap  = 1

spi_cs0        = port:PA00<2><1><default><default>

spi_sclk       = port:PA01<2><default><default><default>

spi_mosi       = port:PA02<2><default><default><default>

spi_miso       = port:PA03<2><default><default><default>

 

;———————————————————————————-

;SPI device configuration

;spi_dev_num: number of spi devices

;———————————————————————————-

[spi_devices]

spi_dev_num = 1

 

;———————————————————————————-

;[spi_board0] spi device configuration

;modalias      = spi device name

;sflash_size    = spi flash size, optional, if spi_board0 is nor flash , carefully

;max_speed_hz  = max transfer speed

;bus_num       = bus ID

;chip_select   = chip select, 0,1

;mode          = SPI transfer mode

;———————————————————————————-

[spi_board0]

;modalias      = "at25df641"

modalias      = "spidev"

sflash_size   = 32

max_speed_hz  = 50000000

bus_num       = 0

chip_select   = 0

mode          = 0

 

 

 

 

3、原始编译:

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1$
tar zxvf r16_tinav2.1_csdn_20170901_1040.tar.gz

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1$

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1$
mv tina spi_csdn_tinav2.1

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1$

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1$
cd spi_csdn_tinav2.1/

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
source build/envsetup.sh
 

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
lunch

     30. astar_parrot-tina

Which would you like?30

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
make -j12

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
pack -d

 

 

刷机之后:

root@TinaLinux:/#

root@TinaLinux:/# find . -name spi*

./proc/irq/97/spi0

./sys/bus/spi

./sys/bus/spi/devices/spi0.0

./sys/bus/platform/devices/spi.0

./sys/bus/platform/drivers/spi

./sys/bus/platform/drivers/spi/spi.0

./sys/devices/platform/spi.0

./sys/devices/platform/spi.0/spi_master

./sys/devices/platform/spi.0/spi_master/spi0

./sys/devices/platform/spi.0/spi_master/spi0/spi0.0

./sys/class/spi_master

./sys/class/spi_master/spi0

./sys/kernel/debug/clk/hosc/pll_periph/pll_periphahb1/ahb1/spinlock

./sys/kernel/debug/clk/hosc/pll_periph/spi0

./sys/kernel/debug/clk/hosc/spi1

root@TinaLinux:/#

 

 

 

 

4、在内核中打开SPI(生成设备节点/dev/spidev0.0):

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
make kernel_menuconfig

Device Drivers  —>

[*] SPI support  —>

< >   User mode SPI device driver support

修改为:

<*>   User mode SPI device driver support

 

 

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$ make -j12

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$ pack -d

 

 

root@TinaLinux:/# find . -name spi*

./dev/spidev0.0

./proc/irq/97/spi0

./sys/bus/spi

./sys/bus/spi/devices/spi0.0

./sys/bus/spi/drivers/spidev

./sys/bus/spi/drivers/spidev/spi0.0

./sys/bus/platform/devices/spi.0

./sys/bus/platform/drivers/spi

./sys/bus/platform/drivers/spi/spi.0

./sys/devices/platform/spi.0

./sys/devices/platform/spi.0/spi_master

./sys/devices/platform/spi.0/spi_master/spi0

./sys/devices/platform/spi.0/spi_master/spi0/spi0.0

./sys/devices/platform/spi.0/spi_master/spi0/spi0.0/spidev

./sys/devices/platform/spi.0/spi_master/spi0/spi0.0/spidev/spidev0.0

./sys/class/spi_master

./sys/class/spi_master/spi0

./sys/class/spidev

./sys/class/spidev/spidev0.0

./sys/kernel/debug/clk/hosc/pll_periph/pll_periphahb1/ahb1/spinlock

./sys/kernel/debug/clk/hosc/pll_periph/spi0

./sys/kernel/debug/clk/hosc/spi1

./sys/module/spidev

root@TinaLinux:/#

root@TinaLinux:/#

 

 

 

 

5、增加SPI的测试验证程序(spidev_test.c):

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
find . -name spidev_test.c

./lichee/linux-3.4/Documentation/spi/spidev_test.c

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
find . -name spi*.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/drivers/mtd/spi/spi_spl_load.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/drivers/spi/spi.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/arch/powerpc/cpu/mpc8260/spi.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/arch/powerpc/cpu/mpc5xx/spi.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/arch/powerpc/cpu/mpc8xx/spi.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/board/calao/sbc35_a9g20/spi.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/board/calao/tny_a9260/spi.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/board/renesas/sh7752evb/spi-boot.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/board/renesas/sh7757lcr/spi-boot.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/board/renesas/sh7753evb/spi-boot.c

./out/astar-parrot/compile_dir/host/u-boot-2014.10/board/emk/top9000/spi.c

./package/kernel/spi-gpio-custom/src/spi-gpio-custom.c

./lichee/linux-3.4/sound/soc/pxa/spitz.c

./lichee/linux-3.4/kernel/spinlock.c

./lichee/linux-3.4/lib/spinlock_debug.c

./lichee/linux-3.4/drivers/mtd/nand/spia.c

./lichee/linux-3.4/drivers/staging/rts_pstor/spi.c

./lichee/linux-3.4/drivers/spi/spi-pl022.c

./lichee/linux-3.4/drivers/spi/spi-sh-sci.c

./lichee/linux-3.4/drivers/spi/spi-sunxi.c

./lichee/linux-3.4/drivers/spi/spi-dw-pci.c

./lichee/linux-3.4/drivers/spi/spi-pxa2xx-pci.c

./lichee/linux-3.4/drivers/spi/spi-atmel.c

./lichee/linux-3.4/drivers/spi/spi-bfin5xx.c

./lichee/linux-3.4/drivers/spi/spi-xilinx.c

./lichee/linux-3.4/drivers/spi/spi-dw-mmio.c

./lichee/linux-3.4/drivers/spi/spi-au1550.c

./lichee/linux-3.4/drivers/spi/spi-ep93xx.c

./lichee/linux-3.4/drivers/spi/spi-mpc52xx-psc.c

./lichee/linux-3.4/drivers/spi/spi-topcliff-pch.c

./lichee/linux-3.4/drivers/spi/spidev.c

./lichee/linux-3.4/drivers/spi/spidev – ??.c

./lichee/linux-3.4/drivers/spi/spi-omap-uwire.c

./lichee/linux-3.4/drivers/spi/spi-mpc52xx.c

./lichee/linux-3.4/drivers/spi/spi-imx.c

./lichee/linux-3.4/drivers/spi/spi-fsl-lib.c

./lichee/linux-3.4/drivers/spi/spi-omap-100k.c

./lichee/linux-3.4/drivers/spi/spi-tegra.c

./lichee/linux-3.4/drivers/spi/spi-nuc900.c

./lichee/linux-3.4/drivers/spi/spi-sh.c

./lichee/linux-3.4/drivers/spi/spi-omap2-mcspi.c

./lichee/linux-3.4/drivers/spi/spi-pxa2xx.c

./lichee/linux-3.4/drivers/spi/spi-gpio.c

./lichee/linux-3.4/drivers/spi/spi-txx9.c

./lichee/linux-3.4/drivers/spi/spi-ath79.c

./lichee/linux-3.4/drivers/spi/spi-sh-hspi.c

./lichee/linux-3.4/drivers/spi/spi-dw.c

./lichee/linux-3.4/drivers/spi/spi-oc-tiny.c

./lichee/linux-3.4/drivers/spi/spi-butterfly.c

./lichee/linux-3.4/drivers/spi/spi-orion.c

./lichee/linux-3.4/drivers/spi/spi-sh-msiof.c

./lichee/linux-3.4/drivers/spi/spi-s3c64xx.c

./lichee/linux-3.4/drivers/spi/spi-bfin-sport.c

./lichee/linux-3.4/drivers/spi/spi-fsl-spi.c

./lichee/linux-3.4/drivers/spi/spi-tle62x0.c

./lichee/linux-3.4/drivers/spi/spi-bcm63xx.c

./lichee/linux-3.4/drivers/spi/spi-coldfire-qspi.c

./lichee/linux-3.4/drivers/spi/spi-dw-mid.c

./lichee/linux-3.4/drivers/spi/spi-stmp.c

./lichee/linux-3.4/drivers/spi/spi-ppc4xx.c

./lichee/linux-3.4/drivers/spi/spi-lm70llp.c

./lichee/linux-3.4/drivers/spi/spi-ti-ssp.c

./lichee/linux-3.4/drivers/spi/spi-altera.c

./lichee/linux-3.4/drivers/spi/spi-rspi.c

./lichee/linux-3.4/drivers/spi/spi.c

./lichee/linux-3.4/drivers/spi/spi-bitbang.c

./lichee/linux-3.4/drivers/spi/spi-mpc512x-psc.c

./lichee/linux-3.4/drivers/spi/spi-s3c24xx.c

./lichee/linux-3.4/drivers/spi/spi-sirf.c

./lichee/linux-3.4/drivers/spi/spi-fsl-espi.c

./lichee/linux-3.4/drivers/spi/spi-davinci.c

./lichee/linux-3.4/drivers/net/phy/spi_ks8995.c

./lichee/linux-3.4/drivers/net/ethernet/toshiba/spider_net.c

./lichee/linux-3.4/drivers/net/ethernet/toshiba/spider_net_ethtool.c

./lichee/linux-3.4/drivers/net/wireless/wl1251/spi.c

./lichee/linux-3.4/drivers/net/wireless/wl12xx/spi.c

./lichee/linux-3.4/drivers/net/wireless/esp8089/spi_sif_esp.c

./lichee/linux-3.4/Documentation/spi/spidev_test.c

./lichee/linux-3.4/Documentation/spi/spidev_fdx.c

./lichee/linux-3.4/arch/s390/lib/spinlock.c

./lichee/linux-3.4/arch/x86/xen/spinlock.c

./lichee/linux-3.4/arch/powerpc/platforms/cell/spider-pic.c

./lichee/linux-3.4/arch/powerpc/platforms/cell/spider-pci.c

./lichee/linux-3.4/arch/arm/mach-pxa/spitz.c

./lichee/linux-3.4/arch/arm/mach-pxa/spitz_pm.c

./lichee/linux-3.4/arch/arm/mach-u300/spi.c

./lichee/linux-3.4/arch/mips/kernel/spinlock_test.c

./lichee/linux-3.4/arch/mips/txx9/generic/spi_eeprom.c

./lichee/linux-3.4/arch/tile/lib/spinlock_32.c

./lichee/linux-3.4/arch/tile/lib/spinlock_64.c

./lichee/brandy/u-boot-2011.09/drivers/mtd/spi/spi_flash.c

./lichee/brandy/u-boot-2011.09/arch/powerpc/cpu/mpc8260/spi.c

./lichee/brandy/u-boot-2011.09/arch/powerpc/cpu/mpc5xx/spi.c

./lichee/brandy/u-boot-2011.09/arch/powerpc/cpu/mpc8xx/spi.c

./lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw5/spinor/spi_hal.c

./lichee/brandy/u-boot-2011.09/arch/arm/cpu/armv7/sun8iw8/spinor/spi_hal.c

./lichee/brandy/u-boot-2011.09/arch/arm/cpu/arm720t/lpc2292/spi.c

./lichee/brandy/u-boot-2011.09/board/calao/sbc35_a9g20/spi.c

./lichee/brandy/u-boot-2011.09/board/calao/tny_a9260/spi.c

./lichee/brandy/u-boot-2011.09/board/renesas/sh7757lcr/spi-boot.c

./lichee/brandy/u-boot-2011.09/board/emk/top9000/spi.c

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$

 

 

请严重注意:测试应用程序的名字不能叫:spidev_test。感觉是tinav2.1的SDK自动过滤掉了spidev_test这个应用程序名!

不过叫spidev_test0还是可以的!^_

 

(应用程序的写法请参考:W:\spi_csdn_tinav2.1\package\allwinner\cameratest。并做响应的修改!)

W:\spi_csdn_tinav2.1\package\allwinner\spidev_test0\Makefile

W:\spi_csdn_tinav2.1\package\allwinner\spidev_test0\src\Makefile

spidev_test0.c这个就是lichee/linux-3.4/Documentation/spi/spidev_test.c,不过需要根据实际修改设备节点!)

默认为:static const char *device = "/dev/spidev1.1";

请改为:static const char *device = "/dev/spidev0.0";

W:\spi_csdn_tinav2.1\package\allwinner\spidev_test0\src\spidev_test0.c

 

 

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$
make menuconfig

Allwinner  —>

< > spidev_test0……………….. spidev_test0 just test the SPI interface (NEW)

修改为:

<*> spidev_test0……………….. spidev_test0 just test the SPI interface

 

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$ make -j12

rootroot@cm-System-Product-Name:/home/rediron/r16_tinav2.1/spi_csdn_tinav2.1$ pack -d

 

 

开发板:SC3817R

请将开发板上的U8引脚上的第2脚(SPI0-MISO)和第5脚(SPI0-MOSI)通过1k欧姆的电阻连接在一起!(不建议直连,阻值可以根据实际情况灵活决定!)

[   15.644254] sunxi_i2c_do_xfer()985 – [i2c0] incomplete xfer (status: 0x20, dev addr: 0x5d)

[   15.656389] xt_time: kernel timezone is -0000

[   16.569503] android_usb gadget: high-speed config #1: android

 

 

 

BusyBox v1.24.1 () built-in shell (ash)

 

 _____  _              __     _

|_   _||_| ___  _ _   |  |   |_| ___  _ _  _ _

  | |   _ |   ||   |  |  |__ | ||   || | ||_’_|

  | |  | || | || _ |  |_____||_||_|_||___||_,_|

  |_|  |_||_|_||_|_|  Tina is Based on OpenWrt!

 ———————————————-

 Tina Linux (Neptune, 593A1793)

 ———————————————-

root@TinaLinux:/#

root@TinaLinux:/#

root@TinaLinux:/#

root@TinaLinux:/#

root@TinaLinux:/#

root@TinaLinux:/# spidev_test0 

spi mode: 0

bits per word: 8

max speed: 500000 Hz (500 KHz)

 

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

DE AD BE EF BA AD

F0 0D

root@TinaLinux:/#

(验证通过!)

 

 


本文由【waitig】发表在等英博客
本文固定链接:全志R16平台SPI0接口的验证(分色排版)
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)