使用Xilinx Vivado设计套件创建一个简单的HelloWorld项目

可编程逻辑

1333人已加入

描述

什么是FPGA

Xilinx以制造 可编程门阵列(FPGA)而闻名,它是基于一个通过可编程接点连接的可配置逻辑块(CLBs)矩阵。根据Control Engineering Europe中的 “FPGA的优点(Advantages of FPGA)”这篇文章,多种控制回路能够以不同但是十分快的速度在FPGA设备上运行。FPGA也可以在制造后再编程以达到别种应用或是功能需求,这使它在专业工程师中非常流行。许多工程师都把这种技术应用到机械学习,无线通信,嵌入式视觉和云计算应用中。

什么是ZYNQ

Xilinx Zynq®-7000 全可编程系统芯片 (AP SoC)系列包含了基于嵌入式处理器的软件可编程性和FPGA的硬件可编程性。这个技术使得我们在单一设备上集成CPU,DSP,ASSP和混合信号功能时进行关键分析和硬件加速。

安装Vivado, SDK 和板支持文件

在创建数字或系统设计前你首先需要安装 Xilinx Vivado 设计套件。 Xilinx Vivado Webpack 这个版本是免费的,通过 Digilent Wiki 上提供的使用指导也可以帮助你快读安装和运行Vivado。在下载Vivado时,确保你使用设计工具(Design Tools)栏目中的“软件开发套件(Software Development Kit)”来安装SDK。为了防止你忘了这个步骤,你也可以返回安装软件来安装“软件开发套件(Software Development Kit)”。

内容

一旦你下载并安装了Vivado,你需要把ZYBO板文件放入本地Xilinx Vivado文件夹,它定义了ZYBO板上的不同界面和协议。之后你就可以成功建立IP和SDK了。Diligent提供了一个教程: https://reference.digilentinc.com/reference/software/vivado/board-files?。.. 。

注意:在Vivado board文件安装指导中,你需要把头文件(board_files)放入你的本地文件夹。然后,我会推荐你复制独立的board文件(例如,一旦你下载了vivdado board文件,找到vivado-boards-master ewoard_files并复制“zybo文件夹”。否则你可能会在设计中碰到一些不必要的错误。

创建项目

我将会使用 Digilent ZYBO 并根据他们的 开始指南(getting started guide) 来创建一个简单的HelloWorld项目。

项目概要

在这个项目中你将会学到如何用四个板上的开关来控制板上的LED。当你按下四个不同的按钮后,你可以看到来自电脑端的多种信息。

设计流程

打开Vivada并选择Zybo板

创建一个新的Vivado项目

在新的项目中创建一个空的板块设计工作区

使用IP集成工具添加需要的IP模块并创建硬件设计

验证并保存板块设计

创建HDL系统封装

运行设计综合与实现

生成Bit文件

导出包含了bit源文件的硬件设计到SDK工具

开启 SDK

硬件设计概要

你可以根据开始指南(getting started guide)中的步骤2-6来创建硬件设计,以下是一些说明。

自动运行模块(Run Block Automation)对话框可以让你提供微处理器系统需要的一些基础特性输入。

“3.4)双击新的axi_gpio_0内核可以弹出自定义窗口。在IP设置页检查启动双通道,并点击OK”,你可以创建两种输入-SW和BTN。每一个axi_gpio内核都支持32位单双GPIO通道。在这个项目中,每个通道我们只需要四位。你可以在AXI GPIO Guide中找到详细信息。

“3.5)重复步骤3.3可以添加另一个GPIO内核,但是不要启动双通道”,你将会创建一个输出-LED。

自动运行连接可以帮助你hook界面和外部I/O接口

默认,UART界面中的一种已经被放置在ZYNQ IP中了

请参考:http://blog.dev-flow.com/en/8-first-use-of-the-zynq-7000-processor-system-on-a-zynq/。

Xilinx

软件设计概要

