hikey960 SPI调试进阶之进阶篇(1)  

分享到:

DragonCat
Level 2Admin
注册时间:7年 前
帖子数: 42
2017年6月21日 上午10:37  

  1. SPI回环测试

 

 

 

我们需要使用回环测试来测试SPI控制器是否能正常工作以及管脚是否配置正确。

 

 

 

配置dts

 

 

 

spi4: spi@fdf06000 {

 

compatible = "arm,pl022", "arm,primecell";

 

reg = <0x0 0xfdf06000 0x0 0x1000>;

 

#address-cells = <1>;

 

#size-cells = <0>;

 

interrupts = <0 313 4>;

 

clocks = <&crg_ctrl HI3660_CLK_GATE_SPI4>;

 

clock-names = "apb_pclk";

 

pinctrl-names = "default";

 

pinctrl-0 = <&spi4_pmx_func &spi4_cfg_func>;

 

num-cs = <1>;

 

cs-gpios = <&gpio27 2 0>; /*cs : 218*/

 

//status = "disabled";

 

status = "ok";

 

 

 

+spidev@0 {

 

+ compatible = "dcb,spidev";

 

+ reg = <0 0>;

 

+ spi-max-frequency = <9600000>;

 

+};

 

};

 

 

 

spidev.c 驱动文件中添加:

 

 

 

#ifdef CONFIG_OF

 

static const struct of_device_id spidev_dt_ids[] = {

 

{ .compatible = "rohm,dh2228fv" },

 

{ .compatible = "lineartechnology,ltc2488" },

 

+{ .compatible = "dcb,spidev" },

 

{},

 

};

 

 

 

这样就在spi bus上挂载了 匹配的驱动与设备,在/dev 下生成了SPI设备节点,如下图:

SPI回环测试硬件连接:将SPI2_DI SPI2_DO连接,即又发又收。

我们需要操作这个节点来实现回环测试,在android kernel代码中附带spi的测试程序,代码路径在/Documentation/spi/, 我们需要编译它,我们需要在/Documentation/spi/下增加Android.mk,如下:

 

 

 

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

 

LOCAL_SRC_FILES += spidev_test.c

 

LOCAL_MODULE:= spidev_test

 

include $(BUILD_EXECUTABLE)

 

 

 

/Documentation/spi/路径下执行mm,在out/target/product/hikey960/system/bin/下生成

 

spidev_test

运行spidev_test,如下图:

运行结果:RX接收的数据与TX发送的数据是一样的。

 

结论:SPI管脚配置正确;SPI控制器也OK.

 

 

 

备注:./spidev_test -D /dev/spidev32766.0 -s (SPI速率)

 

 

 

 

 

 


回复引用
cl0603413
Level 0
注册时间:7年 前
帖子数: 2
2017年6月21日 下午4:22  

能否给出配置dts:以及spidev.c 驱动文件的在aosp中的具体文件路径啊

谢谢~


回复引用
wolfkin
Level 2Admin
注册时间:7年 前
帖子数: 27
2017年6月21日 下午5:39  

这写代码都是在kernel里面的

dts在hikey-linaro\arch\arm64\boot\dts\hisilicon\中

spi相关代码在hikey-linaro\drivers\spi中


回复引用
cl0603413
Level 0
注册时间:7年 前
帖子数: 2
2017年6月22日 上午9:42  

确认下啊:

 

1.dts在hikey-linaro\arch\arm64\boot\dts\hisilicon\中的hi3660-hikey960.dts文件吧?

2.spidev.c相关代码在hikey-linaro\drivers\spi中的spidev.c文件吧?


回复引用
DragonCat
Level 2Admin
注册时间:7年 前
帖子数: 42
2017年6月22日 上午11:21  

hikey960 dts在hikey-linaro\arch\arm64\boot\dts\hisilicon\,   spi 配置部分在hi3660.dtsi

spidev.c相关代码是在hikey-linaro\drivers\spi中的spidev.c。


回复引用
  
Working

登陆 或者 注册