部署开发环境:开发前需要PC安装好Linux操作系统,推荐使用Ubuntu 16.04 64bit发行版,连接网线并配置好网络,后续操作需要连接互联网安装或下载相关软件包。
本章主要介绍MYD-Y6ULX开发板底板外围硬件设备应用例程的使用。
使用前,需要先安装Yocto提供的SDK工具链,再编译所有例程代码,并拷贝至开发板目录下。
编译应用例程
加载工具链到当前终端后,可以查看gcc的版本信息,确认当前环境已正确加载。
$source /opt/myir-imx6ulx-fb/4.1.15-2.0.1/environment-setup-cortexa7hf-neon-
poky-linux-gnueabi
$ ARM-poky-linux-gnueabi-gcc --version
arm-poky-linux-gnueabi-gcc (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
编译示例代码:
$cd $DEV_ROOT/04-Sources
$tar xvf example.tar.gz
$cd example
$make
Ethernet 测试
本例使用Linux sokect API,实现简单的C/S结构的程序,两个程序通过TCP/IP协议栈通信。将可执行程序arm_client拷贝至开发板,pc_server拷贝
至PC,将开发板和PC接入网络。
在 PC 上配置IP并运行服务程序:
$ sudo ifconfig eth0 192.168.1.111
$ ./pc_server
REC FROM: 192.168.1.222
在开发板上运行客户程序,将看到所发送的信息:
# ifconfig eth0 192.168.1.222
# ./arm_client 192.168.1.111
form server: Make Your idea Real!
GPIO-KEY 测试
本例演示如何在Linux用户空间读取按键状态和键值。运行gpio_key程序后,按下或释放S2按键,串口会输出相应按键的状态信息。按下"Ctrl-C"可
退出程序。
在开发板的控制终端上执行程序:
# ./gpio_key /dev/input/event2
Hit any key on board ......
key 2 Pressed
key 2 Released
key 2 Pressed
key 2 Released
GPIO-LED 测试
本例程演示使用Linux系统API操作开发板上的LED灯,D30。运行程序后,D30闪烁。按下"Ctrl-C"可结束程序。
# ./gpio_led /sys/class/leds/user/brightness
USB Host 测试
使用USB存储设备插入USB HOST(J6)接口,调试串口会输出检测设备信息。同时,使用将此存储设备挂载至linux系统下对其读写。
# u*** 1-2: USB disconnect, device number 6
u*** 1-2: new high-speed USB device number 7 using atmel-ehci
u*** 1-2: New USB device found, idVendor=0bda, idProduct=0316
u*** 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
u*** 1-2: Product: USB3.0-CRW
u*** 1-2: Manufacturer: Generic
u*** 1-2: SerialNumber: 20120501030900000
u***-storage 1-2:1.0: USB Mass Storage device detected
scsi host5: u***-storage 1-2:1.0
scsi 5:0:0:0: Direct-Access Generic- SD/MMC 1.00 PQ:
0 ANSI: 4
sd 5:0:0:0: [sda] 31116288 512-byte logical blocks: (15.9 GB/14.8
GiB)
sd 5:0:0:0: [sda] Write Protect is off
sd 5:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't
support DPO or FUA
sda: sda1 sda2
sd 5:0:0:0: [sda] Attached SCSI removable disk
# mount /dev/sda1 /mnt/
# echo "hello" > /mnt/hello.txt
# cat
USB Device测试
本例程演示使用开发板的Micro USB接口(J26)作为Device模式,可以将指定的文件或设备模拟为设备,连接到其它USB HOST设备。这里把内存作为
存储设备提供给HOST设备。
开发板上使用modprobe加载驱动:
#mkfs.vfat /dev/ram1
#modprobe g_mass_storage file=/dev/ram1 removable=1
iSerialNumber="1234"
[ 3048.950498] Mass Storage Function, version: 2009/09/11
[ 3048.982245] LUN: removable file: (no medium)
[ 3048.997849] LUN: removable file: /dev/ram1
[ 3049.000674] Number of LUNs=1
[ 3049.002272] Number of LUNs=1
[ 3049.023990] g_mass_storage gadget: Mass Storage Gadget,
version: 2009/09/11
[ 3049.029682] g_mass_storage gadget: g_mass_storage ready
[ 3094.766373] g_mass_storage gadget: high-speed config
#1: Linux File-Backed Storage
Linux PC机上查看到有USB设备接入,SerialNumber为"1234",Manufacturer是内核构建版本号:
#dmesg | tail -n 20
[2872436.778616] u*** 1-1: USB disconnect, device number 102
[2872436.779156] sd 3:0:0:0: [sdb] Synchronizing SCSI cache
[2872436.779201] sd 3:0:0:0: [sdb] Synchronize Cache(10)
failed: Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
[2872442.508567] u*** 1-1: new high-speed USB device number 103
using xhci_hcd
[2872442.650549] u*** 1-1: New USB device found, idVendor=0525,
idProduct=a4a5
[2872442.650551] u*** 1-1: New USB device strings: Mfr=3, Produ
ct=4, SerialNumber=5
[2872442.650552] u*** 1-1: Product: Mass Storage Gadget
[2872442.650553] u*** 1-1: Manufacturer: Linux 4.1.15-1.2.0+g8d9
8da6 with 2184000.u***
[2872442.650554] u*** 1-1: SerialNumber: 1234
[2872442.657827] u***-storage 1-1:1.0: USB Mass Storage device
detected
[2872442.657895] u***-storage 1-1:1.0: Quirks match for vid 0525
pid a4a5: 10000
[2872442.657923] scsi host3: u***-storage 1-1:1.0
[2872443.669426] scsi 3:0:0:0: Direct-Access Linux File-
Stor Gadget 0401 PQ: 0 ANSI: 2
[2872443.669886] sd 3:0:0:0: Attached scsi generic sg1 type 0
[2872443.670820] sd 3:0:0:0: [sdb] 131072 512-byte logical blocks:
(67.1 MB/64.0 MiB)
[2872443.779976] sd 3:0:0:0: [sdb] Write Protect is off
[2872443.779979] sd 3:0:0:0: [sdb] Mode Sense: 0f 00 00 00
[2872443.890093] sd 3:0:0:0: [sdb] Write cache: enabled, read cache:
enabled, doesn't support DPO or FUA
[2872444.110372] sdb:
[2872444.330074] sd 3:0:0:0: [sdb] Attached SCSI removable disk
此章结束,下一章将继续介绍i.MX6UL开发板的Linux应用开发(二)。
更多回帖