本文讲述怎样使用PS的gpio,不涉及fpga部分,软件涉及到一级引导程序fsbl的创建及app的创建,程序运行在ddr中.
z-turn板的mio 50引脚连接到了按键K1,该实验实现的功能为,检测按键并从串口打印出相应的信息.
1. 用vivado搭建硬件模型.
在block design的Re-customize IP界面,点击Presets->Apply Configuration, 定位到上章导出的memtest.tcl硬件配置文件.
点击MIO configuration->展开GPIO,选中GPIO MIO.将硬件参数导出为gpio.tcl.
综合完之后导出硬件参数,从vivado启动SDK.
2. 在SDK中编辑软件
2.1 创建一级引导程序fsbl
File->New->Application,参数如下:
点击Next->选择Zynq FSBL->Finish.完成后多了两个工程,fsbl和fsbl_bsp,记得把fsbl_bsp的sd卡驱动改成2.2版本的.
2.2 创建app工程
File->New->Application,参数如下:
注意Board Support Package选已创建好的fsbl_bsp,不要创建新的了.点击Next->选择Hello World->Finish.
2.3 修改源码
1>. 增加fsbl的打印信息
在fsbl的src目录下,修改fsbl_debug.h文件,增加#define FSBL_DEBUG_INFO 1
2>. 修改helloworld.c文件
#include <stdio.h>
#include "platform.h"
#include "xgpiops.h"
#include "xil_printf.h"
#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID
#define K1_PIN 50
int main()
{
int Status;
int cnt = 0;
XGpioPs_Config *ConfigPtr;
XGpioPs Gpio; /* The driver instance for GPIO Device. */
init_platform();
print("gpio test\n\r");
/*
* Initialize the GPIO driver.
*/
ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
Status = XGpioPs_CfgInitialize(&Gpio, ConfigPtr,
ConfigPtr->BaseAddr);
if (Status != XST_SUCCESS) {
print("cfg init err\n");
return XST_FAILURE;
}
// K1 GPIO Setting
XGpioPs_SetDirectionPin(&Gpio, K1_PIN, 0);
XGpioPs_SetOutputEnablePin(&Gpio, K1_PIN, 0);
while (1) {
Status = XGpioPs_ReadPin(&Gpio, K1_PIN);
if (!Status) {
xil_printf("K1 Press %d\n\r", cnt++);
while (!XGpioPs_ReadPin(&Gpio, K1_PIN));
}
}
cleanup_platform();
return 0;
}
4. 生成BOOT.bin下载到z-turn板子上运行
编译完成后,右击Project Explorer的fsbl工程->Create Boot Image.
将gpio.elf添加进来:
CPU上电时,会先运行fsbl,fsbl再将gpio的代码copy到ddr中运行,查看gpio的链接文件可知gpio程序是在ddr中运行的.
将gpio\gpio.sdk\fsbl\bootimage\文件夹下的BOOT.bin copy到SD卡上,插到z-turn板上运行,会出现以下串口信息:
Xilinx First Stage Boot Loader
Release 2014.4 Jan 22 2015-11:39:25
Devcfg driver initialized
Silicon Version 3.1
Boot mode is SD
SD: rc= 0
SD Init Done
Flash Base Address: 0xE0100000
Reboot status register: 0x60600000
Multiboot Register: 0x0000C000
Image Start Address: 0x00000000
Partition Header Offset:0x00000C80
Partition Count: 2
Partition Number: 1
Header Dump
Image Word Len: 0x00003003
Data Word Len: 0x00003003
Partition Word Len:0x00003003
Load Addr: 0x00100000
Exec Addr: 0x00100000
Partition Start: 0x000055D0
Partition Attr: 0x00000010
Partition Checksum Offset: 0x00000000
Section Count: 0x00000001
Checksum: 0xFFDF17C5
Application
Handoff Address: 0x00100000
In FsblHookBeforeHandoff function
SUCCESSFUL_HANDOFF
FSBL Status = 0x1
gpio test
K1 Press 0
K1 Press 1
K1 Press 2
K1 Press 3
K1 Press 4
K1 Press 5
K1 Press 6