一、 准备工作
NXP源码路径:ELF1开发板资料包7-NXP 原厂资料7-1 NXP官方源码linux-imx-imx_4.1.15_2.0.0_ga.tar.bz2
1、将NXP源码拷贝到开发环境home/root/work目录下解压
elf@ubuntu:~/work$ tar jvxf linux-imx-imx_4.1.15_2.0.0_ga.tar.bz2
elf@ubuntu:~/work$ cd linux-imx-imx_4.1.15_2.0.0_ga/
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ ls
2、添加默认配置文件
将arch/arm/configs路径下的imx_v7_mfg_defconfig复制一份,命名为imx6ull_elf1_defconfig:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ cp arch/arm/configs/imx_v7_mfg_defconfig arch/arm/configs/imx6ull_elf1_defconfig
3、添加ELF 1设备树
将arch/arm/boot/dts路径下的imx6ull-14x14-evk.dts复制一份,命名为imx6ull-elf1-emmc.dts:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ cp arch/arm/boot/dts/imx6ull-14x14-evk.dts arch/arm/boot/dts/imx6ull-elf1-emmc.dts
打开arch/arm/boot/dts/Makefile,找到CONFIG_SOC_IMX6ULL,将imx6ull-elf1-emmc.dts添加到Makefile中:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vi arch/arm/boot/dts/Makefile
4、建立交叉编译脚本
建立一个编译脚本build.sh
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vim build.sh
#!/bin/bash
export CPUS=`grep -c processor /proc/cpuinfo`
source /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
make distclean
make imx6ull_elf1_defconfig
make -j${CPUS}
rm -rf ./.tmp
make modules_install INSTALL_MOD_PATH=./.tmp/rootfs/
cd .tmp/rootfs/
tar -jcvf modules.tar.bz2 *
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ chmod 777 build.sh
二、适配六轴传感器
SPI是串行外设接口(Serial Peripheral Interface)的缩写,是一种高速的,全双工,同步的通信总线。SPI的通信以主从方式工作,一般需要4根线,MISO(主设备数据输入)、MOSI(主设备数据输出)、SCLK(时钟)、CS(片选)。i.MX6ULL有4路SPI接口,ELF 1开发板使用了SPI1连接到六轴传感器icm20607上。
1、硬件原理
2、IOMUX配置
在arch/arm/boot/dts/imx6ul-pinfunc.h中找到相关宏:
MX6UL_PAD_LCD_DATA20__ECSPI1_SCLK
MX6UL_PAD_LCD_DATA21__GPIO3_IO26
MX6UL_PAD_LCD_DATA22__ECSPI1_MOSI
MX6UL_PAD_LCD_DATA23__ECSPI1_MISO
pinctrl_ecspi1: ecspi1grp {
fsl,pins = <
MX6UL_PAD_LCD_DATA20__ECSPI1_SCLK 0x10b0
MX6UL_PAD_LCD_DATA21__GPIO3_IO26 0x10b0
MX6UL_PAD_LCD_DATA22__ECSPI1_MOSI 0x10b0
MX6UL_PAD_LCD_DATA23__ECSPI1_MISO 0x10b0
>;
};
效果如下:
在添加IOMUX之后,需要检查设备树是否有其它地方复用了LCD_DATA20,LCD_DATA21,LCD_DATA22,LCD_DATA23。
打开arch/arm/boot/dts/imx6ull-elf1-emmc.dts文件,搜索引脚PAD NAME,在&iomux的子节点pinctrl_lcdif_dat节点下搜索到以下几个引脚的复用,将其注释掉:
/* MX6UL_PAD_LCD_DATA20__LCDIF_DATA20 0x79
MX6UL_PAD_LCD_DATA21__LCDIF_DATA21 0x79
MX6UL_PAD_LCD_DATA22__LCDIF_DATA22 0x79
MX6UL_PAD_LCD_DATA23__LCDIF_DATA23 0x79 */
3、设备节点配置
&ecspi1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_ecspi1>;
fsl,spi-num-chipselects = <1>;
cs-gpios = <&gpio3 26 GPIO_ACTIVE_LOW>;
status = "okay";
spidevicm: icm20607@0{
compatible = "elf,icm20607";
spi-max-frequency = <8000000>;
reg = <0>;
};
};
效果如下:
4、添加icm20607驱动
(2)将ELF1开发板资料包2-Linux 源代码2-1 驱动源码1_icm20607icm20607.h拷贝到内核源码的include/linux路径下。
(3)修改Kconfig
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vi drivers/misc/Kconfig
添加以下内容:
config ICM20607
tristate "SPI device ICM20607"
depends on SPI && SYSFS
help
If you say yes here,you get support for the icm20607
(4)修改Makefile
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vi drivers/misc/Makefile
添加以下内容:
obj-$(CONFIG_ICM20607) += icm20607.o
效果如下:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ make menuconfig
Device Drivers
-> Misc devices
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ cp .config arch/arm/configs/imx6ull_elf1_defconfig
5、编译
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ ./build.sh
将编译生成的zImage和imx6ull-elf-emmc.dtb拷贝到ELF 1开发板的/run/media/mmcblk1p1 路径下:
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ scp arch/arm/boot/zImage root@172.16.0.175:/run/media/mmcblk1p1/
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ scp arch/arm/boot/dts/imx6ull-elf1-emmc.dtb root@172.16.0.175:/run/media/mmcblk1p1/
root@ELF1~# sync
root@ELF1~# reboot
三、六轴传感器测试
1、查看/dev下是否生成了设备节点,若生成则表示驱动适配成功
2、使用以下测试程序测试六轴传感器是否可以正确读到数据。
root@ELF1:~# elf1_cmd_icm20607