一、 準(zhǔn)備工作
NXP源碼路徑:ELF1開發(fā)板資料包7-NXP 原廠資料7-1 NXP官方源碼linux-imx-imx_4.1.15_2.0.0_ga.tar.bz2
1、將NXP源碼拷貝到開發(fā)環(huán)境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、添加默認(rèn)配置文件
將arch/arm/configs路徑下的imx_v7_mfg_defconfig復(fù)制一份,命名為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設(shè)備樹
將arch/arm/boot/dts路徑下的imx6ull-14x14-evk.dts復(fù)制一份,命名為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、建立交叉編譯腳本
建立一個(gè)編譯腳本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是串行外設(shè)接口(Serial Peripheral Interface)的縮寫,是一種高速的,全雙工,同步的通信總線。SPI的通信以主從方式工作,一般需要4根線,MISO(主設(shè)備數(shù)據(jù)輸入)、MOSI(主設(shè)備數(shù)據(jù)輸出)、SCLK(時(shí)鐘)、CS(片選)。i.MX6ULL有4路SPI接口,ELF 1開發(fā)板使用了SPI1連接到六軸傳感器icm20607上。
1、硬件原理
2、IOMUX配置
在arch/arm/boot/dts/imx6ul-pinfunc.h中找到相關(guān)宏:
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之后,需要檢查設(shè)備樹是否有其它地方復(fù)用了LCD_DATA20,LCD_DATA21,LCD_DATA22,LCD_DATA23。
打開arch/arm/boot/dts/imx6ull-elf1-emmc.dts文件,搜索引腳PAD NAME,在&iomux的子節(jié)點(diǎn)pinctrl_lcdif_dat節(jié)點(diǎn)下搜索到以下幾個(gè)引腳的復(fù)用,將其注釋掉:
/* 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、設(shè)備節(jié)點(diǎn)配置
&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驅(qū)動(dòng)
?
(2)將ELF1開發(fā)板資料包2-Linux 源代碼2-1 驅(qū)動(dòng)源碼1_icm20607icm20607.h拷貝到內(nèi)核源碼的include/linux路徑下。
?
(3)修改Kconfig
elf@ubuntu:~/work/linux-imx-imx_4.1.15_2.0.0_ga$ vi drivers/misc/Kconfig
?
添加以下內(nèi)容:
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
?
添加以下內(nèi)容:
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開發(fā)板的/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下是否生成了設(shè)備節(jié)點(diǎn),若生成則表示驅(qū)動(dòng)適配成功
2、使用以下測試程序測試六軸傳感器是否可以正確讀到數(shù)據(jù)。
root@ELF1:~# elf1_cmd_icm20607