你可以根据开始指南(getting started guide)中的步骤7-10来创建软件设计,以下是一些说明。

当你打开“src”文件夹中的“helloworld.c’’文件后(参考开始指南(getting started guide)中的步骤9.4),你可以通过以下步骤在用户界面看到一些预设功能和库的详细内容。

标记功能/库

Xilinx

右击预设功能/库并打开新选项看到声明

Xilinx

以下是代码和注释

/*****************************************************

Getting Started Guide for Zybo

This demo displays the status of the switches on the

LEDs and prints a message to the serial communication

when a button is pressed.

Terminal Settings:

-Baud: 115200

-Data bits: 8

-Parity: no

-Stop bits: 1

1/6/14: Created by MarshallW

****************************************************/

/*include libraries from Xilinx*/

#include

#include “platform.h”

#include

#include “xparameters.h”

#include “sleep.h”

int main()

{

XGpio input, output; /*Declare two structure input & output. XGpio is*/

int button_data = 0; /*Declare & Define initial button value*/

int switch_data = 0; /*Declare & Define initial switch value*/

/*Initialize the XGpio instance provided by the caller based on the given DeviceID.*/

XGpio_Initialize(&input, XPAR_AXI_GPIO_0_DEVICE_ID); /*We define AXI_GPIO_0 as inputs - BTN & SW*/

XGpio_Initialize(&output, XPAR_AXI_GPIO_1_DEVICE_ID);/*We define AXI_GPIO_1 as inputs - LED*/

XGpio_SetDataDirection(&input, 1, 0xF); /*set first channel of input tristate buffer to input*/

XGpio_SetDataDirection(&input, 2, 0xF); /*set second channel of input tristate buffer to input*/

XGpio_SetDataDirection(&output, 1, 0x0); /*set only channel of output tristate buffer to output*/

init_platform(); /*Initialize the platform hardware resources*/

/*Indefinite loop - running forever*/

while(1){

switch_data = XGpio_DiscreteRead(&input, 2); /*Read the switch (SW) value*/

XGpio_DiscreteWrite(&output, 1, switch_data); /*Write the switch (SW) value to LED (LD)*/

button_data = XGpio_DiscreteRead(&input, 1); /*Read the button (BTN) value*/

/*Set up if-else-if statement to print message in the

*UART terminal. This depends on whether one or

* more buttons are pressed

*/

if(button_data == 0x0){} /*If no button is pressed, do nothing*/

/*If button value is binary 0001 (decimal 1), button 0 (BTN0) is pressed. Use pre-defined function Xil-printf

* to print the message in the terminal

*/

else if(button_data == 0x1)

xil_printf(“button 0 pressed ”);

/*If button value is “binary 0010 (decimal 2)”, button 1 (BTN1) is pressed. Use pre-defined function Xil-printf

*to print the message in the terminal

*/

else if(button_data == 0x2)

xil_printf(“button 1 pressed ”);

/*If button value is “binary 0100 (decimal 4)”, button 2 (BTN2) is pressed. Use pre-defined function Xil-printf

*to print the message in the terminal

*/

else if(button_data == 0x4)

xil_printf(“button 2 pressed ”);

/*If button value is “binary 1000 (decimal 8)”, button 3 (BTN3) is pressed. Use pre-defined function Xil-printf

*to print the message in the terminal

*/

else if(button_data == 0x8)

xil_printf(“button 3 pressed ”);

else

xil_printf(“multiple buttons pressed ”); /*All other values, print “multiple buttons pressed*/

usleep(200000); /*Delay 200000us*/

}

cleanup_platform(); /*Clean up all caches*/

return 0;

}

运行项目

你可以根据步骤11来运行项目。在你对FPGA进行编程并成功创建应用后,你可以看到以下:

1. 试着按下四个开关,并且各自相对应的LED会亮起

2. 在串口端,按下每一个按钮,会弹出“按钮已被按下”的信息。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分