TT Nios2 System Architect
TT Nios2 System Architect
TU-01004-2.0 Document last updated for Altera Complete Design Suite version: 11.0
Document publication date: June 2011
Subscribe
© 2011 Altera Corporation. All rights reserved. ALTERA, ARRIA, CYCLONE, HARDCOPY, MAX, MEGACORE, NIOS, QUARTUS and STRATIX words and logos are
trademarks of Altera Corporation and registered in the U.S. Patent and Trademark Office and in other countries. All other words and logos identified as trademarks or service
marks are the property of their respective holders as described at www.altera.com/common/legal.html. Altera warrants performance of its semiconductor products to current
specifications in accordance with Altera's standard warranty, but reserves the right to make changes to any products and services at any time without notice. Altera assumes no
responsibility or liability arising out of the application or use of any information, product, or service described herein except as expressly agreed to in writing by Altera. Altera
customers are advised to obtain the latest version of device specifications before relying on any published information and before placing orders for products or services.
Additional Information
Taking the Next Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info–1
Document Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info–2
How to Contact Altera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info–2
Typographic Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Info–2
This tutorial teaches you how to use the Quartus® II software and the
Nios® II Embedded Design Suite (EDS) to implement a digital picture viewer in a
Cyclone III FPGA. In this tutorial, you build a processor-based hardware system in
programmable logic for the Nios II Embedded Evaluation Kit, Cyclone® III Edition
(NEEK) and run software on it. The tutorial demonstrates the steps to build complete,
complex embedded designs using the Altera® design software.
1 You must use the specified spelling for names of files, components, and other objects,
for the tutorial design to function correctly with the software provided. For example,
the software application refers to hardware components by the names specified in this
tutorial. If you name a component differently, the software application does not
identify it correctly.
f For information about installing the Quartus II software, refer to the Altera Software
Installation and Licensing Manual.
f For additional information, refer to the USB-Blaster Download Cable User Guide.
To architect a system, you specify the design requirements and develop a suitable
design strategy to address each requirement. Design requirements include immediate
design goals of the product and features to keep your product commercially
successful in the future. You must consider desired application functionality, cost,
flexibility to add future features, time to market, and obsolescence.
Programmable logic solutions provide optimal flexibility in your architecture to add
features over time quickly and at low cost. For example, a programmable logic
solution enables you to add features such as graphics or video display to a
commercial implementation of the digital picture viewer quickly and cheaply.
Programmable logic solutions allow you to integrate all the parts of the design on a
single low-cost, low-power programmable logic device. They support short time to
market, and insulate your design from part obsolescence — the potential lack of
future support for specific microprocessors, LCD panels, LCD controllers, and flash
memory devices, for example — by providing the ability to migrate your design to
another device without extensive modification.
Therefore, this tutorial implements the digital picture viewer on a programmable
logic platform using Altera’s Qsys system integration tool.
Product design goals originate in customer requirements and become inputs to
system definition. System definition is the first step in the design process.
The following sections describe the Altera design flow for an embedded system, the
design requirements for the digital picture viewer design you implement in this
tutorial, the design strategies that dictate the decisions about the hardware
components in the implemented design, and the basic system description for the
digital picture viewer. By explaining the design flow, design requirements, and design
strategy in this chapter, this chapter teaches you the system architecture of the digital
picture viewer.
Design Flow
Figure 2–1 depicts the typical flow for embedded system design.
In Qsys
Define System
Select Components
Make Connections
Target Device
FPGA Configuration File Software Application File
In this flow, you specify the system definition using Qsys. After you define the Qsys
system, Qsys generates the following two kinds of output:
■ The HDL files that the Quartus II software compiles to generate the configuration
file for the FPGA. This Quartus II compilation process is the hardware flow.
■ A system description that the software development tools use to generate a system
library specific to the Qsys system. This system library, also called a board support
package, supports the Nios II processor in running the software. The Nios II SBT
for Eclipse provides an environment in which you can develop software
applications for your system. This Nios II SBT development process is the
software flow.
The output of the hardware flow is an FPGA image that configures the target device.
The output of the software flow is an executable file that the Nios II processor can run.
Design Requirements
In this tutorial, you design a digital picture viewer that allows a user to view pictures
stored in JPEG format and to scroll through JPEG pictures stored in the external flash
memory, using the LCD touch-screen display.
Design Strategy
Qsys provides standard hardware components that you can add to your system. You
can add several instances of each component. The only restriction is the resources
available on your board to implement all of the components you instantiate in your
design.
The NEEK comprises a Cyclone III FPGA Starter Board and an LCD Multimedia High
Speed Mezzanine Card (HSMC) daughtercard in addition to accessories and software.
The following NEEK hardware resources are required to run the design you create in
this tutorial:
■ The following Cyclone III FPGA Starter Board resources are required:
■ Cyclone III EP3C25F324 FPGA
■ Embedded USB-Blaster™ circuitry (including an Altera EPM3128A CPLD)
allowing download of FPGA configuration files through your PC’s USB port
■ 256-Mbit DDR SDRAM
■ 1 MByte of synchronous SRAM
■ 16 MBytes of Intel P30/P33 flash memory
■ 50-MHz on-board oscillator
■ The following LCD daughtercard resources are required:
■ LCD touch-screen 800 × 480 pixel display
■ 10-bit VGA digital access card
The NEEK has additional features, including additional memory, not required to
implement this design.
The Qsys system contains both control path and data path components. The Nios II
processor is the main system controller. It initializes and calibrates the LCD controller,
intercepts user touch input, and initializes the data path. It communicates with other
control path components through Avalon Memory-Mapped (Avalon-MM) interface
ports.The Nios II processor reads the program code from DDR SDRAM memory, and
the DDR SDRAM also holds the video frame buffer. A tristate conduit bridge
component connects the flash controller with the off-chip flash memory.
The Nios II processor sends frame buffer data from the DDR SDRAM to a video
pipeline of specialized Avalon Streaming (Avalon-ST) components that move and
process the pixel data, converting it to video data signals and sending them to the
LCD screen.
The pixels must be rendered on the LCD screen smoothly and without delays. This
design achieves this goal by running the DDR SDRAM at a high clock rate to improve
the performance of the video frame buffer.
Table 2–1 shows how the individual design requirements for this project are
implemented by specific design strategies, which in turn dictate the components you
add to your system in this tutorial.
Table 2–1. Standard Hardware Components to Implement the Digital Picture Viewer Requirements
Design Requirement Design Strategy Components Needed
■ LCD screen controller ■ PIO
Display JPEG pictures on the LCD Display ■ A video pipeline to send video data to ■ Video pipeline peripherals
the LCD screen
■ An interrupt to capture touch screen ■ PIO
Scroll through JPEG pictures events ■ SPI
■ Touch screen control
■ Need a large memory. Use the on-board ■ DDR SDRAM controller
DDR SDRAM ■ SGDMA
Frame buffering
■ Transfer video data from memory to
Video pipeline
Store JPEG images, FPGA configuration
file, application software, and reset Use the on-board flash memory Flash controller
vectors in a nonvolatile memory
Store program code, stack, and exception
Use the onboard DDR SDRAM DDR SDRAM controller
vectors
Generate interrupts and measure system
Need a timer Interval timer
performance
Download, run, and debug software JTAG UART communication interfaces JTAG UART
Keep track of hardware and software Ensure software is only run on the
System ID peripheral
builds hardware for which it was compiled
f The implementation of the video pipeline and the touch screen controller are
described in more detail in Implementing an LCD Controller and the Nios II 3C25
Microprocessor with LCD Controller Data Sheet.
Block Diagram
Figure 2–2 shows a high-level block diagram of the system you develop to implement
the design.
Tristate
Conduit
Bridge
Video Subsystem
Nios II/f CFI Flash System Data Video
Timing Pixel Timing Pixel
Processor Controller ID SG-DMA Format Sync
Adatper 0 FIFO Adatper 1 Converter
Adapter Generator
As systems get larger and more complicated, it is easier to design at a higher level of
abstraction using—and reusing—customized HDL components, which may include
IP cores, verification IP and other design modules. Qsys automatically generates the
system interconnect fabric, which is the glue logic that connects the design blocks
together. The system interconnect fabric manages design issues such as dynamic
bus-width matching, interrupt priorities, and arbitration.
f For additional information about the Altera system interconnect fabric, refer to Avalon
Interface Specifications.
Qsys supports hierarchical system design, which means you can instantiate a system
as a component in a higher-level system. This approach allows you to divide a large
design into smaller subsystems, which are easier to manage and control. You can also
promote design reuse by reusing these subsystems with minimal changes in your
other designs. In this tutorial, the video pipeline components are grouped in the video
subsystem and low-frequency components such as the PIO and SPI components are
grouped in the peripheral subsystem.
f For additional information about Qsys, refer to the Qsys System Integration Tool page
of the Altera website.
In this chapter, you add components to the system, make connections where required,
assign the clocks, set arbitration priorities, and generate the system.
The tutorial combines various components and subsystems to create a Qsys complete
system. The video subsystem and peripheral subsystem are also complete Qsys
systems, which you add to your top level system.
The following Qsys files are provided in the tutorial folder:
■ main_system.qsys—A partially-completed, top-level Qsys system, to which you
add a Nios II embedded processor, a DDR SDRAM controller, a flash controller,
and a video subsystem.
■ video_system.qsys—A completed Qsys system that contains the video pipeline
components.
■ peripheral_system.qsys—A completed Qsys system that contains the
low-frequency peripherals.
After you add the components to the top-level system, you must perform some
additional steps to create the .sof that you use to configure the FPGA. All of the
necessary steps are described in this chapter.
If you wish to skip the steps to create the .sof, you can use the completed design
available in your <working directory>/complete_system folder and skip to Chapter 4,
Completing the Quartus II Project.
Start Qsys
To run Qsys, perform the following steps:
1. Run the Quartus II software. On your Windows system, click Start > All Programs
> Altera > Quartus II <version>.
2. On the File menu, click Open Project.
3. Browse to locate <working directory>/tutorial/sys_arc_lab.qpf. The Quartus II
project for the tutorial opens. Ignore the error messages referring to the
unconnected components. You connect the components later in this tutorial.
4. On the Tools menu, click Qsys. Qsys opens.
5. On the File menu, click Open and browse to locate the top-level Qsys file,
<working directory>/tutorial/main_system.qsys. Qsys loads a partial system. In the
following section, you add the remaining components to the system.
PIO (Parallel I/O) pio_id_eeprom_scl Two-wire EEPROM ID interface components. The I2C serial
EEPROM ID chip stores information about the board, including the
PIO (Parallel I/O) pio_id_eeprom_dat touch screen calibration data.
SPI (3 Wire Serial) touch_panel_spi Touch screen interface components. Refer to Implementing an LCD
PIO (Parallel I/O) touch_panel_pen_irq_n Controller.
JTAG UART jtag_uart Enables software to access a debug serial port.
Enables software to perform periodic interrupts for maintenance
Interval timer sys_clk_timer
and to maintain software application timing requirements.
Scatter-Gather DMA
sgdma Controls the video pipeline components.
Controller
Avalon-ST Timing
timer_adapter_0
Adapter
On-Chip Memory fifo
Avalon-ST Timing
timer_adapter_1
Adapter Video pipeline components. Refer to Implementing an LCD
Pixel Converter Controller.
pixel_converter
(BGR0 -> BGR)
Avalon-ST Data
data_format_adapter
Format Adapter
Video Sync Generator video_sync_generator
1 Ignore the error messages that appear in the Qsys message console. The steps in
“Complete the System” on page 3–9 resolve these errors.
1 Altera recommends that you save your work after you add each component. To save
the current Qsys system, on the File menu, click Save.
1 Alternatively, you can use the search box on the Component Library tab to
locate components in the library.
2. Select the Nios II/f processor. Figure 3–1 shows the Nios II Processor parameter
editor after you select the Nios II/f core.
3. Click Finish.
4. In the Module Name column on the System Contents tab, right-click the new
Nios II processor name, click Rename, and type cpu to rename the new
component.
5. In the connection panel, connect the data_master port of cpu to the control_slave
port of sysid and the slow_clock_crossing_bridge_s0 port of
peripheral_subsystem.
Figure 3–2 shows the connection panel with the data_master port of cpu correctly
connected.
Figure 3–3 shows the Memory Settings tab after you assign these settings.
Figure 3–3. Memory Settings for DDR SDRAM Controller with ALTMEMPHY
7. In the Export column, click Click to export and set the following ddr_sdram signal
rows to the following names:
■ For external_connection, type ddr_sdram_external_connection.
■ For memory, type ddr_sdram_memory.
■ For auxfull, type ddr_sdram_auxfull.
Figure 3–4 shows the exported connections.
Figure 3–5 shows the component with the Intel 128P30 preset parameter settings.
4. Click Finish.
5. In the Module Name column, right-click the new Generic Tri-state Controller
name, click Rename, and type flash to rename the new component.
6. Connect the uas port of flash to the data_master port of cpu and the
instruction_master port of cpu.
7. Connect the tcm port of flash to the tcs port of flash_bridge.
2. Click Finish.
3. In the Module Name column, right-click the new video system name, click
Rename, and type video_subsystem to rename the new component.
4. Connect the sgdma_csr port of video_subsystem to the data_master port of cpu to
give the processor access to the SGDMA in the video subsystem.
5. Connect the s1 port of ddr_sdram to the sgdma_descriptor_read port of
video_subsystem, the sgdma_descriptor_write port of video_subsystem, and the
sgdma_m_read port of video_subsystem.
6. In the Export column, Click to export and type lcd_video_interface in the
video_subsystem video_interface signal row.
After you perform these instructions, the Qsys system contains all required
components. Next, you complete the system design and resolve the system validation
errors.
S S S S S
CFI Flash DDR Peripheral
System ID S M Video
Controller SDRAM Subsystem
Controller Subsystem
M
S
Tristate
Conduit
Bridge
Figure 3–8 shows the Qsys Clock Settings tab with available clocks for the system.
To change the clocks for the individual components, perform the following steps for
each component port:
1. On the System Contents tab, click the Clock column in the component row to
reveal a list of clocks.
Table 3–2. Clocks for Individual Components in Digital Picture Viewer Qsys System
Clock Name Frequency Source Component/Port
osc_clk 50 MHz Oscillator ddr_sdram / refclk
■ flash_bridge / clk
■ peripheral_subsystem / clk_100
■ sysid / clk
ddr_sdram_sysclk 100 MHz SDRAM PLL
■ cpu / clk
■ flash / clk
■ video_subsystem / clk_100
Figure 3–9. Base Address Setting Conflict that Requires Manual Reassignment
Figure 3–10 shows the related peripheral_subsystem component ports after you
perform this step.
Figure 3–11 shows the arbitration values after you make the assignments.
1 Altera recommends that your reset vector specify a nonvolatile memory location.
When a software exception or interrupt event occurs, the Nios II processor begins
executing software in another predefined location.The exception vector specifies this
location.
To set the reset and exception vectors for the Nios II processor in your system,
perform the following steps:
1. In the Module Name column, double-click cpu. The Nios II processor parameter
editor appears.
2. In the Reset Vector Memory list, select flash.uas.
3. In the Reset Vector Offset box, type 0x100000.
4. In the Exception Vector Memory list, select ddr_sdram.s1.
6. Click Finish.
Your Qsys system content is complete and you can now generate the Qsys system.
1. On the Generation tab, click the Generate button. The Generate dialog box
appears, displaying generation messages as generation proceeds.
As shown in Figure 2–1 on page 2–2, Qsys creates the following output items:
■ HDL files for the components in your system
■ HDL files for the system interconnect to connect the components together
■ System description used by the software development tool, the Nios II SBT for
Eclipse, to build the software project
After your system generates successfully, the following message appears:
Generate completed.
2. Click Close.
In this chapter, you complete the Quartus II project by adding the top-level HDL file,
which instantiates the Qsys system, adding the timing constraints file, and setting the
pin assignments. You compile your project in the Quartus II software to perform
analysis, synthesis, fitting, and timing analysis. Compilation generates an FPGA
image as a .sof file. After you download the FPGA image to the NEEK, the on-board
FPGA functions as a processor custom-made for your application.
1 If you wish to work with the completed project provided with the tutorial files, click
Open Project on the Quartus II software File menu, browse to locate <working
directory>/complete_system/sys_arc_lab.qpf, then skip directly to “Configure the
FPGA” on page 4–3.
f For more information about the Quartus II Programmer, refer to the Quartus II
Programmer chapter in volume 3 of the Quartus II Handbook.
10. If your .sof does not appear in the Quartus II Programmer, perform the following
steps:
a. Click Add File.
b. Browse to locate <working directory>/tutorial/sys_arc_lab.sof.
c. Click Open.
11. Turn on Program/Configure for your .sof.
12. Click Start to program the FPGA.
After the Programmer completes programming the FPGA, the progress bar reaches
100%, and no error messages appear.
After you complete all the steps in this chapter, you have successfully compiled and
downloaded the FPGA image to the Cyclone III device on your NEEK. The processor
is ready to run. Next, you must develop the software application and download it to
the NEEK.
In this chapter, you use the Nios II SBT for Eclipse to develop the software application
that runs on your system. You create a new software application project, a board
support package (BSP) for your project (to provide a software runtime environment
customized for the hardware system defined in the previous chapter), add the
software source files to the project, configure the project, and build the project. The
result of the build process is an .elf file. The Nios II SBT for Eclipse downloads the
application .elf to the memory location at which the Nios II processor expects to find
the executable program. The Nios II processor then runs the application .elf.
f For more information about the Nios II SBT for Eclipse, refer to the Getting Started with
the Graphical User Interface chapter of the Nios II Software Developer’s Handbook and to
the Developing Nios II Software chapter of the Embedded Design Handbook.
Figure 5–1 shows the Nios II Board Support Package project wizard.
Figure 5–2 shows the New Project dialog box after you perform these steps.
4. On the Linker Script tab, for each enabled row in the Linker Section Mappings
table, select ddr_sdram in the Linker Region Name column.
Figure 5–5 shows the settings for the Nios II BSP Editor Linker Script tab.
Figure 5–5. BSP Settings for BSP Editor Linker Script Tab
Figure 5–6. Altera Read-Only Zip File System Settings for Digital Picture Viewer
f For more information about the Altera read-only zip file system, refer to the
Read-Only Zip File System chapter of the Nios II Software Developer’s Handbook.
1 If you are prompted to regenerate the BSP, right click picture_viewer_bsp and click
Regenerate BSP, then repeat step 1.
Figure 5–7 shows the Nios II Flash Programmer after completing the steps.
Figure 5–7. Flash Programmer Settings to Program Flash Memory With JPEG Images .zip File
f For more information about the Flash Programmer, refer to the Nios II Flash
Programmer User Guide.
3. If the Run Configurations dialog box appears, perform the following steps:
a. On the Target Connection tab, click Refresh Connections and Apply until a
board connection establishes.
b. Click Run.
The Run or Run As command rebuilds the software project to create an up–to-date
executable and then download the code to memory. The debugger resets the Nios II
processor, and the Nios II processor then executes the downloaded code.
Console Output
After the application begins executing, it relays messages to the Nios II SBT for
Eclipse through the JTAG interface. Figure 5–8 shows the output in the Nios II view.
1 The Nios II Flash Programmer overwrites the default application selector on the
NEEK. To restore the factory image, refer to the "Restoring the Factory Image"
appendix in the Nios II Embedded Evaluation Kit, Cyclone III Edition User Guide.
2. On the File menu, click New. The New Flash Programmer Settings Files dialog
box appears.
3. Select Get flash programmer system details from BSP Settings File.
4. In the BSP Settings File name box, browse to locate <working
directory>/tutorial/software/picture_viewer_bsp/settings.bsp.
5. Click OK.
6. To convert and program the .sof, perform the following steps:
a. On the Flash: flash tab, click Add. The Select Files for Flash Conversion
dialog box appears.
b. In the Files of type list, select Quartus II SOF File.
c. Browse to locate <working directory>/tutorial/sys_arc_lab.sof.
d. Under Files for flash conversion, double-click in the Flash Offset column.
e. In the Flash Offset box, type 0x20000.
f. Next to the File generation command box, click Properties.
g. In the Additional arguments box, type --activeparallel.
h. Click Close.
7. To convert and program the .elf, perform the following steps:
a. On the Flash: flash tab, click Add. The Select Files for Flash Conversion
dialog box appears.
b. In the Files of type list, select Nios II ELF File.
c. Browse to locate <working
directory>/tutorial/software/picture_viewer/picture_viewer.elf.
8. Click Start. A new Nios II Flash Programmer Settings File (.flash-settings) is
created and flash memory is programmed. Programming might take a few
minutes.
Figure 5–9 shows the Nios II Flash Programmer after completing the steps.
This chapter provides additional information about the document and Altera.
f The following documents and web pages provide information to help you create
custom components for your Qsys system:
■ The System Design with Qsys section of Volume 1: Design and Synthesis of the
Quartus II Handbook provides complete reference on using Qsys, including topics
such as building memory subsystems, creating custom components, and
automatically generating interconnect fabric based on a network-on-a-chip
topology.
■ Avalon Memory-Mapped Master Templates web page describes how to use an
Avalon-MM template to create an Avalon-MM custom component.
■ Avalon Memory-Mapped Slave Template web page describes how to use an
Avalon-MM template to create an Avalon-MM slave custom component.
■ Guidelines for Developing a Nios II HAL Device Driver describes how to develop
software device drivers for your custom component.
f The following Altera documents and web pages provide background and general
information about building embedded systems using Altera tools:
Typographic Conventions
The following table shows the typographic conventions this document uses.