https://github.com/qiweiii-git/qwi12_petaled
1.在linux下使用./makeall.sh即可自动编译Vivado及PetaLinux工程。 如何使用linux自动编译工程请参考利用Linux自动编译Vivado工程 2.在Windows下打开Vivado,运行source run.tcl即可自动创建工程并编译。
在Xilinx的PetaLinux中,以控制AXI GPIO的方式来控制LED灯亮灭。
PetaLinux工具要求主机系统 /bin/sh 为“bash”。使用sudo dpkg-reconfigure dash命令更改默认的shell /bin/sh(选择“否”)。 查看目前是dash还是bash命令:ls -l /bin/sh 安装库:
sudo apt-get install libssl-dev:i386 flex:i386 bison:i386 libselinux1:i386 libncurses5 libncurses5-dev libc6:i386 libstdc++6:i386 zlib1g:i386 libssl-dev tftpd tftp openbsd-inetd tofrodos:i386 iproute2:i386 gawk:i386 gcc net-tools:i386 zlib1g-dev:i386将安装文件(下载链接: https://pan.baidu.com/s/14aQF8kvf9_DELPji3momIw 提取码: n4ju)复制到Ubuntu中。 PetaLinux2015.4将会安装到/opt目录中。
sudo su chmod +x petalinux-v2015.4-final-installer.run ./petalinux-v2015.4-final-installer.run /opt系统框图如下:
2.2.1 UART配置 2.2.2 SD配置 2.2.3 DDR配置
地址分配:
将GPIO输出连接至顶层端口输出。 并为LED端口分配管脚:
set_property PACKAGE_PIN M14 [get_ports LED] set_property IOSTANDARD LVCMOS33 [get_ports LED]3.1.1 导出Vivado硬件描述文件 3.1.2 复制hdf及bit至工程目录 3.1.3 新建PetaLinux工程
petalinux-create --type project --template zynq --name qwi12_petaled3.2.1 进入petalinux工程目录
cd qwi12_petaled3.2.2 配置硬件信息
petalinux-config --get-hw-description ../等待一定时间后出现配置页面 无需任何改动,保存后退出。 等待一定时间后配置完成。
等待一定时间后出现配置页面 无需任何改动,保存后退出。
等待一定时间后出现配置页面
等待一定时间后编译完成
等待一定时间后合并完成 在images/linux中找到BOOT.BIN及image.ub,复制出来。
4.1.1 将SD卡格式化成FAT32格式
4.1.2 将BOOT.BIN及image.ub复制到SD卡中 4.1.3 启动 设备上电后,通过UART打印启动信息 4.1.4 登陆
Login: root Password: root登陆完成:
4.2.1 查看GPIO设备
ls /sys/class/gpio4.2.2 查看GPIO控制器标签
cat /sys/class/gpio/gpiochip905/label显示该GPIO控制器地址为0x41100000,即是我们设计控制LED的GPIO控制器。而gpiochip906为PS端的GPIO控制器。 4.2.3 使能GPIO控制器
echo -n 905 > /sys/class/gpio/export使能后GPIO设备就会多出gpio905 4.2.4 设置GPIO控制器方向为输出(默认为输入)
echo out > /sys/class/gpio/gpio905/direction设置为输出方向后,LED才能被控制起来,由于GPIO控制器默认数值为0,硬件上设计低电平时LED亮,因此设置为输出方向后,LED即亮起来。 4.2.5 查看当前GPIO数值
cat /sys/class/gpio/gpio905/value当前GPIO值为0,LED亮。
4.2.6 控制GPIO来控制LED亮灭(1为灭,0为亮)
echo 1 > /sys/class/gpio/gpio905/value echo 0 > /sys/class/gpio/gpio905/value编写GPIO应用程序,实现LED每隔1s切换一次状态,即1s亮1s灭。
int main() { int value; int export; int direction; // export GPIO controller export = open("/sys/class/gpio/export", O_WRONLY); if (export < 0) { printf("Cannot open GPIO controller export\n"); exit(1); } write(export, "905", 4); close(export); printf("GPIO controller export successfully\n"); // Modify GPIO controller direction direction = open("/sys/class/gpio/gpio905/direction", O_RDWR); if (direction < 0) { printf("Cannot open GPIO controller direction\n"); exit(1); } write(direction, "out", 4); close(direction); printf("GPIO controller direction changed to output successfully\n"); // Modify GPIO controller value value = open("/sys/class/gpio/gpio905/value", O_RDWR); if (value < 0) { printf("Cannot open GPIO controller value\n"); exit(1); } // Swap GPIO control value each 1 second while (1) { sleep(1); write(value,"1", 2); printf("GPIO controller value changed to 1 successfully\n"); sleep(1); write(value,"0", 2); printf("GPIO controller value changed to 0 successfully\n"); } }4.3.1 创建Petalinux App
petalinux-create -t apps --template c --name qwi12_petaled --enable4.3.2 将GPIO应用程序代码复制到Petalinux App目录中
cp ../../software/qwi12_petaled.c components/apps/qwi12_petaled/4.3.3 按照第三章中步骤编译Petalinux 4.3.4 将BOOT.BIN及image.ub复制到SD卡中 4.3.5 设备启动后执行GPIO应用程序,实现LED每隔1s切换一次状态
/bin/qwi12_petaled4.3.6 将GPIO应用程序设置为上电自启动 修改Makefile
vi components/apps/qwi12_petaled/Makefile在Makefile的install:中添加如下代码:
$(TARGETINST) -d -p 0755 qwi12_petaled /etc/init.d/qwi12_petaled $(TARGETINST) -s /etc/init.d/qwi12_petaled /etc/rc5.d/S99qwi12_petaled设备上电后就会自动运行GPIO应用程序 至此,在Petalinux中控制AXI GPIO来控制LED灯亮灭实验已完成。