OK6410A SPI驱动测试的应用程序

官网的的包里的代码是正常且可以用的,后来又搜索到文中的测试代码,决定更符合应用习惯,于是测试一下,并把详细的测试步骤记录下来...

代码来自网络:

感谢作者的劳动及奉献精神

编译后,在板子上测试,开始效果如下:

<span style="font-family: Arial, Helvetica, sans-serif;">....
setup status = 0</span>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi0.0: 12000000 Hz (max)

spi mode: 0
bits per word: 8
max speed: 11083 KHz (11 MHz)

SPI - LookBack Mode Test...

Error:
File:<SpiDev.c> Fun:[SPI_LookBackTest] Line:259
 LookBack Mode Test error
[root@FORLINX6410]# ls
有错误提示...

查看代码后,决定将调试信息打印出来


将代码调试状态置 “1”

调整后

运行结果:


SPI - Open Succeed. Start Init SPI...spidev spi0.0: setup mode 0, 8 bits/w, 4750000 Hz max --> 0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setup status = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi0.0: spi mode 00
spidev spi0.0: setup mode 0, 8 bits/w, 4750000 Hz max --> 0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setup status = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi0.0: 8 bits per word
spidev spi0.0: setup mode 0, 8 bits/w, 4750000 Hz max --> 0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setup status = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi0.0: 5000000 Hz (max)

spi mode: 0
bits per word: 8
max speed: 4750 KHz (4 MHz)

SPI - LookBack Mode Test...

send spi message Succeed
SPI Send [Len:16]: 
        0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 
        0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 
SPI Receive [len:16]:
        0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 
        0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 

Error:
File:<SpiDev.c> Fun:[SPI_LookBackTest] Line:259
 LookBack Mode Test error

打印结果一看,错误很明显:发送和接受结果不一致,所以报错


开始没整明白,到底咋回事?

正常情况下,贴出来的代码肯定是不会有问题的,因为作者没有必要这么整。

因此,出问题时,首先要肯怀疑自己,肯定是自己的原因导致出了问题...


想了想,貌似也只有打开的设备时有问题...

按照这个思路修改


static const char *device = "/dev/spidev1.0";

果然

修改打开设备字符串后,结果如下:


[root@FORLINX6410]# ./spi                
SPI - Open Succeed. Start Init SPI...spidev spi1.0: setup mode 0, 8 bits/w, 496268 Hz max --> 0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setup status = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi1.0: spi mode 00
spidev spi1.0: setup mode 0, 8 bits/w, 496268 Hz max --> 0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setup status = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi1.0: 8 bits per word
spidev spi1.0: setup mode 0, 8 bits/w, 11083333 Hz max --> 0

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
setup status = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
spidev spi1.0: 12000000 Hz (max)

spi mode: 0
bits per word: 8
max speed: 11083 KHz (11 MHz)

SPI - LookBack Mode Test...

send spi message Succeed
SPI Send [Len:16]: 
        0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 
        0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 
SPI Receive [len:16]:
        0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 
        0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 
SPI - LookBack Mode  OK

至此,终于OK了


PS:

   SPI驱动的实现或者说修改还没整理,在ubuntu上还,其实也不复杂,具体方法网络上也能搜索的到。

想整理得看得顺溜,还是要花点时间的,因为不是虚拟机上装的ubuntu,截图麻烦... 尽快抽空整理整理也... 



本不想把代码贴出来,考虑到原作者代码页面乱码加上下载附件需要注册,于是就把作者的代码贴出来了


/*
 * 说明:SPI通讯实现
 *	       方式一: 同时发送与接收实现函数: SPI_Transfer()
 *	       方式二:发送与接收分开来实现
 *	       SPI_Write() 只发送
 *	       SPI_Read()  只接收
 *	       两种方式不同之处:方式一,在发的过程中也在接收,第二种方式,收与发单独进行
 *  Created on: 2013-5-28
 *      Author: lzy
 */

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>

#include "Debug.h"
#define SPI_DEBUG 0

