Академический Документы
Профессиональный Документы
Культура Документы
Xilinx is disclosing this Document and Intellectual Property (hereinafter the Design) to you for use
in the development of designs to operate on, or interface with Xilinx FPGAs. Except as stated
herein, none of the Design may be copied, reproduced, distributed, republished, downloaded,
displayed, posted, or transmitted in any form or by any means including, but not limited to,
electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of
Xilinx. Any unauthorized use of the Design may violate copyright laws, trademark laws, the laws of
privacy and publicity, and communications regulations and statutes.
Xilinx does not assume any liability arising out of the application or use of the Design; nor does
Xilinx convey any license under its patents, copyrights, or any rights of others. You are responsible
for obtaining any rights you may require for your use or implementation of the Design. Xilinx
reserves the right to make changes, at any time, to the Design as deemed desirable in the sole
discretion of Xilinx. Xilinx assumes no obligation to correct any errors contained herein or to advise
you of any correction if such be made. Xilinx will not assume any liability for the accuracy or
correctness of any engineering or technical support or assistance provided to you in connection with
the Design.
THE DESIGN IS PROVIDED AS IS" WITH ALL FAULTS, AND THE ENTIRE RISK AS TO ITS
FUNCTION AND IMPLEMENTATION IS WITH YOU. YOU ACKNOWLEDGE AND AGREE THAT
YOU HAVE NOT RELIED ON ANY ORAL OR WRITTEN INFORMATION OR ADVICE, WHETHER
GIVEN BY XILINX, OR ITS AGENTS OR EMPLOYEES. XILINX MAKES NO OTHER
WARRANTIES, WHETHER EXPRESS, IMPLIED, OR STATUTORY, REGARDING THE DESIGN,
INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, TITLE, AND NONINFRINGEMENT OF THIRD-PARTY RIGHTS.
IN NO EVENT WILL XILINX BE LIABLE FOR ANY CONSEQUENTIAL, INDIRECT, EXEMPLARY,
SPECIAL, OR INCIDENTAL DAMAGES, INCLUDING ANY LOST DATA AND LOST PROFITS,
ARISING FROM OR RELATING TO YOUR USE OF THE DESIGN, EVEN IF YOU HAVE BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THE TOTAL CUMULATIVE LIABILITY OF
XILINX IN CONNECTION WITH YOUR USE OF THE DESIGN, WHETHER IN CONTRACT OR
TORT OR OTHERWISE, WILL IN NO EVENT EXCEED THE AMOUNT OF FEES PAID BY YOU
TO XILINX HEREUNDER FOR USE OF THE DESIGN. YOU ACKNOWLEDGE THAT THE FEES,
IF ANY, REFLECT THE ALLOCATION OF RISK SET FORTH IN THIS AGREEMENT AND THAT
XILINX WOULD NOT MAKE AVAILABLE THE DESIGN TO YOU WITHOUT THESE LIMITATIONS
OF LIABILITY.
The Design is not designed or intended for use in the development of on-line control equipment in
hazardous environments requiring fail-safe controls, such as in the operation of nuclear facilities,
aircraft navigation or communications systems, air traffic control, life support, or weapons systems
(High-Risk Applications). Xilinx specifically disclaims any express or implied warranties of fitness
for such High-Risk Applications. You represent that use of the Design in such High-Risk
Applications is fully at your risk.
2012 Xilinx, Inc. All rights reserved. XILINX, the Xilinx logo, and other designated brands included
herein are trademarks of Xilinx, Inc. All other trademarks are the property of their respective owners.
Table of Contents
Lab 1: Basic System Implementation ............................................................... 3
Lab 2: Application Development ..................................................................... 51
Lab 3: Software Interrupts ............................................................................... 81
Lab 4: Debugging ........................................................................................... 101
Lab 5: Writing a Device Driver ....................................................................... 121
Lab 6: Integrating a Custom Peripheral ........................................................ 147
Lab 7: Building Custom AXI IP for an Embedded System .......................... 171
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Introduction
This lab is an introduction to the Xilinx Platform Studio. From the modules, you learned the general
concepts of hardware construction. In this lab, you will learn how to construct the hardware platform used
for all of the labs in this course. You will use the Processor Configuration Wizard (PW) to create the
hardware and example test software application named Peripheral_Test. Subsequently, you will create a
new SDK software workspace and add the sample application to it. The hardware consists of:
GPIO interface to drive eight LEDs located under the LCD display
Not all of the hardware will be used by the software application in this lab.
Objectives
After completing this lab, you will be able to:
Implement a processor system via the PlanAhead software and XPS using the Processor
Configuration Wizard (PCW)
Procedure
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab is comprised of five primary steps: You will implement a processor design with the Processor
Configuration Wizard (PCW); implement the hardware design; create an SDK workspace and add the test
application software generated by PCW; connect the development board hardware; and, finally, configure
the Zynq EPP and test the application.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this lab
from www.xilinx.com/training/downloads.htm. These are the original lab files and do not contain any work
that you may have previously completed.
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-1. Select Start > All Programs > Xilinx ISE Design Suite > PlanAhead > PlanAhead (32) for 32bit systems or PlanAhead for 64-bit systems to launch the PlanAhead software.
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-3. In the Project name field, enter lab1. In the Project location field, browse to the
C:\training\EmbSysSoft\labs directory.
Value
Family
Zynq-7000
Package
CLG484
Speed Grade
-1
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-2.
Add a new source file that is of an embedded type. When specified, it will
automatically launch the XPS tool. Then you will use the Processor
Configuration Wizard (PCW) to create the embedded processor system.
).
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Take a moment to view the architecture of the processing system (PS). Click the blocks in green
to view the available settings.
1-3.
10
UART 1
Timer 0
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
11
Lab Workbook
12
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-3-4. Click the I/O Peripherals block to open the ZYNQ MIO Configuration dialog box. Select Show
I/O Standard Options. Observe the enabled I/O peripherals (IOP) and the I/O connection.
www.xilinx.com
1-877-XLX-CLAS
13
Lab Workbook
Not all peripherals used in this lab will be used in subsequent labs.
14
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-3-7. To view how the tool has configured the DDR3 memory, click the Memory Interfaces block in the
ZYNQ tab.
www.xilinx.com
1-877-XLX-CLAS
15
Lab Workbook
1-3-9. Select the IP Catalog tab in the left window and expand General Purpose IO to view the
available cores under the corresponding entries.
16
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-3-12. Change the instance name of the peripheral to LEDs_8bit by clicking once in the Name column
of the axi_gpio_0 component, typing the new name, and then clicking any other screen object.
At this point, the peripherals should look like those in the figure below, although not necessarily in
the same order.
Figure 1-17: Bus Interfaces Tab after Adding and Renaming the axi_gpio_0 Peripheral
Notice that the wire coming from the LEDs_8bit peripheral is attached to the AXI interconnect.
This indicates that this component is connected to the AXI.
As indicated in the previous step when the interconnect was created for the processing system,
the interconnect for the LEDs_8bit peripheral has been automatically made by the tools when the
GPIO was first added. When performed manually, this connection can be made by one of two
ways:
o
The more flexible method requires expanding the LEDs_8bit component and clicking in the
Bus Name column next to the S_AXI port of the component and selecting the desired AXI
interconnect (in this design, there is only a single AXI interconnect).
17
Lab Workbook
1-4.
In this step, you will create an external port to the processor system that
can later be attached to the eight physical LEDs. The configuration of the
GPIO that was deferred earlier will be performed. All of these items will be
performed in the Ports tab of the SAV.
1-4-1. Select the Ports tab in the System Assembly View and expand the LEDs_8bit instance and the
two sub-ports.
18
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
19
Lab Workbook
1-4-6. Because you want to use only one channel, keep the Enable Channel option de-selected.
20
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-4-7. Select Channel 1 to view Channel 1-related configurable parameters. Enter 8 in the GPIO Data
Channel Width box to match the width of the eight LEDs on the the FMC card.
www.xilinx.com
1-877-XLX-CLAS
21
Lab Workbook
1-4-10. Click in the Net column of the GPIO_IO_O port of the LEDs_8bits instance and select Make
External from the Net column drop-down list.
1-5.
In this step, you will make reset and clock connections to the AXI
interconnect and processing system.
1-5-1. In the Ports tab, expand processing_system7_0 instance and again expand the (BUS_IF)
M_AXI_GP0 sub-port.
22
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-5-2. For M_AXI_GP0_ACLK, select the clock processing_system7_0_FCLK_CLK0 from the Net
column drop-down list.
1-6.
Similarly, you will have to create AXI general-purpose I/O for the following
peripherals:
However, in the interest of time, the completed MHS file is available for you
and you can use it to create AXI general-purpose I/O for the above
peripherals.
1-6-1. In the Project tab on the left, under Project Files, double-click the system.mhs file.
1-6-2. Using Windows explorer, browse to the C:\training\EmbSysSoft\Support directory and open the
system_snippet.mhs file using a text editor.
1-6-3. Replace the contents of the system.mhs in XPS with the contents of the system_snippet.mhs file
in the Support directory. Save it. Click to Reload.
1-6-4. If you are not using the system_snippet.mhs file from the Support directory and are creating AXI
general-purpose I/O for each of the peripherals, be sure to perform the following changes to the
system.mhs file.
www.xilinx.com
1-877-XLX-CLAS
23
Lab Workbook
24
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Question 1
Which of the components did you specifically add as peripherals in the Processor Configuration Wizard?
Step 2
The design is now specified. The result is the system.mhs file, which is a netlist of the
various components of the processor system. The netlist is an ASCII-readable file and
the System Assembly View in XPS is its graphic representation.
The next step in the design process is to engage the Xilinx implementation tools to
generate a processor subsystem netlist, export that hardware description to the SDK
software tool, and finally generate a bitstream in the PlanAhead tool. At that point, the
hardware specification and implementation will be complete for all subsequent labs in
the course. Due to time constraints, the hardware netlist and bit file will not be
generated but the necessary steps will be outlined.
2-1.
www.xilinx.com
1-877-XLX-CLAS
25
2-2.
Lab Workbook
2-2-1. In the Hierarchy window, right-click the system component and select Create Top HDL.
26
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-3.
The user constraint file contains Zynq EPP pin placement information and
timing constraints. Add the UCF to the project.
2-4.
Synthesize
Translate
Map
This action will implement the hardware design that can be directly
downloaded to the Zynq EPP via a download cable. You can then start
using the software development tools in SDK to implement the software
application on this hardware.
2-4-1. In the Flow Navigator, click Synthesis Settings under Synthesis. Set the strategy to PlanAhead
Defaults.
2-4-2. In the Flow Navigator, click Implementation Settings under Implementation. Set the strategy to
ISE Defaults.
www.xilinx.com
1-877-XLX-CLAS
27
Lab Workbook
28
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 3
The hardware portion of the project is done. In this step, you will create an SDK
workspace, create a software platform, and add the Peripheral Tests software
application that was created by BSB. Upon automatic launch when exporting embedded
hardware, SDK creates a hardware platform project in the new workspace that you
specified in the last step. On this platform you will build a First Stage Bootloader (FSBL)
project, Board Support Package (BSP), and a software application. All of these projects
will be members of the SDK workspace.
In this step, you will create a software project by using one of the available projects that
SDK supports. When creating a simple software application project, SDK can autocreate the BSP project.
Of the projects in the workspace (hardware platform, BSP, and software application),
two of them will be automatically created, leaving little work for you.
SDK will automatically build the software application project and produce an Executable
and Load Format (ELF) file.
3-1.
Export the processor and launch the Software Development Kit (SDK).
3-1-1. In the Hierarchy window, select and double-click the system_i - system (system.xmp)
component.
3-1-2. In XPS, select Project > Export Hardware Design to SDK. Uncheck Include bitstream and
BMM file.
29
Lab Workbook
PlanAhead/XPS software project. While not a requirement, it is a good idea to keep the SDKrelated files together.
3-1-3. Click Export & Launch SDK.
3-1-4. Browse to and select the
C:\training\EmbSysSoft\labs\lab1\lab1.srcs\sources_1\edk\system\SDK directory for
software development and click OK.
30
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
3-1-5. Verify that the SDK tool launches. Close the welcome screen.
3-2.
www.xilinx.com
1-877-XLX-CLAS
31
Lab Workbook
3-2-1. In SDK, select File > New > Xilinx Board Support Package.
32
CPU: ps7_cortexa9_0
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
33
3-3.
Lab Workbook
34
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
3-3-2. Select Zynq FSBL from the Select Project Template area.
3-4.
In this step, you will add a new C software application project by using the
BSB-created Peripheral Tests sample application project template and the
newly created lab1-bsp.
www.xilinx.com
1-877-XLX-CLAS
35
Lab Workbook
SDK supports multiple software projects in a single SDK project. There are several different types
of software application projects, with the simplest being a C application project. In this type of
project, the software designer writes code from the standpoint of beginning in the main{} C
function.
The New Xilinx C Project dialog box appears. Note that every software application is attached to
a software platform (BSP) that is already attached to a hardware design.
3-4-2. Select the Peripheral Tests project template. Keep the default project name peripheral_tests_0
and click Next.
36
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
3-4-3. Select Target an existing Board Support Package, select lab1-bsp, and click Finish.
www.xilinx.com
1-877-XLX-CLAS
37
Lab Workbook
3-4-6. Select ps7_ddr_0_S_AXI_BASEADDR as the memory area used from the Code Sections, Data
Sections, and Heap and Stack drop-down lists.
3-5.
From SDK, open the file testperiph.c and examine the test code. Then test
your understanding by answering the questions that follow.
3-5-1. In the Project Explorer tab, expand the src folder under the peripheral_tests_0 application.
38
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Question 2
What does the testperiph.c program do?
Question 3
What is the program unable to do? Hint: See the comment at about line 204.
www.xilinx.com
1-877-XLX-CLAS
39
Lab Workbook
3-5-4. Close the testperiph.c file and examine the xgpio_tapp_example.c test program and note:
o
There is a conditional compile directive (a few lines below) to insert a software-based timing
delay loop when the code is not targeted for simulation.
Question 4
What is the constant name defining the number of times a wait loop will be executed to make the LED
visible? Hint: Look a few lines below line 209.
Question 5
How many times will the wait loop be executed? (Hint: Look for a #define statement near the beginning of
the program.)
Step 4
In this step, you will become familiar with the Zynq EPP ZC702 development board and
learn how to connect to it.
You will verify that the board configuration switches and jumpers are properly set and
then connect the power supply, download, and serial cables to the evaluation board.
Ask the instructor for help if you encounter problems.
40
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
4-1.
Connect the ZC702 board to your machine. Open a terminal in SDK to view
the output of the software application.
www.xilinx.com
1-877-XLX-CLAS
41
Lab Workbook
42
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 5
In this last step, you will configure the Zynq EPP, download the application, and test the
program for proper operation.
You will then perform a simple modification to the application to make a row of LEDs
continuously chase each other.
This lab assumes that the ZC702 hardware board and download cabling are in place.
5-1.
The Zynq EPP will now be configured with a bitstream that has been
provided for you.
5-1-1. Make sure that the hardware board is set up and turned on.
5-1-2. In SDK, select Xilinx Tools > Program FPGA.
www.xilinx.com
1-877-XLX-CLAS
43
Lab Workbook
5-1-3. In the Bitstream field, browse to the C:\training\EmbSysSoft\Support directory and select the
system.bit file.
44
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
5-2.
5-2-1. In the Project Explorer tab, right-click the peripheral_tests_0 software application and select
Run As > Run Configurations.
45
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
5-3.
5-3-1. In the Project Explorer tab, double-click the testperiph.c file under the src folder to open it.
5-3-2. At line 104, add the C statement while (1) {
5-3-3. At line 135, add a }.
5-4.
5-4-1. In the Project Explorer tab, right-click the peripheral_tests_0 software application and select
Run As > Run Configurations. Click Run.
5-4-2. Verify that the LEDs turn on and off sequentially for a "light-chasing" effect.
www.xilinx.com
1-877-XLX-CLAS
47
Lab Workbook
5-4-3. To terminate the program, click the Terminate icon in the Console tab.
Question 6
Where does the print() routine output to? How would the output device be configured?
Question 7
Was it necessary to re-implement (Translate, Map, Place & Route) the hardware when the software was
updated? Describe the relationship between hardware and software updates.
Conclusion
In this lab, you built a hardware system and learned how to include an embedded processor design as
part of a PlanAhead software project.
The processor component of the design was added as a new source, launching XPS and using the
Processor Configuration Wizard. When you completed the hardware design, you exported it (the Export
Hardware Design to SDK command), launched the SDK tools, created a peripheral test software
application project, and produced the ELF software object for it.
You returned to the PlanAhead software to generate the hardware bitstream file and complete the
hardware design process. You then connected the ZC702 development board to your computer and
tested the sample software application that was created.
48
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Answers
1. What does the testperiph.c program do?
The program first enables the processor cache via calls to the appropriate system services.
Subsequently, there are BSB-generated calls to test routines for each of the selected peripherals.
Each of these calls is enclosed in braces {}.
The other source files in the project support the various tests for each of the peripherals.
2. What is the program unable to do? Hint: See the comment at about line 204.
The ps7_uart_1 will not be run because it has been selected as the STDOUT device. However, the
UART will be used as an output device.
3. What is the constant name defining the number of times a wait loop will be executed to make the LED
visible? Hint: Look a few lines below line 209.
LED_DELAY
4. How many times will the wait loop be executed? (Hint: Look for a #define statement near the
beginning of the program.)
#define LED_DELAY 1000000
// 1,000,000 times
5. Where does the print() routine output to? How would the output device be configured?
The print() function prints to STDOUT, although this information is not obvious from looking at these
files.
This information would be found in the OS and Libraries Document Collection reference document
under the software section (select Start > All Programs > Xilinx ISE Design Suite 14.1 > EDK >
Documentation > Reference User Guides). Most of the Xilinx software services follow normal C
language practices.
The output device that STDOUT talks to was configured when BSB selected and configured the
sample software application during the Application step of the Processor Configuration Wizard.
6. Was it necessary to re-implement (Translate, Map, Place & Route) the hardware when the software
was updated? Describe the relationship between hardware and software updates.
No, the hardware does not have to be re-implemented when the software changes, only if the
hardware changes.
Typically, during software development, the hardware platform is static and having to re-implement
would take unnecessary time. Instead, Xilinx keeps the existing bitstream (BIT file) and updates it
with the new software object.
A BMM file indicates where in block RAM the object code (ELF file) should be placed. This is all done
as part of the Program FPGA command.
www.xilinx.com
1-877-XLX-CLAS
49
Lab Workbook
Application Development
Introduction
In this lab you will use the Xilinx Software Development Kit (SDK) to create a simple software application
project. The source files for a software loop-based stopwatch are provided. The application is mostly
written, lacking only the code to initialize the data direction of two general-purpose I/O peripherals,
axi_gpio, as either inputs or outputs. One of the five peripherals is for the directional pushbuttons on the
evaluation board, which you will configure as inputs. The other drives the LEDs, which you will configure
as outputs.
It is your task to find and use the correct Level 0 driver calls that set I/O direction, requiring you to search
the hardware and device driver documentation. In the example used for the lab, these calls are #define
macros that have low overhead and execute quickly. The axi_gpio is one of the most popular processor
peripherals, so much of what you learn here will be useful in future projects.
Objectives
After completing this lab, you will be able to:
Procedure
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab comprises four primary steps: You will open a pre-built basic hardware system and create an
SDK software application project; add Level 0 axi_gpio device drivers to the software application;
configure the Zynq EPP; and finally, download and run the application.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this lab
from www.xilinx.com/training/downloads.htm. These are the original lab files and do not contain any work
that you may have previously completed.
Step 1
51
Application Development
Lab Workbook
The working directory of the SDK workspace for this lab and all subsequent labs is
C:\training\EmbSysSoft\labs. You will create the SDK workspace and software platform
for the hardware that was developed in the "Basic System Implementation" lab in this
directory. This workspace directory and software platform will be used in subsequent
labs.
A working version of the hardware that you built in the the "Basic System
Implementation" lab has been placed in the C:\training\EmbSysSoft\Support\hw
directory so that this and subsequent labs do not require the completion of the "Basic
System Implementation" lab.
Once SDK is launched and a workspace is set up in this directory, you will not be able
to move these directories.
1-1.
1-1-1. Select Start > All Programs > Xilinx ISE Design Suite > EDK> Xilinx Software Development
Kit to launch SDK.
The Workspace Launcher opens.
SDK creates a workspace environment consisting of project files, tool settings, and your software
application. Once set, you cannot change the location of this workspace. If it is necessary to
move a software application to another location or computer, use the Import and Export facilities
built into SDK. A good location for the software workspace is the root directory of your ISE tool
project.
1-1-2. In the Workspace Launcher, browse to and select C:\training\EmbSysSoft\labs as the
workspace directory and click OK.
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
SDK must associate with a hardware system that has been previously exported. It needs
hardware configuration information so that an appropriate software platform or board support
package can be built.
1-1-3. Close the Welcome screen if it appears in SDK.
1-1-4. Select File > New > Xilinx Hardware Platform Specification.
1-1-5. Enter EmbSysSoftHWP in the Project name field. Browse to C:\training\EmbSysSoft\Support\
hw, select the system.xml hardware project, and click Open.
www.xilinx.com
1-877-XLX-CLAS
53
Application Development
Lab Workbook
Step 2
In this step, you will generate the software platform for the hardware and an empty
software project. Then you will import C source files into the project and SDK will
automatically build and produce an Executable and Load Format (ELF) file.
You will examine, but not change, the board support package (BSP) platform options.
Provided are the nearly completed C source code and associated LCD display drivers,
which you will add to the project. Then you will generate a linker script and configure the
compiler options.
As a first step in a new software environment, a software platform must be built to
contain a library of system and processor services, as well as device drivers for the
hardware peripherals that make up the system. Once a software platform has been
built, then a software application can be written. Xilinx provides the Software Platform
wizard to accomplish this task.
54
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-1.
Application Development
2-1-1. In SDK, select File > New > Xilinx Board Support Package.
www.xilinx.com
1-877-XLX-CLAS
55
Application Development
Lab Workbook
56
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-2.
Application Development
www.xilinx.com
1-877-XLX-CLAS
57
Application Development
Lab Workbook
2-2-2. Select the Empty Application project template. Enter stopwatch-lab2 in the Project name field
and click Next.
58
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
2-2-3. Select Target an existing Board Support Package, select lab2-bsp, and click Finish.
2-3.
Import the source code files lab2.c, lcd.c, and lcd.h from the
C:\training\EmbSysSoft\Support directory into the project. Verify that it
builds correctly.
2-3-1. In the Project Explorer tab, expand the stopwatch-lab2 project, right-click the src directory, and
select Import.
www.xilinx.com
1-877-XLX-CLAS
59
Application Development
Lab Workbook
2-3-2. In the Select dialog box, expand General, select File System, and click Next.
60
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
Use the default Into folder directory path, which copies the files into the src folder of the current
project.
www.xilinx.com
1-877-XLX-CLAS
61
Application Development
Lab Workbook
2-4.
Review the board support package platform options and note how to
change them from SDK. No changes need to be made.
2-4-1. In the Project Explorer tab, right-click lab2-bsp and select Board Support Package Settings.
In the Overview view of the Board Support Package Settings dialog box, note that standard Xilinx
libraries for TCP/IP, flash, memory file system, and others can be selected to be included in the
board support package.
Figure 2-12: Overview View of the Board Support Package Settings Dialog Box
62
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
You will come back to this in the "File Systems" lab to include the Xilinx Memory File System. At
this time nothing needs to be done.
2-4-2. In the left navigation pane, select standalone to view the OS configuration settings.
www.xilinx.com
1-877-XLX-CLAS
63
Application Development
Lab Workbook
2-4-3. In the left navigation pane, select drivers to view driver settings.
64
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
2-4-4. In the left navigation pane, select cpu to view CPU-related configuration settings.
2-5.
Generate a linker script, locating the Code, Data, Stack, and Heap sections
in on-chip block RAM. The off-chip DDR3 RAM will not be used in this lab.
2-5-1. In the Project Explorer tab, right-click the stopwatch-lab2 project and select Generate Linker
Script.
www.xilinx.com
1-877-XLX-CLAS
65
Application Development
Lab Workbook
2-5-2. Select ps7_ddr_0_S_AXI_BASEADDR as the memory area used from the Code Sections, Data
Sections, and Heap and Stack drop-down lists.
2-6.
Verify the C/C++ Build properties. Make sure that compiler optimization is
off and that debugging symbols are enabled for the Debug configuration.
Verify that the proper linker script has been selected.
2-6-1. In the Project Explorer tab, right-click the stopwatch-lab2 project and select C/C++ Build
Settings.
2-6-2. In the Properties dialog box, expand C/C++ Build in the left navigation pane and select Settings.
2-6-3. In the Configuration area, select Debug [ Active ] from the drop-down list.
2-6-4. In the Tool Settings tab, expand ARM gcc compiler, select Optimization, and set the
Optimization Level to None (-O0).
66
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
2-6-5. Select Debugging in the properties list just below Optimization and set the Debug Level to
Default (-g).
www.xilinx.com
1-877-XLX-CLAS
67
Application Development
Lab Workbook
Question 1
When might you change a setting in the Board Support Package Settings dialog box and regenerate the
BSP?
Question 2
What would you do differently in this step to generate faster, more compact C code?
Step 3
The stopwatch application is almost complete. To complete the application, the registers
controlling the data direction of the axi_gpio peripherals used for the pushbutton inputs
and LED outputs need to be initialized.
68
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
3-1.
Application Development
3-1-1. In the Project Explorer tab, expand the EmbSysSoftHWP hardware platform project and doubleclick system.xml to open the hardware platform specification in the edit window.
www.xilinx.com
1-877-XLX-CLAS
69
Application Development
Lab Workbook
3-1-2. Click the Datasheet link to open the gpio datasheet in a browser window.
70
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
It states that bits in the register cleared to 0 configure the associated I/O pin as an output and
bits set to 1 configure the associated I/O pin as an input.
Now you need a way to set up the registers in the lab2.c program. For the sake of simplicity, you
will use a low-level macro.
3-2.
3-2-1. In the Project Explorer tab, expand the lab2-bsp board support package project and double-click
system.mss to open the board support package information in the edit window.
3-2-2. In the list of peripheral drivers, click the Documentation link next to a gpio peripheral.
www.xilinx.com
1-877-XLX-CLAS
71
Application Development
Lab Workbook
72
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
3-2-4. Find the low-level generic write register macro for xps_gpio and click the link to xgpio_l.h next to
it.
www.xilinx.com
1-877-XLX-CLAS
73
Application Development
Lab Workbook
The xgpio_l.h file reference document opens in the browser window, displaying information about
the low-level write register macro.
3-3.
Find the program location in the lab2.c source (with the comment "Student
to add code here") to set the axi_gpio data direction for the pushbuttons
and LEDs. Using the macro driver functions, initialize the data direction for
the two axi_gpio peripherals. Compile and link the code.
To perform this step, you will need the base address of the 8-bit LEDs and
5-bit pushbutton peripherals. The base address #defines are found in the
xparameters.h file that is automatically created when the BSP is built.
74
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
3-3-1. In the Project Explorer tab, expand the stopwatch-lab2 project, expand the src folder and
double-click lab2.c to open it in the edit window.
www.xilinx.com
1-877-XLX-CLAS
75
Application Development
Lab Workbook
Question 3
In what file are the low-level macro-based gpio functions found? How many gpio macro functions exist?
Question 4
Is changing, editing, or adding to the xparameters.h file a good idea? Why or why not?
Step 4
In this last step, you will configure the programmable logic, download the application,
and test the program for proper stopwatch operation. The hardware portion of the
design has already been implemented for you. This is the same configuration that was
created in the "Basic System Implementation" lab. This lab assumes that the ZC702
hardware board and download cabling are in place.
4-1.
Configure the Zynq EPP with the bitstream. The BIT file is located in the
C:\training\EmbSysSoft\Support directory
4-1-1. Make sure that the hardware board is set up and turned on.
76
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
www.xilinx.com
1-877-XLX-CLAS
77
Application Development
4-2.
Lab Workbook
4-2-1. In the Project Explorer tab, right-click the stopwatch-lab2 software application and select Run
As > Run Configurations.
78
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Application Development
START BTN3
STOP
RESET BTN1
BTN2
4-2-5. To terminate the program, click Terminate button on the Console tab. If not visible, select Xilinx
Tools > XMD Console and enter stop in the XMD command box.
Question 5
Why is the bootloop program specified for FPGA configuration?
Question 6
The Run configuration is set for the Debug project configuration. What is the purpose for all of these
configurations?
Conclusion
In this lab, you created a basic SDK software application that operates a software loop-based stopwatch.
The application utilized Level 0 axi_gpio device drivers. You used the documentation available from SDK
to investigate how to identify and install these drivers in the C source. You learned how to configure the
FPGA, then load and run the software application.
www.xilinx.com
1-877-XLX-CLAS
79
Application Development
Lab Workbook
Answers
1. When might you change a setting in the Board Support Package Settings dialog box and regenerate
the BSP?
The settings can be changed for various reasons, including:
Changing hardware
2. What would you do differently in this step to generate faster, more compact C code?
In the C/C++ Build section properties, the compiler optimization was turned off to enhance debugging.
Setting the optimization level higher will cause the compiler to generate more efficient and compact
code.
3. In what file are the low-level macro-based gpio functions found? How many gpio macro functions
exist?
Low-level, macro-based functions for the gpio peripheral are all found in the xgpio_l.h file.
There are only two gpio macro functions: XGpio_WriteReg( ) and XGpio_ReadReg( ). These macros
are useful for doing simple tasks in small programs. In larger, more complex programs, the gpio
functions found in the xgpio.c file may be a better choice.
4. Is changing, editing, or adding to the xparameters.h file a good idea? Why or why not?
No, the xparameters.h file is regenerated every time the BSP is built by LibGen. This is a read-only
file.
5. Why is the bootloop program specified for FPGA configuration?
The bootloop program is a default program that is essentially a branch to *. Its purpose is to keep the
processor safely occupied after configuration until the actual application is downloaded. In normal
operation, the tested and debugged software application would be in this place.
6. The Run configuration is set for the Debug project configuration. What is the purpose for all of these
configurations?
SDK accommodates multiple setups for quickly choosing an object ELF application to download to
the simulator or hardware; this is a RUN configuration. Project configurations, such as Release,
Debug, and Profile, each allow the compiler/linker to generate a different ELF file based on tool
settings for each configuration. The Debug configuration is created by default during project creation.
80
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
Introduction
This lab will convert the stopwatch application of the "Application Development" lab from a softwarebased timing loop to an interrupt-driven, timer-based peripheral. The application program has been
mostly written for you and includes usage of the interrupt controller (GIC) and timer (TTC0) peripherals.
The application program performs the following regarding the interrupt:
Registers the interrupt controller interrupt service routine (ISR) with the processor interrupt data
structure
Registers the timer ISR with the interrupt controller interrupt data structure
You will be required to search BSP processor services documentation to find and use the correct
processor service calls that initialize the processor interrupt data structure and enable interrupts. The API
documentation for the interrupt controller (GIC) and timer (TTC0) device driver services will be examined.
The axi_timer is one of the most commonly used processor peripherals, so much of what you will learn
here will be useful for future projects.
Objectives
After completing this lab, you will be able to:
Investigate interrupt controller (GIC) and timer (TTC0) device driver services
Procedure
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab comprises three primary steps: You will create an SDK software application; add processor
services device drivers to the software application; and, finally, configure the Zynq EPP and test the
application.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this lab
from www.xilinx.com/training/downloads.htm. These are the original lab files and do not contain any work
that you may have previously completed.
www.xilinx.com
1-877-XLX-CLAS
81
Software Interrupts
Lab Workbook
Step 1
In this step, you will create a software application in SDK by using the provided C
source code. You must complete the code, then add it and the LCD display drivers to
the project. A linker script will be generated and the compiler options set.
Keep working with the SDK workspace that you started using in the "Application
Development" lab. Even if you are not able to complete or get subsequent labs working,
the workspace is valid for use.
This lab adds another software application project to the existing SDK project,
illustrating that multiple applications can be created in one SDK workspace. Every
subsequent lab in this course will add a new software application to the SDK
workspace.
1-1.
82
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
1-1-4. Verify that your workspace appears similar to the following figure.
1-2.
www.xilinx.com
1-877-XLX-CLAS
83
Software Interrupts
Lab Workbook
84
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
1-2-2. Select the Empty Application project template. Enter interrupt-lab3 in the Project name field
and click Next.
www.xilinx.com
1-877-XLX-CLAS
85
Software Interrupts
Lab Workbook
1-2-3. Select Target an existing Board Support Package, select lab2-bsp, and click Finish.
86
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
1-2-5. In the Select dialog box, expand General, select File System, and click Next.
www.xilinx.com
1-877-XLX-CLAS
87
Software Interrupts
Lab Workbook
Use the default Into folder directory path, which copies the files into the src folder of the current
project.
88
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
1-2-9. In the Project Explorer tab, note that folder icon for interrupt-lab3 has a red X. Expand the folder
and note that the src folder and its lab3.c file also have a red X.
1-3.
Generate a linker script, locating the Code, Data, Stack, and Heap sections
in on-chip block RAM. The off-chip DDR3 RAM will not be used in this lab.
1-3-1. In the Project Explorer tab, right-click the interrupt-lab3 project and select Generate Linker
Script.
www.xilinx.com
1-877-XLX-CLAS
89
Software Interrupts
Lab Workbook
1-3-2. Select ps7_ddr_0_S_AXI_BASEADDR as the memory area used from the Code Sections, Data
Sections, and Heap and Stack drop-down lists.
1-4.
Verify the C/C++ Build properties. Make sure that compiler optimization is
set to None and that debugging symbols are enabled for this new
configuration. Verify that the proper linker script is selected.
Fix the program bug in the application.
1-4-1. In the Project Explorer tab, right-click the interrupt-lab3 project and select C/C++ Build
Settings.
1-4-2. In the Configuration area, select Release from the drop-down list.
1-4-3. In the Tool Settings tab, expand ARM gcc compiler, select Optimization, and set the
Optimization Level to None.
1-4-4. Select Debugging in the properties list just below Optimization and set the Debug Level to None.
90
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
1-4-5. In the Tool Settings tab, select Linker Script under ARM gcc linker and verify that the linker
script file is ../src/lscript.ld.
91
Software Interrupts
Lab Workbook
1-4-8. Click the red symbol next to the vertical scroll bar to display the line in the file that is causing the
error.
The error is the undefined label INTC_DEVICE_ID0. The problem is just a typo where the ID0
should be a ID.
Step 2
The stopwatch application is mostly finished. What remains is enabling the interrupt for
the device and enable the timer interrupt.
You will use driver documentation sources.
2-1.
Open lab3.c and find the commented location for enabling the interrupt for
the device and enabling the timer interrupt.
Add the appropriate code, save the file, and verify error-free compilation.
92
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
If the file is not already open, expand the lab2-bsp project in the Project Explorer tab, then
double-click the system.mss file to open it.
2-1-2. Click the Documentation link next to scugic.
www.xilinx.com
1-877-XLX-CLAS
93
Software Interrupts
Lab Workbook
2-1-3. Click the Files, then Globals, and then Functions links.
94
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
2-1-4. Click the xscugic.h link and view the function details.
Question 1
Where is the BaseAddress parameter found for ps7_scutimer_0?
Question 2
What level of driver service is this? How can you tell? What file would be referenced to understand its
operation?
www.xilinx.com
1-877-XLX-CLAS
95
Software Interrupts
Lab Workbook
Step 3
In this last step, you will configure the Zynq EPP, download the application, and test the
program for proper stopwatch operation. The hardware portion of the design has
already been implemented for you. This is the same configuration that was used in the
"Basic System Implementation" lab. This lab assumes that the ZC702 hardware board
and download cabling are in place.
3-1.
Configure the Zynq EPP with the bitstream that has been provided for you.
3-1-1. Make sure that the hardware board is set up and turned on.
3-1-2. In SDK, select Xilinx Tools > Program FPGA.
3-1-3. In the Bitstream field, browse to the C:\training\EmbSysSoft\Support directory and select the
system.bit file.
3-2.
Create a new Run configuration named interrupt-lab3 Debug and test the
application.
3-2-1. In the Project Explorer tab, right-click the interrupt-lab3 software application and select Run As
> Run Configurations.
96
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
Project: interrupt-lab3
START BTN3
STOP BTN2
RESET BTN1
www.xilinx.com
1-877-XLX-CLAS
97
Software Interrupts
Lab Workbook
3-2-6. To terminate the run, click the red Terminate icon in the Console window. If not visible, select
Xilinx Tools > XMD Console and enter stop in the XMD command box.
Question 3
Is the stopwatch program more accurate with a timer than the software loop from the "Application
Development" lab?
Conclusion
In this lab, you converted a software loop-based stopwatch to an interrupt-driven, timer-based stopwatch.
You researched scu_gic and scu_timer in the documentation to enable the interrupt.
98
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Software Interrupts
Answers
1. Where is the BaseAddress parameter found for ps7_scutimer_0?
In the xparameters_ps.h file, the symbol is defined as XPAR_SCUTIMER_BASEADDR.
2. What level of driver service is this? How can you tell? What file would be referenced to understand its
operation?
[ANSWER]
3. Is the stopwatch program more accurate with a timer than the software loop from the "Application
Development" lab?
Yes, while the software timing loop may be predictable, it is difficult to determine how much time the
rest of the main{} program loop takes to execute. With a hardware timer, the main{} loop starts every
10 ms. As long as main{} takes less than 10 ms, the timer will be accurate to the clock frequency.
www.xilinx.com
1-877-XLX-CLAS
99
Lab Workbook
Debugging
Lab 4: Debugging
Cortex-A9 Processor and Zynq EPP ZC702 Board
Introduction
This lab will introduce you to the SDK software debugger. The stopwatch application created in the
previous lab will be set up for debugging and observations will be made by using the debuggers features.
You are encouraged to experiment with the various debug options.
Objectives
After completing this lab, you will be able to:
Procedure
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab comprises three primary steps: You will open a pre-built basic hardware system and create an
SDK software application project; configure the Zynq EPP, create a Debug Run configuration, and
download the application; and, finally, use the features of the debugger.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this lab
from www.xilinx.com/training/downloads.htm. These are the original lab files and do not contain any work
that you may have previously completed.
Step 1
The first step of this lab is to create an SDK software application as you did in previous
labs. The C code source from the previous lab will be used as the target for debugging.
The software application will compile and link without errors.
Keep working with the SDK workspace that you started using in the "Application
Development" lab. Even if you are not able to complete or get subsequent labs working,
the workspace is valid for use.
This lab adds another software application project to the existing SDK project,
illustrating that multiple applications can be created in one SDK workspace. Every
subsequent lab in this course will add a new software application to the SDK
workspace.
www.xilinx.com
1-877-XLX-CLAS
101
Debugging
1-1.
Lab Workbook
102
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
1-1-4. Verify that your workspace appears similar to the following figure.
www.xilinx.com
1-877-XLX-CLAS
103
Debugging
1-2.
Lab Workbook
104
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
1-2-2. Select the Empty Application project template. Enter debug-lab4 in the Project name field and
click Next.
www.xilinx.com
1-877-XLX-CLAS
105
Debugging
Lab Workbook
1-2-3. Select Target an existing Board Support Package, select lab2-bsp, and click Finish.
106
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
1-2-5. In the Select dialog box, expand General, select File System, and click Next.
www.xilinx.com
1-877-XLX-CLAS
107
Debugging
Lab Workbook
1-2-8. Use the default Into folder directory path, which copies the files into the src folder of the current
project.
1-3.
Generate a linker script, locating the Code, Data, Stack, and Heap sections
in on-chip block RAM. The off-chip DDR RAM will not be used in this lab.
1-3-1. In the Project Explorer tab, right-click the debug-lab4 project and select Generate Linker Script.
108
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
1-3-2. Select ps7_ddr_0_S_AXI_BASEADDR as the memory area used from the Code Sections, Data
Sections, and Heap and Stack drop-down lists.
1-4.
Verify the C/C++ Build properties. Make sure that compiler optimization is
off and that the Debug Level is Maximum for the Debug configuration.
Verify that the proper linker script has been selected.
1-4-1. In the Project Explorer tab, right-click the debug-lab4 project and select C/C++ Build Settings.
1-4-2. In the Configuration area, select Debug [ Active ] from the drop-down list.
www.xilinx.com
1-877-XLX-CLAS
109
Debugging
Lab Workbook
1-4-3. In the Tool Settings tab, expand ARM gcc compiler, select Optimization, and set the
Optimization Level to None (-O0).
110
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
Step 2
In this step, you will configure the Zynq EPP, set up the project for debugging, download
the application, and open the SDK Debug perspective. The hardware portion of the
design has already been implemented for you. This is the same configuration that was
used in the previous labs. This lab assumes that the ZC702 hardware board and
download cabling are in place.
2-1.
Configure the Zynq EPP with the bitstream that has been provided for you.
2-1-1. Make sure that the hardware board is set up and turned on.
2-1-2. In SDK, select Xilinx Tools > Program FPGA.
2-1-3. In the Bitstream field, browse to the C:\training\EmbSysSoft\Support directory and select the
system.bit file.
2-2.
2-2-1. In the Project Explorer tab, right-click the debug-lab4 project and select Debug As > Debug
Configurations.
www.xilinx.com
1-877-XLX-CLAS
111
Debugging
Lab Workbook
Project: debug-lab4
112
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
Step 3
In this step, you will use the debugger to research interrupt latency time by using
breakpoints, examine the contents of the memory-mapped timer peripheral via the
Memory tab, determine the time spent updating the LCD display by using breakpoints,
and identify how to free run and halt a program thread.
3-1.
Set up the project for debugging, setting a breakpoint in the timer interrupt
handler.
www.xilinx.com
1-877-XLX-CLAS
113
Debugging
Lab Workbook
).
This line is the next statement following an assignment to variable zx. Note that the breakpoint
that you just set appears in the Breakpoints view (upper right pane, Breakpoints tab).
3-1-4. Click the Play/Resume button (green triangle
3-2.
Calculate the latency for entering the timer interrupt service routine.
3-2-1. Subtract the value of the local variable zx from the auto-reload value.
The timer interrupt occurred when the timer value reached zero. The timer continues to count
even after interrupting. The value of the local temporary variable zx is set to the current timer
value after entering the timer interrupt service routine (line 423).
Because the timer counts down from the auto-reload value, the result is the number of timer
ticksat ~2.5 ns per tickthat it took to get into the ISR. (ScuTimer runs at 400 MHz).
114
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
Question 1
Approximately how many clock ticks were required for the system to enter the timer interrupt? What does
this number represent in actual time?
Question 2
What does this time signify from a system view?
3-3.
3-3-1. In the bottom window, select the Memory tab (located in the same window as the Console tab).
If it not available, select Window > Show View and select Memory.
3-3-2. Click the green + sign in the Memory tab toolbar to add a memory monitor.
The Memory Monitor dialog box appears, requesting the address to be monitored.
www.xilinx.com
1-877-XLX-CLAS
115
Debugging
Lab Workbook
3-3-4. In the Outline tab (middle right side), scroll to the top of the list and double-click the
xparameters.h include file to open it.
3-3-5. Again, in the Outline tab, double-click the xparameters_ps.h file to open it.
3-3-6. Again, in the Outline tab, scroll down the list to find the base address of ScuTImer (the #define
name is XPAR_SCUTIMER_BASEADDR).
3-3-7. Click XPAR_SCUTIMER_BASEADDR in the Outline tab list and the line where it is defined is
highlighted in the window to the left.
#define XPAR_SCUTIMER_BASEADDR (XPS_SCU_PERIPH_BASE + 0x600) where
XPS_SCU_PERIPH_BASE is 0xF8F00000
3-3-8. Note the base address of XPAR_SCUTIMER_BASEADDR.
3-3-9. Return to the C/C++ Perspective (upper right of the SDK window
file which may already be open as a tab in the edit window.
If the system.xml file is not already open, expand the EmbSysSoftHWP project in the Project
Explorer tab (left side) and double-click the system.xml file to open it.
3-3-10. In the IP blocks present in the design list, click the ps7_scutimer_0 datasheet link to open its
datasheet.
Note: The datasheet is not available for the beta version.
The count vale register address is 0xF8F00604 (base address + 4).
3-3-11. Return to the SDK Debug perspective.
3-3-12. Click the green + sign in the Memory tab toolbar to add a memory monitor.
3-3-13. In the Memory Monitor dialog box, enter the base address of the ps7_scutimer_0 peripheral as
the memory address to monitor.
Remember to type the address as a hex value by using the 0x prefix.
3-3-14. Click OK.
Question 3
What is the base address of ScuTimer and the offset to the count register? How many bytes of memory
does this count register consume?
Question 4
What bsp source file might contain a #define for the base address of ScuTimer?
116
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
3-3-15. In the Variables window, right-click zx and select Format > Hexadecimal.
It is necessary to compare the count register value with the value of the local variable zx.
Unfortunately, the Count value register value is by default shown as hex and there is no way to
easily change its radix. However, the radix display format of the zx variable in the Variables
window can be easily changed.
The value of zx will be displayed in hex.
Question 5
Are the values of the variable zx and the Count value register the same? Should they be close? Why or
why not?
3-4.
Remove the existing breakpoint and set a new breakpoint. Calculate the
time spent servicing the LCD.
3-4-1. Open the lab4.c file again and scroll to line 423. Double-click the breakpoint marker in the left
margin, or the line number, to remove the breakpoint.
You could also have removed the breakpoint by right-clicking the breakpoint in the Breakpoints
window and selecting Remove.
3-4-2. Scroll up to line 304 and double-click the line number to set a new breakpoint.
This breakpoint is set at the next statement after the assignment to zx upon LCD update
completion.
3-4-3. Click the Play/Resume button to run to the breakpoint.
This operation may take a few seconds for the system to update.
On line 304, the general-purpose variable zx is used to calculate how much time is spent
servicing the LCD. This is the difference between the value of the timer before the LCD is
serviced (line 295) and the timer value read at line 304. At line 307, the calculation is complete
and zx can be observed.
Question 6
At ~2.5 ns per count, approximately how much time is spent servicing the LCD?
3-5.
www.xilinx.com
1-877-XLX-CLAS
117
Debugging
Lab Workbook
3-5-2. In the Breakpoints window toolbar, click the Skip All Breakpoints icon ( ).
Conclusion
In this lab, you used the debugger in SDK to debug a basic software application. You learned how to set
up a software project for debugging and how to use the features of the debugger.
118
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Debugging
Answers
Answers listed represent sample solutions only. Your results may differ depending on the version of the
software, service pack, or operating system that you are using.
1. Approximately how many clock ticks were required for the system to enter the timer interrupt? What
does this number represent in actual time?
About 202 clock ticks at ~2.5 ns per tick. Approximately 5 s.
2. What does this time signify from a system view?
This is the interrupt latency time.
3. What is the base address of ScuTimer and the offset to the count register? How many bytes of
memory does this count register consume?
0xF8F00600 is the ScuTimer base address. The count register offset if (0xF8F00600 + 0x4). Four
bytes, 0xF8F00604 0xF8F00607.
4. What bsp source file might contain a #define for the base address of ScuTimer?
The xscutimer_hw.h file found by expanding lab2-bsp > ps7_cortexa9_0 > libsrc > scutimer_v1_00a >
src. The parameter name can be found in the Outline list (XSCUTIMER_COUNTER_OFFSET).
5. Are the values of the variable zx and the Count value register the same? Should they be close? Why
or why not?
The value of zx and Count register are not the same or even close. They would only be the same or
close by coincidence. The timer is a peripheral on the SCU unit and does not stop when the
processor is halted. The debugger reads the timer value some amount of time after the breakpoint is
reached.
6. At ~2.5 ns per count, approximately how much time is spent servicing the LCD?
Typically, about 1 msec.
zx (number of counts) * 2.5 ns = ~1 ms.
www.xilinx.com
1-877-XLX-CLAS
119
Lab Workbook
Introduction
A device driver is a lower-level service that typically interfaces the software application with a specific
piece of hardware. Device drivers can either be part of your software application project or part of the
board support package (BSP). When it is part of your application project, the source code for the drivers
must always be present and compiled/linked with your application. If the driver is used often and well
debugged, a better alternative is to make it a service of the BSP. This makes it easier to distribute and the
programmer does not have to be concerned with keeping track of it in the application project.
All Xilinx-provided peripherals have device drivers that are included in the BSP when they are used.
When a custom peripheral is created via the Create and Import Peripheral Wizard, a skeleton software
driver for BSP inclusion is provided, along with a hardware skeleton.
Because this lab is a software exercise and there is limited time, you will not be able to build a custom
piece of hardware and a software driver for it. Instead, you will create a custom driver for the axi_gpio bus
peripheral. The process will illustrate the ability of the SDK to support multiple software drivers for any
given hardware peripheral.
The hardware platform in this class uses an axi_gpio peripheral as a controller for the LCD display on the
Zynq EPP ZC702 evaluation board. The timer software application project in the "Application
Development" lab included a low-level driver for the LCD display. In this lab, you will move the LCD
device driver from the software application into the BSP as an included service.
The structure of the device driver environment is sensitive to directory/file names and locations.
Generating *.mdd and *.tcl definition files will be necessary. To make the task easier, you will use the
Create and Import Peripheral Wizard in XPS to generate dummy hardware peripheral and device driver
skeletons. You will ignore the hardware portion and build on the software structure that the wizard
generates.
Objectives
After completing this lab, you will be able to:
Create a device driver skeleton by using the Create and Import Peripheral Wizard
Procedure
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab comprises four primary steps: You will create a skeleton device driver; add the LCD device driver
from the "Application Development" lab and create the BSP; create a project in SDK with the application
program from the "Application Development" lab; and, finally, verify proper device driver operation by
downloading to the hardware and testing.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this lab
from www.xilinx.com/training/downloads.htm. These are the original lab files and do not contain any work
that you may have previously completed.
www.xilinx.com
1-877-XLX-CLAS
121
Lab Workbook
Step 1
The first step of this lab will be to create an LCD dummy peripheral using the Create
and Import Peripheral Wizard in XPS to generate the skeleton structure of the device
driver.
1-1.
1-1-1. Select Start > All Programs > Xilinx ISE Design Suite > EDK > Xilinx Platform Studio to
launch XPS.
1-1-2. In the Xilinx Platform Studio dialog box, click Create New Blank project.
122
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-3. In the Create New XPS Project dialog box, browse to the C:\training\EmbSysSoft\labs directory to
specify a project file and append the lab6 directory. Accept the default system.xmp project file.
www.xilinx.com
1-877-XLX-CLAS
123
Lab Workbook
1-1-6. Click OK to close the How to Add IPs to Design dialog box.
124
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
The Welcome window for the Create and Import Peripheral Wizard appears.
www.xilinx.com
1-877-XLX-CLAS
125
Lab Workbook
1-1-9. In the Peripheral Flow dialog box, select Create templates for a new peripheral and click Next.
126
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-10. In the Repository or Project dialog box, select To an XPS project and click Next.
127
Lab Workbook
1-1-12. In the Bus Interfaces dialog box, select AXI4-Lite: Simpler, non-burst control register style
interface and click Next.
128
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-13. In the IPIF (IP Interface) Services dialog box, deselect all options and click Next.
www.xilinx.com
1-877-XLX-CLAS
129
Lab Workbook
1-1-14. In the IP Interconnect (IPIC) dialog box, review the settings and click Next.
130
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-15. In the Peripheral Simulation Support dialog box, deselect Generate BFM simulation platform if
necessary and click Next.
www.xilinx.com
1-877-XLX-CLAS
131
Lab Workbook
1-1-16. In the Peripheral Implementation Support dialog box, select Generate template driver files to
help you implement software interface and click Next.
132
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
1-1-17. Review the summary of the peripheral that will be created and click Finish.
www.xilinx.com
1-877-XLX-CLAS
133
Lab Workbook
1-1-18. Using Windows Explorer, verify that the new drivers directory has been added to the XPS project
structure.
Question 1
Browse to the C:\training\EmbSysSoft\labs\lab6\drivers\lcd_v1_00_a\src directory. This directory is where
the source files for the device driver reside. What files have been placed there by the wizard?
Question 2
What is in the lcd.c file?
No hardware was changed or created so the design does not have to be re-implemented. The
goal of the process is to associate a custom driver to existing peripheral hardware. The new
peripheral is named lcd but the hardware is actually an unmodified gpio peripheral.
1-1-19. Close XPS.
134
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 2
The skeleton driver that was added in the last step needs to be customized as an
axi_gpio peripheral driver. You will accomplish this by modifying the lcd.mdd device
driver description file.
The lcd.c device driver file from the "Application Development" lab will replace the
skeleton version of the same name that was generated by the wizard. The generated
lcd.h file will not be needed because the drivers in lcd_ml605.c will actually be calling
the axi_gpio drivers that are already in the BSP.
This is a valuable feature in that device drivers in the BSP (or software platform) can
call other device driver services in the same BSP.
In this step, you will:
o Modify lcd.mdd to point to the axi_gpio peripheral by using SDK.
o Replace the lcd.c file located in the C:\training\EmbSysSoft\labs\lab6\drivers\
lcd_v1_00_a\src directory with custom driver files from the C:\training\EmbSysSoft\
Support\MB_ML605 directory.
o Add the path for the custom lcd driver files to the User-Defined Software
Repositories.
o Create a new BSP and modify its settings to use the lcd driver for the LCD display.
o Regenerate the BSP.
2-1.
Modify the configuration files that integrate the driver source into the BSP
are in the C:\training\EmbSysSoft\labs\lab6\drivers\lcd_v1_00_a\data
directory.
The lcd_v2_1_0.mdd file needs to be modified so that this software driver is
associated with the axi_gpio peripheral. The lcd_v2_1_0.tcl file does not
need modification because it generates symbols that will not be used in the
xparameters.h file.
www.xilinx.com
1-877-XLX-CLAS
135
Lab Workbook
Figure 5-16: Associating the lcd Driver with the axi_gpio Peripheral
Changing this symbol directs the association on the device driver to the name of the supported
hardware. In this step, you are indicating that this driver is for the axi_gpio peripheral, as opposed
to the non-existent LCD hardware that was specified, but not used, when the skeleton was
created with the Create and Import Peripheral Wizard.
2-1-4. Save and close the lcd_v2_1_0.mdd file.
2-1-5.
2-1-6. Using Windows Explorer, copy the lcd_zc702.c and lcd_driver.h files from the
C:\training\EmbSysSoft\Support directory to the
C:\training\EmbSysSoft\labs\lab6\drivers\lcd_v1_00_a\src directory.
This replaces the skeleton custom driver source file generated by the Create and Import
Peripheral Wizard with the new custom lcd driver source files. Note that the file name is not
important as the make utility will compile all the *.c files in the src directory.
Note: Open the lcd_selftest.c from the directory
C:\training\EmbSysSoft\labs\lab6\drivers\lcd_v1_00_a\src directory. Comment the line no. 13
(#include "xio.h").
2-2.
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-2-2. To the right of the Local Repositories area, click New, then browse to and select the
C:\training\EmbSysSoft\labs\lab6 directory and click OK.
The path should appear in the Local Repositories list.
www.xilinx.com
1-877-XLX-CLAS
137
2-3.
Lab Workbook
The newly created device driver must be associated with the instance of
the LCD display. Currently, the GPIO driver is selected.
In this step, you will create a new BSP named lab6-bsp and set the driver
for its LCD peripheral to be the new lcd driver.
2-3-1. In SDK, select File > New > Xilinx Board Support Package.
2-3-2. In the Xilinx Board Support Package Project dialog box, enter these settings and click Finish.
o
138
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-3-3. In the left navigation pane, expand Overview and select drivers. For the Character_LCD_2x16
instance, select lcd from the Driver column drop-down list.
Figure 5-19: Associating the lcd Driver with the Character_LCD_2x16 Instance
This assigns the custom lcd driver that was just created to the Character_LCD_2x16 instance in
the design.
2-3-4. Click OK to close the Board Support Package Settings dialog box and start BSP regeneration.
2-3-5. In the Console window, verify that the BSP is built without errors.
www.xilinx.com
1-877-XLX-CLAS
139
Lab Workbook
2-3-6. In the Project Explorer tab, expand the lab6-bsp project and verify that the lcd_v1_00_a directory
was added to the microblaze_0\libsrc directory.
Question 3
Which of the preceding steps resulted in lcd as an option for the axi_gpio driver in the Software Platform
Settings dialog box?
Question 4
In the Project Explorer pane, double-click the lcd_driver.h file to open it. Note that functions are divided
into External and Internal. External functions are those called by other functions outside of the driver.
What parameter is passed into all external functions? Why would this parameter be needed?
140
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Question 5
If errors occurred in the BSP build after you added the new driver, what might the problem be?
Step 3
The newly added driver is ready to be tested. You will use the application from the
"Application Development" lab to test the driver. Note that the LCD display driver, which
was part of the "Application Development" lab application project, will not be present.
The same lcd driver is now part of the BSP. Here you will create an SDK software
application project and import the lab6 source file into it.
3-1.
In this step, you will create another software application project that uses
the LCD by relying on the presence of the LCD drivers in the BSP.
www.xilinx.com
1-877-XLX-CLAS
141
Lab Workbook
The next step is to associate a board support package to the project. The board support package
contains all the software drivers for system components.
3-1-3. Select Target an existing Board Support Package, select lab6-bsp, and click Finish.
3-1-4. In the Project Explorer tab, expand the lcd_driver-lab6 project, right-click the src directory, and
select Import.
3-1-5. In the Select dialog box, expand General, select File System, and click Next.
3-1-6. In the From directory field, browse to the C:\training\EmbSysSoft\Support directory and click OK.
3-1-7. Select lab6.c for import.
Use the default Into folder directory path, which copies the files into the src folder of the current
project.
3-1-8. Click Finish.
The application is automatically built.
3-1-9. Check the linker script settings for the lcd_driver-lab6 C project.
Hint: Right-click the project name.
3-2.
Generate a linker script, locating the Code, Data, Stack, and Heap sections
in on-chip block RAM.
3-2-1. In the Project Explorer tab, right-click the lcd_driver-lab6 project and select Generate Linker
Script.
3-2-2. Select ps7_ddr_0_S_AXI_BASEADDR as the memory area used from the Code Sections, Data
Sections, and Heap and Stack drop-down lists.
3-2-3. Click Generate. Click Yes to overwrite the existing linker script file if prompted.
IMPORTANT: When you click Generate, the application is automatically compiled and linked. If
there is an error, repeat the step to generate the linker script.
Question 6
How do you know that the LCD drivers are part of the BSP?
142
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 4
You are now ready for the big test. Configure the Zynq EPP, download the program,
and make sure that the stopwatch application is still working.
This lab assumes that the ZC702 hardware board and download cabling are in place.
4-1.
Configure the Zynq EPP with the bitstream that has been provided for you.
4-1-1. Make sure that the hardware board is set up and turned on.
4-1-2. In SDK, select Xilinx Tools > Program FPGA.
4-1-3. In the Bitstream field, browse to the C:\training\EmbSysSoft\Support directory and select the
system.bit file.
www.xilinx.com
1-877-XLX-CLAS
143
Lab Workbook
START BTN3
STOP
RESET BTN1
BTN2
Question 7
Do you expect any difference in performance, whether the LCD drivers are part of the BSP or
application project, as in the "Application Development" lab?
Conclusion
In this lab, you created a new software driver for the axi_gpio peripheral. You used the Create and Import
Peripheral Wizard to create the skeleton framework and used the lcd driver from the "Application
Development" lab with minor modifications as the main source for this driver.
144
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Answers
1. Browse to the C:\training\EmbSysSoft\labs\lab6\drivers\lcd_v1_00_a\src directory. This directory is
where the source files for the device driver reside. What files have been placed there by the wizard?
lcd.c
lcd.h
lcd_selftest.c
Makefile
www.xilinx.com
1-877-XLX-CLAS
145
Lab Workbook
Introduction
This lab guides you through the process of adding the custom IP created in the "Building Custom AXI IP
for an Embedded System" lab to an existing processor system using XPS and then integrating the
processor system with other logic in an ISE software design. At the end of the lab, you will download the
software and design to hardware using the XMD tool.
Objectives
After completing this lab, you will be able to:
Place the processor system in the hierarchy of a Project Navigator software project
Add other logic to an Project Navigator tool project that contains a processor system
Procedure
In this lab, you will extend the hardware design from the "Adding IP to a Hardware Design" lab by adding
to the existing processor system the AXI-based LCD controller that you built and tested in the two
previous labs, AXI_GPIO. This controller interfaces with logic to control the rotary switch that is on the
evaluation board.
In this lab, the processor system will be an XPS-based project that is a sub-project of a greater Project
Navigator project. In the current design, it is the sole component of the ISE software project. In Project
Navigator, you will expand the design by:
The software for this project is provided as an exported, archived SDK project. You will create a new SDK
workspace and import the archived project.
Working in Project Navigator, you will build out the design to include a new top-level component and other
logic. These files are provided for you. The top-level file lacks an instantiation of the processor system
component. Your task will be to have the tools generate an instantiation template for the processor
system. You will then copy and complete the processor system instantiation in the top-level design
component.
The other logic provided is a rotary switch decoder. The rotary switch outputs two signals that produce a
quadrature square wave. The direction of the rotary switch is determined by which signal is leading or
lagging by its edges:
www.xilinx.com
1-877-XLX-CLAS
147
Lab Workbook
Switch closures, by nature, are noisy. The logic that is provided debounces all of the input signals,
detects the quadrature motion, and decodes it into two new signals:
ROTARY_EVENT_OUT: a single clock-width pulse that indicates that there was movement on the
switch
ROTARY_LEFT_OUT: at a high level when the last rotation was to the left
The three outputs of the rotary switch logic will be connected to the input pins of the AXI_GPIO
component so that the software can read the states. The ROTARY_EVENT_OUT out signal is a very
short pulse indicating that there has been activity on the switch in the left or right direction based on the
state of ROTARY_LEFT_OUT. Because it is difficult to capture ROTARY_EVENT_OUT in software, it will
also be attached to the interrupt input pin of the processor so that the event can be captured in an
interrupt service routine. And because this signal is a pulse, its nature is such that it is a self-clearing,
edge-triggered, interrupt.
The completed design is illustrated in the following figure.
This lab is separated into steps that consist of general overview statements that provide information on
the detailed instructions that follow. Follow these detailed instructions to progress through the lab.
This lab comprises five primary steps: You will open the project; add the IP to the processor system;
create the software project, integrate into the ISE software project; and, finally, download and test the
design in hardware.
Note: If you are unable to complete the lab at this time, you can download the original lab files for this lab
from www.xilinx.com/training/downloads.htm. These are the original lab files and do not contain any work
that you may have previously completed.
148
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 1
The working directory for this lab (C:\training\embedded\labs\lab6) has already been
created for you. You will launch this project in the ISE software and complete the
design.
1-1.
Launch Project Navigator and open the project file. Then launch XPS for
the system component.
1-1-1. Select Start > All Programs > Xilinx ISE Design Suite > ISE Design Tools > Project
Navigator to launch Project Navigator.
1-1-2. Click Open Project. Browse to the C:\training\embedded\labs\lab6 directory, select
PS_ZC702.xise, and click Open.
1-1-3. In the Sources window, double-click system to launch XPS.
Step 2
To complete the processor system design, you will add a simple GPIO component and
the custom LCD controller IP that you created and verified in the previous labs. The
GPIO component will attach the rotary switch interface logic that you will add later to the
design.
2-1.
2-1-1. Select the IP Catalog tab in the left window and expand General Purpose IO to view the
available cores under the corresponding entries.
149
Lab Workbook
2-1-2. Double-click the AXI General Purpose IO core (version 1.01.b) in the IP Catalog tab and click
Yes to add this IP to the design.
The XPS Core Config dialog box will automatically appear. You will configure the core in the next
few steps.
2-1-3. To properly document the embedded system, change the name of the newly added GPIO to
Rotary_Switch_3Bit in the Component Instance Name Field.
2-1-4. Because you want to use only one channel, leave the Enable Channel 2 option de-selected.
2-1-5. Expand Channel 1 to view Channel 1-related configurable parameters.
2-1-6. Enter 3 in the GPIO Data Channel Width box.
You need only three inputs from the rotary switch logic in the ISE software.
2-1-7. Enter 1 for TRUE in the Channel 1 is Input Only box.
150
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
www.xilinx.com
1-877-XLX-CLAS
151
2-2.
Lab Workbook
The LCD_IP peripheral that was created in the "Building Custom AXI IP for
an Embedded System" lab will be added to the embedded system in this
step.
2-2-1. Select the IP Catalog tab in the left window and expand Project Local pcores > USER to view
the available custom, user-generated cores.
152
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-2-3. Scroll to the bottom of the All tab and verify that the value of the C_BOARD_TYPE parameter is
ZC702 and the C_LCD_WIDTH parameter is 11.
2-3.
2-3-1. Change the instance name of the peripheral to LCD_2x16 by clicking once in the Name column,
typing the new name, and then clicking any other screen object.
www.xilinx.com
1-877-XLX-CLAS
153
2-4.
Lab Workbook
The two newly added components have been configured and attached to
the AXI interconnect. In the next steps, the port signals specific to the
peripheral will be connected.
You will start with the rotary switch GPIO and create a three-bit bus net as
an input to the GPIO and make it external to the system.
2-4-1. Select the Ports tab and expand the Rotary_Switch_3Bit instance.
2-4-2. Right-click in the Net column of the GPIO_IO port of the Rotary_Switch_3Bit instance and make
sure that No Connection is selected.
If this is not the case, click No Connection in the Net column to delete the net. It has been
reported that the configuration wizard may automatically create an external net on the I/O pins of
the GPIO. This is not desired because you will be using the GPIO in input mode only.
Note: If the Net column is not visible, right-click any of the column names and select Net.
2-4-3. Click in the Net column of the GPIO_IO_I port of the Rotary_Switch_3Bit instance to enter edit
mode and then enter Rotary_IN for the net name and then click any other screen object.
2-4-4. After the net name has been selected, click again in the Net column and select Make External
from the Net column drop-down list.
154
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-4-5. Click in the Net column of the S_AXI_ACLK port of the Rotary_Switch_3Bit instance and verify
that clk_75mhz is selected. If not, select clk_75mhz as the net name from the Net column dropdown list.
2-5.
In the same manner, bring the output pins of the LCD controller external to
the embedded processor system.
155
Lab Workbook
2-5-3. Click in the Net column of the S_AXI_ACLK port of the LCD_2x16 instance and verify that
clk_75mhz is selected. If not, select clk_75mhz as the net name from the Net column drop-down
list.
2-6.
2-6-1. Select the Addresses tab and expand processing_system7_0s Address Map. Verify that all
peripherals have assigned addresses.
2-7.
One of the inputs from the rotary switch signal conditioning module is
producing a pulse, a single clock cycle wide, every time the knob is
rotated. This signal is a great candidate to be an interrupt to the processor.
In this step, you will attach this signal directly to the processor interrupt
input pin.
2-7-1. Select the Ports tab and expand the processing_system7_0 component.
2-7-2. Locate the IRQ_F2P signal in the list.
156
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-7-3. Right-click in the Name column of the IRQ_F2P port of the processing_system7_0 instance
and select New Connection.
2-8.
2-8-1. Select the Ports tab and expand the clock_generator_0 component.
2-8-2. Locate the CLKOUT1 port that is connected to the clk_75mhz signal in the list.
www.xilinx.com
1-877-XLX-CLAS
157
Lab Workbook
2-8-3. Click in the Net column and select Make External from the Net column drop-down list.
158
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-8-7. At line no. 36, connect the Rotary_IN[2] signal to the interrupt port of the processor.
Question 1
Ports are initially No Connection. What happens in the MHS file when you select New Connection? What
happens if you type in a net name instead?
Question 2
What does making a net name external do in the MHS file?
Question 3
Where are the default values for peripheral parameters found?
www.xilinx.com
1-877-XLX-CLAS
159
Lab Workbook
Step 3
An SDK software project has been created and archived for you. In this step, you will
learn how to import an archived software project into a new workspace. The imported
project will be compiled and an ELF file will be generated.
3-1.
160
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Once selected, this workspace directory should not move because the SDK project file pointers
are referenced by absolute directory location.
www.xilinx.com
1-877-XLX-CLAS
161
3-2.
Lab Workbook
Your software team has been busy writing the software for this project.
They have taken advantage of the feature to develop software
independently from the hardware in SDK. The finished software project was
archived. In this step, you will import the SDK project that the software
team exported to a zip file.
3-2-1. In SDK, select File > Import. Expand the General folder, select Existing Projects into
Workspace, and click Next.
162
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
3-2-3. Make sure that the lab6-bsp software platform, lab6-app application project, and zynq_fsbl_0
application are all selected. Click Finish.
www.xilinx.com
1-877-XLX-CLAS
163
Lab Workbook
3-2-4. In the C/C++ Projects tab, expand lab6-app > src and double-click the RotarySwitchLCD.c
application to open it.
Step 4
The ISE software project currently has only the processor system component at the top
level. In this step, you will add a new top-level entity to the design and instantiate the
processor system component into it. You will also add logic to decode the movement of
the rotary switch, add and update the user constraints file, and add the software ELF
file.
4-1.
A top-level VHDL file has been provided. It is missing the processor system
component instantiation. Another component file that conditions the rotary
switch sensor is provided in its entirety. In this step, you will add both files
to the ISE software project.
4-1-1. Select Project > Add Copy of Source. Browse to the C:\training\embedded\support directory,
select Rotary_LCD_TOP.vhd, and click Open.
4-1-2. Click OK to accept the adding of the file to the project with Association to All flows.
4-1-3. In the same way, add the rotary_switch.vhd design file, located in the same directory.
This module is for debouncing the switch contacts and decoding the movement of the rotary
switch.
164
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
4-1-4. In the Hierarchy window, verify that Rotary_LCD_TOP.vhd appears at the top level of the design,
as indicated by the three-square icon next to the file name.
4-2.
In this step, you will create an instantiation template for the system
embedded processor component and copy-and-paste the VHDL component
declaration and port map statement into the top-level Rotary_LCD_TOPMB.vhd module at the specified, commented locations.
In the Hierarchy window, you may have noticed that the system component
is outside of the designs hierarchical tree. This is because it needs to be
instantiated in the top level of the design. Once properly instantiated, the
ISE tool will re-generate the hierarchical view.
4-2-1. In the Hierarchy window, select system. In the Processes window, expand Design Utilities and
double-click View HDL Instantiation Template. Click OK in the To Instantiate the Embedded
Processor System dialog box.
4-2-2. Copy the system component and attribute statements.
4-2-3. In the Hierarchy window, double-click the Rotary_LCD_TOP.vhd file to open it.
4-2-4. After the comment at line 65, paste the system component and attribute statements.
4-2-5. In the same way, copy-and-paste the system instantiation statement after the comment at line
121.
Note that this statement is incomplete because local signals have not been included in the port
map. A completed Rotary_LCD_TOP.vhd is printed at the end of this lab.
www.xilinx.com
1-877-XLX-CLAS
165
4-3.
Lab Workbook
The port map instantiation template for the processor system does not
contain the names of the actual port parameters needed to hook the
signals in the system component to the rest of the design.
Connect the port map of the Inst_system component instance of system to
the following port assignments.
Inst_system: system PORT MAP(
CLK_N => CLK_N,
CLK_P => CLK_P,
reset_pin => reset_pin,
processing_system7_0_MIO => processing_system7_0_MIO,
processing_system7_0_PS_SRSTB => processing_system7_0_PS_SRSTB,
processing_system7_0_PS_CLK => processing_system7_0_PS_CLK,
processing_system7_0_PS_PORB => processing_system7_0_PS_PORB,
processing_system7_0_DDR_Clk => processing_system7_0_DDR_Clk,
processing_system7_0_DDR_Clk_n => processing_system7_0_DDR_Clk_n,
processing_system7_0_DDR_CKE => processing_system7_0_DDR_CKE,
processing_system7_0_DDR_CS_n => processing_system7_0_DDR_CS_n,
processing_system7_0_DDR_RAS_n => processing_system7_0_DDR_RAS_n,
processing_system7_0_DDR_CAS_n => processing_system7_0_DDR_CAS_n,
processing_system7_0_DDR_WEB_pin => processing_system7_0_DDR_WEB_pin,
processing_system7_0_DDR_BankAddr => processing_system7_0_DDR_BankAddr,
processing_system7_0_DDR_Addr => processing_system7_0_DDR_Addr,
processing_system7_0_DDR_ODT => processing_system7_0_DDR_ODT,
processing_system7_0_DDR_DRSTB => processing_system7_0_DDR_DRSTB,
processing_system7_0_DDR_DQ => processing_system7_0_DDR_DQ,
processing_system7_0_DDR_DM => processing_system7_0_DDR_DM,
processing_system7_0_DDR_DQS => processing_system7_0_DDR_DQS,
processing_system7_0_DDR_DQS_n => processing_system7_0_DDR_DQS_n,
processing_system7_0_DDR_VRN => processing_system7_0_DDR_VRN,
processing_system7_0_DDR_VRP => processing_system7_0_DDR_VRP,
LEDs_8bit_GPIO_IO_O_pin => LEDs_8bit_GPIO_IO_O_pin,
Rotary_Switch_3Bit_GPIO_IO_I_pin => Rotary_db,
LCD_2x16_lcd_pin => LCD_2x16_lcd_pin,
CLK_FPGA => clk
);
4-4.
The user constraint file contains pin placement information and timing
constraints for the programmable logic.
Because the rotary switch and LCD peripherals have been added, a second
UCF file, which constrains the programmable logic pin numbers, has been
provided. In this step, you will add this file to the project and then
implement the complete design.
166
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
4-4-1. Select Project > Add Copy of Source. Browse to the C:\training\embedded\support directory,
select system_rotary.ucf, and click Open.
4-4-2. Click OK to accept the adding of the file to the project with Association to the implementation
flow.
4-4-3. In the Hierarchy window, select Rotary_LCD_TOP.vhd. In the Processes window, double-click
Generate Programming File.
The tool chain will be started with XST synthesis followed by implementation (translate, map,
place and route), finishing with BitGen.
This will take about seven to nine minutes. There will be some warnings that can be safely
ignored. At the end of this process, a bitstream file (.bit file extension) will be created.
You are now ready to download the design onto the board.
Note: There is a bug in the tool, which fails due to the bmm file creation. But it does generate the
BIT file.
Question 4
What is the value of Project Navigator being able to create an instantiation template for the processor
design?
Step 5
In this final step, you will use the ELF files, download the design into hardware, and
operate the system.
5-1.
Connect the ZC702 board to your machine. Open a terminal in SDK to view
the output of the software application. (Follow the instructions in the
"Adding and Downloading Software" lab to set up the board and SDK
terminal).
5-1-1. Select Xilinx Tools > XMD Console to start the XMD debugger to download and run the
program. In the shell, type the following commands in sequence:
connect arm hw
dow system/SDK/zynq_fsbl_0/Debug/zynq_fsbl_0.elf
download the bootloader file
con
continue or start execution
stop
www.xilinx.com
1-877-XLX-CLAS
167
Lab Workbook
Conclusion
In this lab, you integrated a processor system with other non-processor-related logic. The processor
system was treated as another component in a greater design.
Xilinx recommends using Project Navigator (or PlanAhead software) as the basis for your design. Add
a processor module and design the processor system in XPS and the software application in SDK.
Project Navigator will generate a processor instantiation template for the processor module that can be
incorporated with other logic in your design.
168
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Answers
1. Ports are initially No Connection. What happens in the MHS file when you select New Connection?
What happens if you type in a net name instead?
When New Connection is selected, XPS creates a new net base on the name of the peripheral
instance concatenated with the formal port name. You can override this by typing in a net name
yourself.
2. What does making a net name external do in the MHS file?
Making a net name external puts a global Port instance at the beginning of the MHS file. A new
component port signal of the original net name concatenated with _pin is created. This new port will
be visible as a connection to the processor system.
The port name will be the formal name on the processor instance in Project Navigator. This name can
be changed in the External Ports list.
3. Where are the default values for peripheral parameters found?
In the MPD file of the IP.
4. What is the value of Project Navigator being able to create an instantiation template for the processor
design?
This saves time via the generation of component and port map statements that can be copied and
pasted (Verilog is also supported). The template shows the formal port names of the signals that
make up the processor component. You would otherwise have to locate them manually in the MHS
file.
www.xilinx.com
1-877-XLX-CLAS
169
Lab Workbook
Objectives
After completing this lab, you will be able to:
Create an XPS project for the purpose of designing a custom bus peripheral
Create a custom IPIC using the Create and Import Peripheral (CIP) wizard
Modify the MPD and PAO skeleton files created by the CIP wizard
Use the Project Navigator project created by the CIP wizard to author the peripheral design
Procedure
The purpose of this lab is for you to design and build a custom AXI peripheral that can control the onboard LCD display that is used on many of the Xilinx evaluation boards. The challenge will be to
implement a design that is largely insensitive to the different board hardware requirements.
The lab will illustrate a design flow targeted for building AXI interface peripherals. A dummy project will be
created in XPS that will hold only the created peripheral. The Create and Import Peripheral (CIP) wizard
will be used to generate the peripheral pcores directory structure, skeleton design files, an ISE software
development project, and a Bus Functional Model (BFM) design/project (subject of subsequent lab). The
actual peripheral design development work will take place via the ISE software flow that will be created by
the CIP wizard. The purpose of this CIP wizard-created ISE software project is to provide a design
authoring environment and the ability to check HDL syntax. Synthesis and implementation should not be
performed in this lab.
www.xilinx.com
1-877-XLX-CLAS
171
Lab Workbook
You will use the Create and Import Peripheral (CIP) wizard of XPS to create a user peripheral IP Interface
(IPIC) and then modify the generated skeleton VHDL user design code to add the necessary code to
implement the LCD interface.
172
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 1
In this step you will create a dummy XPS project for the purpose of
designing an AXI-based peripheral. You will start from XPS because this is
the design stage of the peripheral and you will not be implementing the
design. This lab flow will guide you from design inception through
verification of HDL synthesis.
In this step, you will launch Xilinx Platform Studio and create a blank
project named system.xmp in the
C:\training\embedded\labs\lab4\All_Boards directory.
Because you are creating a generic AXI4-Lite peripheral, selecting the
target programmable logic component for this XPS project is not important.
Later, when the component is instantiated into the actual XPS embedded
design, PlatGen will customize the component for the programmable logic
selected in that targeted XPS project.
1-1-1. Select Start > All Programs > Xilinx ISE Design Suite > EDK > Xilinx Platform Studio to
launch XPS.
1-1-2. Click Create New Blank Project.
173
Lab Workbook
Because you are just using this project to create an AXI peripheral, any target device can be
used. In a sense, this is just a dummy project. The Create or Import Peripheral wizard will
generate source VHDL for the peripheral dummy. One of the parameters, later passed when the
peripheral is actually instantiated in the design, is the Xilinx programmable logic family part that is
being targeted.
1-1-4. If the target architecture is the Zynq architecture, de-select AXI Clock Generator and AXI Reset
Module. Accept the other entry default settings and click OK.
Figure 7-3: Creating a Blank Project with the Target Device NOT Important
XPS opens to a blank design. If an informational dialog box referring to the IP Catalog appears,
close it.
174
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 2
This step involves invoking the Create and Import Peripheral Wizard to
build the skeleton IPIC, an ISE software development project, and a Bus
Functional Model (BFM) (subject of a subsequent lab).
In the blank XPS design, you will start the Create and Import Peripheral
wizard and create an AXI peripheral named lcd_ip.
2-1-1. In XPS, select Hardware > Create or Import Peripheral to start the wizard.
The Welcome window for the Create and Import Peripheral Wizard appears.
www.xilinx.com
1-877-XLX-CLAS
175
Lab Workbook
2-1-3. In the Peripheral Flow dialog box, select Create templates for a new peripheral and click Next.
176
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-1-4. In the Repository or Project dialog box, select To an XPS project, as the tools will have already
made the proper project association, and click Next.
www.xilinx.com
1-877-XLX-CLAS
177
Lab Workbook
2-1-5. In the Name and Version dialog box, enter lcd_ip in the Name field, accept the default settings
for the various versions, and click Next.
178
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-1-6. In the Bus Interfaces dialog box, select AXI4-Lite and click Next.
2-2.
So far, the Create and Import Peripheral (CIP) wizard has specified a new
peripheral to be placed in the current XPS project. You will continue with
the wizard and select the features to be generated.
The CIP wizard can also generate a BFM simulation platform for later
peripheral simulation (performed in the "BFM Simulation" lab) and an ISE
software project as a peripheral development environment. Both of these
options will be enabled.
When finished, the Create and Import Peripheral Wizard will generate the
VHDL source code and MPD/PAO skeleton files. You will verify the success
of the CIP wizard by ensuring that the new IP appears in the USER section
of the IP Catalog.
www.xilinx.com
1-877-XLX-CLAS
179
Lab Workbook
2-2-1. In the IPIF (IP Interface) Services dialog box, select Software Reset and User logic software
register. De-select Include data phase timer and click Next.
180
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-2-2. In the User S/W Register dialog box, accept one software accessible register because you need
only one register to control the LCD. Click Next.
www.xilinx.com
1-877-XLX-CLAS
181
Lab Workbook
182
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-2-5. In the Peripheral Simulation Support dialog box, select Generate BFM simulation platform and
click Next.
www.xilinx.com
1-877-XLX-CLAS
183
Lab Workbook
2-2-6. In the Peripheral Implementation Support dialog box, select Generate ISE and XST project files
to help you implement the peripheral using XST flow and click Next.
184
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
2-2-7. Review the summary of the peripheral that will be created and click Finish.
www.xilinx.com
1-877-XLX-CLAS
185
Lab Workbook
2-2-9. Observe that the new lcd_ip peripheral appears under the USER section of the IP Catalog.
Question 1
What IPIC interfaces are you expecting to be generated?
Question 2
What are the names of the HDL files generated? Where are they located?
186
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Step 3
In this step, you will modify the skeleton MPD file that was created in Step
2. Normally, you would also modify the PAO file. However, this design does
not need any other design files.
Every embedded processor system component requires an MPD file that
specifies component port signals, user implementation parameters, and
build options.
The CIP wizard created a skeleton MPD file. As a result, most of the work
has been performed by the CIP wizard. All that is needed is for you to add
any user IP-specific ports and parameters to the file.
Question 3
What do the "" in the user port statement indicate?
www.xilinx.com
1-877-XLX-CLAS
187
Lab Workbook
3-2.
The PAO file dictates the order of synthesis for the files that make up the
peripheral. They must be in a hierarchical order with the top-level module
at the bottom of the file. Because the lab design is simple, it will be part of
the user_logic.vhd file that was created by the CIP wizard and is already
specified in the PAO file. No changes to this file will be necessary.
188
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Question 4
If other HDL resource files needed to be added, between which lines in the file would they be located?
Step 4
In this last step, you will launch the ISE software project that was created by the Create
and Import Peripheral Wizard. This project contains all of the files that make up the
peripheral.
You will modify the user_logic.vhd file to place the necessary logic to interface with the
LCD. Normally, you would instantiate the top level of the controlling logic that forms an
interface to the IPIC in this file. With lab time being short, you will just implement this
logic in the user_logic.vhd file.
The ISE software gives the designer an environment to add files, edit, check syntax,
and simulate submodules. You should not attempt to implement the design because it is
only an AXI peripheral, a fragment of the entire design.
4-1.
User custom ports and parameters must be added to the top level of the
embedded component and then instantiated in the lower levels of the
design to the user_logic.vhd module.
In this step you will add the user-defined parameters, the LCD port signal,
and its port and generic mapping to the lcd_ip-IMP component (the
lcd_ip.vhd file).
www.xilinx.com
1-877-XLX-CLAS
189
Lab Workbook
4-1-2. In the Hierarchy window, expand the various components and familiarize yourself with the design.
Question 5
Examine the Hierarchy window. What do all of these components represent?
190
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
4-1-5. Add the user-defined port lcd of width (0 to C_LCD_WIDTH -1) to the entity port statement under
the --USER ports added here comment.
www.xilinx.com
1-877-XLX-CLAS
191
Lab Workbook
4-1-7. Add a port mapping statement to actually make the connection to the LCD under the --USER
ports mapped here comment.
4-2.
In this step, the custom ports and parameters will be added to the
user_logic.vhd module.
In a typical design you would also instantiate your top-level design in this
module. Due to time constraints, you will place simple code in this file that
will demonstrate a design of a single write only register. The length and
format for this register uses the custom parameters to set the register
length and configuration.
192
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
4-2-2. Add the two user-defined parameters C_BOARD_TYPE and C_LCD_WIDTH to the entity generic
statement under the --USER generics added here comment.
You can copy-and-paste the code from the lcd_ip_v2_1_1-vhdl-code-file-snippet.txt file located in
the C:\training\embedded\support directory.
4-2-3. Add the user-defined port lcd of width (0 to C_LCD_WIDTH -1) to the entity port statement under
the --USER ports added here comment.
Figure 7-21: Adding the User-Defined Parameters and LCD Port Definition
www.xilinx.com
1-877-XLX-CLAS
193
Lab Workbook
4-2-4. Add the user logic under the --USER logic implementation added here comment.
4-3.
The XST synthesis tool can be used to check the syntax of the modified
user_logic.vhd. Actual synthesis and implementation is not performed
because these operations are performed by PlatGen and Project Navigator
when the new peripheral is instantiated in an actual design.
Question 6
Examine the entity port statement. List the IPIC signals that are used.
194
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
Question 7
Of the IPIC signals listed in the previous question, which ones are tied to a constant level and why?
Question 8
In Step 4-2, two VHDL generate statement were added to the user_logic.vhd file. What are the criteria for
generated logic implementation?
Question 9
What is the name of the register that is actually holding the value placed on the LCD output lines?
Conclusion
Use the Create and Import Peripheral (CIP) wizard to build an IPIC interface to your user logic. The
wizard creates the necessary folder structure, skeleton HDL files, and adds the PlatGen files (MPD, PAO)
to the project directory.
After creating a peripheral, use the Project Navigator project that the CIP wizard generated to add
additional code to the peripheral design under the user_logic.vhd file. Bring up any user-defined
parameters and I/O to the top-level peripheral file. The XST synthesis tool can also be used to check the
design HDL code syntax.
www.xilinx.com
1-877-XLX-CLAS
195
Lab Workbook
Answers
1. What IPIC interfaces are you expecting to be generated?
Reset/MIR Write to reset peripheral, read Machine Identification Register. One address decode for
a 32-bit register.
2. What are the names of the HDL files generated? Where are they located?
The files generated are lcd_ip.vhd and user_logic.vhd. They are located in the
C:\training\embedded\labs\lab4\All_Boards\pcores\lcd_ip_v1_00_a\hdl\vhdl directory.
3. What do the "" in the user port statement indicate?
The left side of the port assignment is the net name to assign the signal to. A "" indicates a null
assignment. This will default as a No Connection in the Ports tab of the System Assembly View tab
for the lcd signal.
4. If other HDL resource files needed to be added, between which lines in the file would they be
located?
Between lines 8 and 9. They would be hierarchal below user_logic.vhd and above all of the libraries.
5. Examine the Hierarchy window. What do all of these components represent?
The top-level file, lcd_ip.vhd, and the lower-level file, user_logic.vhd, were generated for you based
on the selections that you made in the Create and Import Peripheral Wizard.
The other files are instantiations of the IPIC components that make up this interface. At this point, you
add your logic components to user_logic.vhd.
6. Examine the entity port statement. List the IPIC signals that are used.
Bus2IP_Clk
Bus2IP_Reset
Bus2IP_Data
Bus2IP_BE
Bus2IP_RdCE
Bus2IP_WrCE
IP2Bus_Data
IP2Bus_RdAck
IP2Bus_WrAck
IP2Bus_Error
7. Of the IPIC signals listed in the previous question, which ones are tied to a constant level and why?
IP2Bus_Error is tied to 0. There will never be a peripheral error for this design.
8. In Step 4-2, two VHDL generate statement were added to the user_logic.vhd file. What are the criteria
for generated logic implementation?
The generate statements are based on the C_BOARD_TYPE parameter, which will be passed down
from the top level. This parameter makes the logic implementation based on the evaluation board that
is used. The KC705, ZC702 and Custom evaluation boards are currently supported. More could be
supported with additional generate statements.
The C_LCD_WIDTH parameter specifies the width of the lcd interface, which will vary based on the
196
www.xilinx.com
1-877-XLX-CLAS
Lab Workbook
evaluation board selected. The width options are three LCD control lines plus either a four-bit or
eight-bit LCD data bus.
9. What is the name of the register that is actually holding the value placed on the LCD output lines?
slv_reg0
www.xilinx.com
1-877-XLX-CLAS
197