[DM8168]Linux下SPI驱动测试

1、内核自带的SPI相关的驱动文件

项目中有CPU与FPGA进行通信,用到SPI接口:

SPI头文件在:

linux-kernel/include/linux/spi.h

SPI实现在:

linux-kernel/drivers/spi/spi.c omap2_mcspi.c spidev.c

DVS8168开发板在以下文件中初始化SPI:

linux-kernel/arch/arm/mach-omap2/board-ti8168evm.c

上述文件中有:

 1 const struct flash_platform_data ti816x_spi_flash = 
 2 {
 3     .type        = "w25x32",
 4     .name        = "spi_flash",
 5     .parts       = ti816x_spi_partitions,
 6     .nr_parts    = ARRAY_SIZE(ti816x_spi_partitions),
 7 };
 8 
 9 struct spi_board_info __initdata ti816x_spi_slave_info[] = 
10 {
11     {
12         .modalias       = "m25p80",
13         .platform_data  = &ti816x_spi_flash,
14         .irq            = -1,
15         .max_speed_hz   = 75000000,
16         .bus_num        = 1,
17         .chip_select    = 0,
18     },
19 };
20 
21 static void __init ti816x_spi_init(void)
22 {
23     spi_register_board_info(ti816x_spi_slave_info,
24     ARRAY_SIZE(ti816x_spi_slave_info));
25 }

修改board-ti8168evm.c 初始化我们自己的SPI设备,如下:

 1 // Dragon add
 2 struct spi_board_info __initdata fpga_spi_slave_info[] = {
 3     {
 4         .modalias = "spidev",
 5         .max_speed_hz = 48000000,       // 48 Mbps
 6         .bus_num = 1,
 7         .chip_select = 2,
 8         .mode = SPI_MODE_1,
 9     },
10 };
11 
12 // Dragon modified
13 static void __init ti816x_spi_init(void)
14 {
15         spi_register_board_info(fpga_spi_slave_info,
16                                 ARRAY_SIZE(fpga_spi_slave_info));
17 }

2、重新编译内核,同时选择生成spi设备驱动

 $ make menuconfig CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=arm

(1)Device drivers -> Memory tech... -> Self-contained --> 取消 support most spi Flash

影响:取消文件(/drivers/mtd/devices/mtd_m25p80.c)

(2)D-evice drivers --> SPI Support --> 勾选 Utilities & Mcspi driver & User mode SPI

影响:加入文件(/drivers/spi/spi_bitbang.c /drivers/spi/omap2_mcspi.c /drivers/spi/spidev.c)

linux-kenel/drivers/spidev.c 实现用户态spi设备驱动的功能

3、编译内核自带spi应用程序,验证SPI功能(注意MISO要与MOSI相连,以实现回环测试)如下:

linux-kenel\Documentation\spi\spidev_test.c

示波器截图,黄色为SCLK,蓝色为MOSI

发送数据与接收数据相同,则说明SPI通信成功!

 

 

posted @ 2015-03-18 18:55  Imapla  阅读(3160)  评论(0编辑  收藏  举报