static const char *device = "/dev/spidev0.0";
static uint8_t mode = 0; /* SPI通信使用全双工,设置CPOL=0,CPHA=0。 */
static uint8_t bits = 8; /* 8bits读写,MSB first。*/
static uint32_t speed = 12 * 1000 * 1000;/* 设置12M传输速度 */
static uint16_t delay = 0;
static int g_SPI_Fd = 0;

static void pabort(const char *s)
{
	perror(s);
	abort();
}

/**
 *  功 能:同步数据传输
 * 入口参数 :
 * 			TxBuf -> 发送数据首地址
 * 			len -> 交换数据的长度
 * 出口参数:
 * 			RxBuf -> 接收数据缓冲区
 * 返回值:0 成功
 * 开发人员:Lzy 2013-5-22
 */
int SPI_Transfer(const uint8_t *TxBuf, uint8_t *RxBuf, int len)
{
	int ret;
	int fd = g_SPI_Fd;

	struct spi_ioc_transfer tr =	{
			.tx_buf = (unsigned long) TxBuf,
			.rx_buf = (unsigned long) RxBuf,
			.len =	len,
			.delay_usecs = delay,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pr_err("can't send spi message");
	else
	{
#if SPI_DEBUG
		int i;
		pr_debug("\nsend spi message Succeed");
		pr_debug("\nSPI Send [Len:%d]: ", len);
		for (i = 0; i < len; i++)
		{
			if (i % 8 == 0)
			printf("\n\t");
			printf("0x%02X ", TxBuf[i]);
		}
		printf("\n");

		pr_debug("SPI Receive [len:%d]:", len);
		for (i = 0; i < len; i++)
		{
			if (i % 8 == 0)
			printf("\n\t");
			printf("0x%02X ", RxBuf[i]);
		}
		printf("\n");
#endif
	}
	return ret;
}

/**
 * 功 能:发送数据
 * 入口参数 :
 * 			TxBuf -> 发送数据首地址
 *			len ->  发送与长度
 *返回值:0 成功
 * 开发人员:Lzy 2013-5-22
 */
int SPI_Write(uint8_t *TxBuf, int len)
{
	int ret;
	int fd = g_SPI_Fd;

	ret = write(fd, TxBuf, len);
	if (ret < 0)
		pr_err("SPI Write error\n");
	else
	{
#if SPI_DEBUG
		int i;
		pr_debug("\nSPI Write [Len:%d]: ", len);
		for (i = 0; i < len; i++)
		{
			if (i % 8 == 0)
			printf("\n\t");
			printf("0x%02X ", TxBuf[i]);
		}
		printf("\n");

#endif
	}

	return ret;
}

/**
 * 功 能:接收数据
 * 出口参数:
 * 		RxBuf -> 接收数据缓冲区
 * 		rtn -> 接收到的长度
 * 返回值:>=0 成功
 * 开发人员:Lzy 2013-5-22
 */
int SPI_Read(uint8_t *RxBuf, int len)
{
	int ret;
	int fd = g_SPI_Fd;
	ret = read(fd, RxBuf, len);
	if (ret < 0)
		pr_err("SPI Read error\n");
	else
	{
#if SPI_DEBUG
		int i;
		pr_debug("SPI Read [len:%d]:", len);
		for (i = 0; i < len; i++)
		{
			if (i % 8 == 0)
			printf("\n\t");
			printf("0x%02X ", RxBuf[i]);
		}
		printf("\n");
#endif
	}

	return ret;
}

/**
 * 功 能:打开设备  并初始化设备
 * 入口参数 :
 * 出口参数:
 * 返回值:0 表示已打开  0XF1 表示SPI已打开 其它出错
 * 开发人员:Lzy 2013-5-22
 */
int SPI_Open(void)
{
	int fd;
	int ret = 0;

	if (g_SPI_Fd != 0) /* 设备已打开 */
		return 0xF1;

	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("can't open device");
	else
		pr_debug("SPI - Open Succeed. Start Init SPI...\n");

	g_SPI_Fd = fd;
	/*
	 * spi mode
	 */
	ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
	if (ret == -1)
		pabort("can't set spi mode");

	ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
	if (ret == -1)
		pabort("can't get spi mode");

	/*
	 * bits per word
	 */
	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't set bits per word");

	ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't get bits per word");

	/*
	 * max speed hz
	 */
	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't set max speed hz");

	ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't get max speed hz");

	pr_debug("spi mode: %d\n", mode);
	pr_debug("bits per word: %d\n", bits);
	pr_debug("max speed: %d KHz (%d MHz)\n", speed / 1000, speed / 1000 / 1000);

	return ret;
}

/**
 * 功 能:关闭SPI模块
 */
int SPI_Close(void)
{
	int fd = g_SPI_Fd;

	if (fd == 0) /* SPI是否已经打开*/
		return 0;
	close(fd);
	g_SPI_Fd = 0;

	return 0;
}

/**
 * 功 能:自发自收测试程序
 * 		接收到的数据与发送的数据如果不一样 ,则失败
 * 说明:
 * 		在硬件上需要把输入与输出引脚短跑
 * 开发人员:Lzy 2013-5-22
 */
int SPI_LookBackTest(void)
{
	int ret, i;
	const int BufSize = 16;
	uint8_t tx[BufSize], rx[BufSize];

	bzero(rx, sizeof(rx));
	for (i = 0; i < BufSize; i++)
		tx[i] = i;

	pr_debug("\nSPI - LookBack Mode Test...\n");
	ret = SPI_Transfer(tx, rx, BufSize);
	if (ret > 1)
	{
		ret = memcmp(tx, rx, BufSize);
		if (ret != 0)
		{
			pr_err("LookBack Mode Test error\n");
//			pabort("error");
		}
		else
			pr_debug("SPI - LookBack Mode  OK\n");
	}

	return ret;
}

int main(int argc, char *argv[])
{
	int ret = 0;

	ret = SPI_Open();
	if (ret)
		return ret;

	SPI_LookBackTest();

//	unsigned char buf[10];
//	SPI_Write(buf, 10);
//	SPI_Read(buf, 10);

	SPI_Close();

return 0;
}

/*
 * Debug.h
 * 摘要:用于打印调试信息
 * 		为了统一控制打印信息是否输出,而用宏定义的打印函数。同时也可以起到开发版本与发布版本是同一个版本
 *  Created on: 2013-5-22
 *      Author: lzy
 */

#ifndef DEBUG_H_
#define DEBUG_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#define 	DEBUG_SWITCH	1		/* 打开调试信息打印功能 */
#define     ERR_DEBUG_SWITCH	1	/* 打印错误信息打印功能 */

/**
 * 简单打印调试信息
 */
#if    DEBUG_SWITCH
#define pr_debug(fmt,args...) printf(fmt, ##args)
#else
#define pr_debug(fmt,args...) /*do nothing */
#endif

/**
 * 错误信息打印
 * 自动打印发生错误时代码所在的位置
 */
#if    ERR_DEBUG_SWITCH
#define pr_err(fmt,args...) printf("\nError:\nFile:<%s> Fun:[%s] Line:%d\n "fmt, __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define pr_err(fmt,args...) /*do nothing */
#endif

#endif /* DEBUG_H_ */




  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
全志R40平台的tinav2.1系统下打开SPI2接口 1、(可选修改) Q:\r40_tinav2.1\spi20_r40_tinav2.1\lichee\brandy\build.sh build_uboot() { if [ "x${PLATFORM}" = "xsun50iw1p1" ] || \ [ "x${PLATFORM}" = "xsun50iw2p1" ] || \ [ "x${PLATFORM}" = "xsun50iw6p1" ] || \ [ "x${PLATFORM}" = "xsun50iw3p1" ] || \ [ "x${PLATFORM}" = "xsun8iw12p1" ] || \ [ "x${PLATFORM}" = "xsun8iw10p1" ] || \ [ "x${PLATFORM}" = "xsun8iw11p1" ]; then cd u-boot-2014.07/ else cd u-boot-2011.09/ fi make distclean if [ "x$MODE" = "xota_test" ] ; then export "SUNXI_MODE=ota_test" fi make ${PLATFORM}_config make -j16 #make spl #make fes if [ ${PLATFORM} = "sun8iw11p1" ]; then make distclean make ${PLATFORM}_nor_config make -j16 #make spl #make fes fi cd - 1>/dev/null } 2、 Q:\r40_tinav2.1\spi20_r40_tinav2.1\lichee\linux-3.10\drivers\spi\spidev.c static struct spi_driver spidev_spi_driver = { .driver = { .name = "spidev", .owner = THIS_MODULE, .of_match_table = of_match_ptr(spidev_dt_ids), }, .probe = spidev_probe, .remove = 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. */ }; 3、验证APP程序: Q:\r40_tinav2.1\spi20_r40_tinav2.1\package\allwinner\spidev20_test\Makefile ############################################## # OpenWrt Makefile for helloworld program # # # Most of the variables used here are defined in # the include directives below. We just need to # specify a basic description of the package, # where to build our program, where to find # the source files, and where to install the # compiled program on the router. # # Be very careful of spacing in this file. # Indents should be tabs, not spaces, and # there should be no trailing whitespace in # lines that are not commented. # ############################################## include $(TOPDIR)/rules.mk # Name and release number of this package PKG_NAME:=spidev20_test PKG_VERSION:=0.0.1 PKG_RELEASE:=1 # This specifies the directory where we're going to build the program. # The root build directory, $(BUILD_DIR), is by default the build_mipsel # directory in your OpenWrt SDK directory PKG_BUILD_DIR := $(COMPILE_DIR)/$(PKG_NAME) include $(BUILD_DIR)/package.mk # Specify package information for this program. # The variables defined here should be self explanatory. # If you are running Kamikaze, delete the DESCRIPTION # variable below and uncomment the Kamikaze define # directive for the description below define Package/spidev20_test SECTION:=utils CATEGORY:=Allwinner TITLE:=spidev20_test just test the SPI2 interface DEPENDS:=+libpthread endef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above define Package/spidev20_test/description If you can't figure out what this program does, you're probably brain-dead and need immediate medical attention. endef # Specify what needs to be done to prepare for building the package. # In our case, we need to copy the source files to the build directory. # This is NOT the default. The default uses the PKG_SOURCE_URL and the # PKG_SOURCE which is not defined here to download the source from the web. # In order to just build a simple program that we have just written, it is # much easier to do it this way. define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ endef define Build/Configure endef define Build/Compile $(MAKE) -C $(PKG_BUILD_DIR) \ CC="$(TARGET_CC)" \ CFLAGS="$(TARGET_CFLAGS)" -Wall \ LDFLAGS="$(TARGET_LDFLAGS)" \ LIBS="-lpthread" \ all endef # We do not need to define Build/Configure or Build/Compile directives # The defaults are appropriate for compiling a simple program such as this one # Specify where and how to install the program. Since we only have one file, # the helloworld executable, install it by copying it to the /bin directory on # the router. The $(1) variable represents the root directory on the router running # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install # directory if it does not already exist. Likewise $(INSTALL_BIN) contains the # command to copy the binary file from its current location (in our case the build # directory) to the install directory. define Package/spidev20_test/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/spidev20_test $(1)/bin/ endef # This line executes the necessary commands to compile our program. # The above define directives specify all the information needed, but this # line calls BuildPackage which in turn actually uses this information to # build a package. $(eval $(call BuildPackage,spidev20_test)) Q:\r40_tinav2.1\spi20_r40_tinav2.1\package\allwinner\spidev20_test\src\Makefile TARGET = spidev20_test INCLUDES += -I. -Icommon/ LIBS += -lpthread -lm -lrt SRCS = spidev20_test.c OBJS = $(SRCS:.c=.o) %.o: %.c $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) all:$(TARGET) clean: rm -rf $(TARGET) *.o *.a *~ cd common && rm -f *.o *.a *.bak *~ .depend Q:\r40_tinav2.1\spi20_r40_tinav2.1\package\allwinner\spidev20_test\src\spidev20_test.c /* * SPI testing utility (using spidev driver) * * Copyright (c) 2007 MontaVista Software, Inc. * Copyright (c) 2007 Anton Vorontsov <avorontsov@ru.mvista.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License. * * Cross-compile with cross-gcc -I/path/to/cross-kernel/include */ #include <stdint.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/types.h> #include <linux/spi/spidev.h> #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static void pabort(const char *s) { perror(s); abort(); } //static const char *device = "/dev/spidev0.0"; //static const char *device = "/dev/spidev0.1"; static const char *device = "/dev/spidev2.0"; static uint8_t mode; static uint8_t bits = 8; static uint32_t speed = 500000; static uint16_t delay; static void transfer(int fd) { int ret; //uint8_t tx[] = { // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, // 0xF0, 0x0D, //}; // CityBrand WelCome U! uint8_t tx[] = { 0x43, 0x69, 0x74, 0x79, 0x42, 0x72, 0x61, 0x6E, 0x64, 0x20, 0x57, 0x65, 0x6C, 0x43, 0x6F, 0x6D, 0x65, 0x20, 0x55, 0x21, 0x43, 0x69, 0x74, 0x79, 0x42, 0x72, 0x61, 0x6E, 0x64, 0x20, 0x57, 0x65, 0x6C, 0x43, 0x6F, 0x6D, 0x65, 0x20, 0x55, 0x21, 0x43, 0x69, 0x74, 0x79, 0x42, 0x72, 0x61, 0x6E, 0x64, 0x20, 0x57, 0x65, 0x6C, 0x43, 0x6F, 0x6D, 0x65, 0x20, 0x55, 0x21, }; uint8_t rx[ARRAY_SIZE(tx)] = {0, }; struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, .len = ARRAY_SIZE(tx), .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, }; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr;); if (ret < 1) pabort("can't send spi message"); for (ret = 0; ret < ARRAY_SIZE(tx); ret++) { //if (!(ret % 6)) // puts(" "); //printf("%.2X ", rx[ret]); if (!(ret % 20)){ puts("\n"); } printf("%c", rx[ret]); } //puts(""); puts("\n"); } static void print_usage(const char *prog) { printf("Usage: %s [-DsbdlHOLC3]\n", prog); puts(" -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" " -d --delay delay (usec)\n" " -b --bpw bits per word \n" " -l --loop loopback\n" " -H --cpha clock phase\n" " -O --cpol clock polarity\n" " -L --lsb least significant bit first\n" " -C --cs-high chip select active high\n" " -3 --3wire SI/SO signals shared\n"); exit(1); } static void parse_opts(int argc, char *argv[]) { while (1) { static const struct option lopts[] = { { "device", 1, 0, 'D' }, { "speed", 1, 0, 's' }, { "delay", 1, 0, 'd' }, { "bpw", 1, 0, 'b' }, { "loop", 0, 0, 'l' }, { "cpha", 0, 0, 'H' }, { "cpol", 0, 0, 'O' }, { "lsb", 0, 0, 'L' }, { "cs-high", 0, 0, 'C' }, { "3wire", 0, 0, '3' }, { "no-cs", 0, 0, 'N' }, { "ready", 0, 0, 'R' }, { NULL, 0, 0, 0 }, }; int c; c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR", lopts, NULL); if (c == -1) break; switch (c) { case 'D': device = optarg; break; case 's': speed = atoi(optarg); break; case 'd': delay = atoi(optarg); break; case 'b': bits = atoi(optarg); break; case 'l': mode |= SPI_LOOP; break; case 'H': mode |= SPI_CPHA; break; case 'O': mode |= SPI_CPOL; break; case 'L': mode |= SPI_LSB_FIRST; break; case 'C': mode |= SPI_CS_HIGH; break; case '3': mode |= SPI_3WIRE; break; case 'N': mode |= SPI_NO_CS; break; case 'R': mode |= SPI_READY; break; default: print_usage(argv[0]); break; } } } int main(int argc, char *argv[]) { int ret = 0; int fd; parse_opts(argc, argv); fd = open(device, O_RDWR); if (fd < 0) pabort("can't open device"); /* * spi mode */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode;); if (ret == -1) pabort("can't set spi mode"); ret = ioctl(fd, SPI_IOC_RD_MODE, &mode;); if (ret == -1) pabort("can't get spi mode"); /* * bits per word */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits;); if (ret == -1) pabort("can't set bits per word"); ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits;); if (ret == -1) pabort("can't get bits per word"); /* * max speed hz */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed;); if (ret == -1) pabort("can't set max speed hz"); ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed;); if (ret == -1) pabort("can't get max speed hz"); printf("spi mode: %d\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); transfer(fd); close(fd); return ret; } 4、修改配置文件: Q:\r40_tinav2.1\spi20_r40_tinav2.1\target\allwinner\azalea-m2ultra\configs\sys_config.fex [jtag_para] jtag_enable = 1 jtag_ms = port:PB14<3><default><default><default> jtag_ck = port:PB15<3><default><default><default> jtag_do = port:PB16<3><default><default><default> jtag_di = port:PB17<3><default><default><default> 修改为: [jtag_para] jtag_enable = 0 ;jtag_ms = port:PB14<3><default><default><default> ;jtag_ck = port:PB15<3><default><default><default> ;jtag_do = port:PB16<3><default><default><default> ;jtag_di = port:PB17<3><default><default><default> ;---------------------------------------------------------------------------------- ;SPI controller configuration ;---------------------------------------------------------------------------------- [spi0] spi0_used = 0 spi0_cs_number = 2 spi0_cs_bitmap = 3 spi0_cs0 = port:PC23<3><1><default><default> spi0_cs1 = port:PI14<2><1><default><default> spi0_sclk = port:PC2<3><default><default><default> spi0_mosi = port:PC0<3><default><default><default> spi0_miso = port:PC1<3><default><default><default> [spi1] spi1_used = 0 spi1_cs_number = 2 spi1_cs_bitmap = 3 spi1_cs0 = port:PA0<3><1><default><default> spi1_cs1 = port:PA4<3><1><default><default> spi1_sclk = port:PA1<3><default><default><default> spi1_mosi = port:PA2<3><default><default><default> spi1_miso = port:PA3<3><default><default><default> [spi2] spi2_used = 0 spi2_cs_number = 2 spi2_cs_bitmap = 3 spi2_cs0 = port:PB14<2><1><default><default> spi2_cs1 = port:PB13<2><1><default><default> spi2_sclk = port:PB15<2><default><default><default> spi2_mosi = port:PB16<2><default><default><default> spi2_miso = port:PB17<2><default><default><default> [spi3] spi3_used = 0 spi3_cs_number = 2 spi3_cs_bitmap = 3 spi3_cs0 = port:PA5<3><1><default><default> spi3_cs1 = port:PA9<3><1><default><default> spi3_sclk = port:PA6<3><default><default><default> spi3_mosi = port:PA7<3><default><default><default> spi3_miso = port:PA8<3><default><default><default> ;---------------------------------------------------------------------------------- ;SPI device configuration ;compatible --- device name ;spi-max-frequency --- work frequency ;reg --- chip select ;optional properties: spi-cpha, spi-cpol, spi-cs-high ;---------------------------------------------------------------------------------- ;[spi0/spi_board0] ;compatible = ;spi-max-frequency = ;reg = ;spi-cpha ;spi-cpol ;spi-cs-high 修改为: ;---------------------------------------------------------------------------------- ;SPI controller configuration ;---------------------------------------------------------------------------------- ;spi0有接SPI器件(和PC引脚和NAND冲突),但是空贴! [spi0] spi0_used = 0 spi0_cs_number = 2 spi0_cs_bitmap = 3 spi0_cs0 = port:PC23<3><1><default><default> spi0_cs1 = port:PI14<2><1><default><default> spi0_sclk = port:PC2<3><default><default><default> spi0_mosi = port:PC0<3><default><default><default> spi0_miso = port:PC1<3><default><default><default> ;和gmac0复用冲突了! [spi1] spi1_used = 0 spi1_cs_number = 2 spi1_cs_bitmap = 3 spi1_cs0 = port:PA0<3><1><default><default> spi1_cs1 = port:PA4<3><1><default><default> spi1_sclk = port:PA1<3><default><default><default> spi1_mosi = port:PA2<3><default><default><default> spi1_miso = port:PA3<3><default><default><default> ;大排针J9引出来了! [spi2] spi2_used = 1 spi2_cs_number = 2 spi2_cs_bitmap = 3 spi2_cs0 = port:PB14<2><1><default><default> spi2_cs1 = port:PB13<2><1><default><default> spi2_sclk = port:PB15<2><default><default><default> spi2_mosi = port:PB16<2><default><default><default> spi2_miso = port:PB17<2><default><default><default> ;和gmac0复用冲突了! [spi3] spi3_used = 0 spi3_cs_number = 2 spi3_cs_bitmap = 3 spi3_cs0 = port:PA5<3><1><default><default> spi3_cs1 = port:PA9<3><1><default><default> spi3_sclk = port:PA6<3><default><default><default> spi3_mosi = port:PA7<3><default><default><default> spi3_miso = port:PA8<3><default><default><default> ;---------------------------------------------------------------------------------- ;SPI device configuration ;compatible --- device name ;spi-max-frequency --- work frequency ;reg --- chip select ;optional properties: spi-cpha, spi-cpol, spi-cs-high ;---------------------------------------------------------------------------------- ;[spi0/spi_board0] ;compatible = ;spi-max-frequency = ;reg = ;spi-cpha ;spi-cpol ;spi-cs-high [spi2/spi_board2] compatible = "spidev" spi-max-frequency = 50000000 reg = 0 ;spi-cpha = 0 ;spi-cpol = 0 ;spi-cs-high = 0 5、刷机之后: root@TinaLinux:/# root@TinaLinux:/# find . -name spi* ./bin/spidev20_test ./dev/spidev2.0 ./proc/irq/44/spi2 ./rom/bin/spidev20_test ./rom/usr/lib/opkg/info/spidev20_test.control ./rom/usr/lib/opkg/info/spidev20_test.list ./sys/bus/spi ./sys/bus/spi/devices/spi2.0 ./sys/bus/spi/drivers/spidev ./sys/bus/spi/drivers/spidev/spi2.0 ./sys/bus/platform/devices/spi2 ./sys/bus/platform/drivers/spi ./sys/bus/platform/drivers/spi/spi2 ./sys/devices/soc/spi2 ./sys/devices/soc/spi2/spi_master ./sys/devices/soc/spi2/spi_master/spi2 ./sys/devices/soc/spi2/spi_master/spi2/spi2.0 ./sys/devices/soc/spi2/spi_master/spi2/spi2.0/spidev ./sys/devices/soc/spi2/spi_master/spi2/spi2.0/spidev/spidev2.0 ./sys/class/spi_master ./sys/class/spi_master/spi2 ./sys/class/spidev ./sys/class/spidev/spidev2.0 ./sys/kernel/debug/clk/hosc/pll_periph0/spi2 ./sys/kernel/debug/clk/hosc/spi0 ./sys/kernel/debug/clk/hosc/spi1 ./sys/kernel/debug/clk/hosc/spi3 ./sys/module/spidev ./usr/lib/opkg/info/spidev20_test.control ./usr/lib/opkg/info/spidev20_test.list root@TinaLinux:/# root@TinaLinux:/#

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值