an 446: debugging nios ii systems with the...

32
Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II Systems with the SignalTap II Logic Analyzer Introduction As FPGA system designs become more sophisticated and system focused, with increasing numbers of processors, peripherals, buses, and bridges, designers have an ever-greater need for system-level debug tools. One such debug tool is Altera's SignalTap ® II embedded logic analyzer, which provides real-time hardware debugging capabilities by embedding a logic analyzer into the system. The Nios ® II plug-in further extends the SignalTap II system debugging capabilities by enabling the capture of a Nios II processor's programmatic execution. This application note examines the use of the Nios II plug-in within the SignalTap II Logic Analyzer, and presents the capabilities, configuration options, and use-modes for the plug-in. Additionally, a short user tutorial is provided that demonstrates how to use the Nios II plug-in, SignalTap II Logic Analyzer, and Nios II IDE to trigger on, capture, and trace the receipt of a character from an RS-232 UART into an interrupt service routine (ISR). The Nios II plug-in extends the capabilities of the SignalTap II Logic Analyzer, enabling you to easily trigger on and capture instruction trace data being executed by the Nios II processor core. You can specify instruction trace triggering to occur when the processor reaches a specific address by entering a symbol name from your program (ELF file), or by specifying your own SignalTap II trigger condition. The Nios II plug-in automatically correlates the processor trace against a specified software image (ELF file), providing you with a symbol name plus offset view of the trace, along with decoded Nios II op-codes. The tutorial uses the “full_featured” hardware and “count binary” software reference designs included in the Nios II development kit. Prerequisites This document targets the systems engineer who wants to design a system for remote configuration. It also provides a simple application that uses the Nios II software to implement the basic remote configuration features. Knowledge Requirements This application note assumes that you are familiar with the operation and use of the Quartus ® II software, SOPC Builder, and the Nios II embedded processor. You should also be familiar with the basic May 2007, ver. 1.0

Upload: others

Post on 16-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 1AN-446-1.0 Preliminary

Application Note 446

Debugging Nios II Systemswith the SignalTap II Logic

Analyzer

Introduction As FPGA system designs become more sophisticated and system focused, with increasing numbers of processors, peripherals, buses, and bridges, designers have an ever-greater need for system-level debug tools. One such debug tool is Altera's SignalTap® II embedded logic analyzer, which provides real-time hardware debugging capabilities by embedding a logic analyzer into the system. The Nios® II plug-in further extends the SignalTap II system debugging capabilities by enabling the capture of a Nios II processor's programmatic execution.

This application note examines the use of the Nios II plug-in within the SignalTap II Logic Analyzer, and presents the capabilities, configuration options, and use-modes for the plug-in. Additionally, a short user tutorial is provided that demonstrates how to use the Nios II plug-in, SignalTap II Logic Analyzer, and Nios II IDE to trigger on, capture, and trace the receipt of a character from an RS-232 UART into an interrupt service routine (ISR).

The Nios II plug-in extends the capabilities of the SignalTap II Logic Analyzer, enabling you to easily trigger on and capture instruction trace data being executed by the Nios II processor core. You can specify instruction trace triggering to occur when the processor reaches a specific address by entering a symbol name from your program (ELF file), or by specifying your own SignalTap II trigger condition. The Nios II plug-in automatically correlates the processor trace against a specified software image (ELF file), providing you with a symbol name plus offset view of the trace, along with decoded Nios II op-codes.

The tutorial uses the “full_featured” hardware and “count binary” software reference designs included in the Nios II development kit.

Prerequisites This document targets the systems engineer who wants to design a system for remote configuration. It also provides a simple application that uses the Nios II software to implement the basic remote configuration features.

Knowledge Requirements

This application note assumes that you are familiar with the operation and use of the Quartus® II software, SOPC Builder, and the Nios II embedded processor. You should also be familiar with the basic

May 2007, ver. 1.0

Page 2: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

2 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

capabilities and operation of the SignalTap II Logic Analyzer. Because the Nios II plug-in is an extension of the SignalTap II Logic Analyzer, the basic use mode for the plug-in is nearly identical to that of the SignalTap II Logic Analyzer.

f This document does not provide you with information about the basic use and operation of the SignalTap II Logic Analyzer. Its goal is solely on how to use the Nios II plug-in within the SignalTap II framework. For more information about a particular SignalTap II configuration option or use mode, refer to the Design Debugging Using the SignalTap II Embedded Logic Analyzer chapter in volume 3 of the Quartus II Handbook.

Tool Requirements

Using the Nios II plug-in requires the following tools:

■ Quartus II software version 7.1 or higher■ Nios II Embedded Development Suite 7.1 or higher

To complete the tutorial at the end of this application note, you also need the following resources:

■ Nios II Development Kit■ RS-232 Serial Cable (optional)■ JTAG ByteBlaster™ or USB-Blaster™ Cable■ The source file bit_bang_uart.c (available as a downloadable file

with this application note)

For more detailed information about the hardware and software required for the tutorial, refer to “Tutorial: Using the Nios II Plug-In” on page 12.

The Nios II Plug-In

The Nios II plug-in operates as a debug extension to the SignalTap II Logic Analyzer, enabling users to capture the instructions executed by a Nios II embedded processor. Both the Nios II instruction address and op-code information are captured by the Nios II plug-in, which operates by instantiating debug nodes inside the Nios II processor's ALU. All variants of the Nios II processor core are supported.

Trigger conditions can be specified as an instruction address, a symbol name (function) present in the Nios II Executable and Linking Format (ELF) file, or a symbol name plus an offset. All instructions captured by the plug-in are decoded into a human readable format, with the instruction address translated into a symbol name plus an address offset (if possible), and the instruction op-code translated into its equivalent assembly language mnemonic.

Page 3: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 3Preliminary

The Nios II Plug-In

While the Nios II plug-in is instantiated on a per-processor basis, it can operate with multiple instances of itself (with other processors), or with other SignalTap II capture instances.

Quartus II Project and SignalTap II Logic Analyzer Set-Up

You must create and configure a SignalTap II file in your Quartus II software project for use with the Nios II plug-in. Adding the SignalTap II file into your system is done by following the normal procedure described in the SignalTap II handbook, as follows:

1. On the Quartus II File menu, click New.

2. In the New dialog box, click the Other Files tab, and select SignalTap II File.

3. Click OK.

The Nios II plug-in currently does not support Quartus II projects in which the incremental compilation option is set. Therefore, you must ensure that incremental compilation has been disabled in your Quartus II project. To disable incremental compilation, do the following:

1. On the Assignments menu, click Settings.

2. In the Settings window, expand the Compilation Process Settings menu item and select the Incremental Compilation option.

3. In the Incremental Compilation panel, turn on the Off option.

4. Click OK.

Adding the Nios II Plug-In

When adding the Nios II plug-in, you must specify the Nios II processor you wish to monitor and, optionally, the processor's software image (ELF file). This ELF file is processed by the Nios II plug-in to extract symbol information, which can be used during configuration to specify trigger conditions.

To add the Nios II plug-in, perform the following operations:

1. Right-click in the SignalTap II node list and select the option Add Nodes with Plug-In, then select Nios II. The Hierarchy Selection dialog box appears.

Page 4: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

4 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

2. In the Hierarchy Selection dialog box, select the Nios II processor instance you want to monitor with the plug-in.

3. In the Nios II plug-in option window, specify the location of the (optional) ELF file.

1 The Nios II plug-in can only be instantiated on a one-for-one basis with a particular Nios II processor. Attempting to add more than one instance of the Nios II plug-in per processor results in an error message being displayed.

You can change which ELF file is used by the Nios II plug-in at any time by doing the following:

1. In the SignalTap II node list, click on the Setup tab.

2. Right-click on the Nios II plug-in instance you want to modify and select Plug-In Options. The configuration options for the Nios II plug-in appear.

1 The ELF file is generated by the Nios II Integrated Development Environment (IDE) during the software build process. In most cases, the ELF file for your software project is present in either the Debug or Release directories created by the Nios II IDE.

Specifying Trigger Conditions

Unlike standard SignalTap II trigger conditions that are described as hardware or logic events, the Nios II plug-in's trigger conditions are specified as instruction addresses. The Nios II plug-in is triggered when the specified instruction address trigger is reached by the Nios II processor during program execution.

Basic Triggering

In basic triggering mode, the Nios II plug-in uses a processor visible system address as the trigger to begin trace capture. The trigger can be set up by right-clicking the Trigger Levels column in the Nios II plug-in and entering a value into the address trigger condition field. The value entered into the address trigger condition field can be represented as a hexadecimal integer or a C/C++ function name (or symbol found in the Nios II executable's ELF file), or a combination of the two.

Page 5: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 5Preliminary

The Nios II Plug-In

The following trigger specifications are supported:

■ Hexadecimal number: 0x<32 bit number> (for example, 0x20000000)■ ELF file symbol: <string> —Any alphanumeric string corresponding

to a symbol found in the ELF file. (for example, foo)■ ELF file symbol + offset: <string>+<hexadecimal number> (for

example, foo+0x80)

To specify a trigger condition with a symbol name option requires the Nios II plug-in is configured with a Nios II processor ELF file. If the ELF file does not contain the symbol name (C/C++ function name) specified, an error message is displayed and the trigger condition field is set to an undefined value. In fact, whenever a value is entered into the trigger condition field, the Nios II plug-in examines the contents of the reference ELF for any changes. This check is useful for situations where the ELF file is changing frequently, such as software debugging, because the ELF file contents are guaranteed to remain synchronized with the specified trigger conditions.

To determine what symbols are present in the ELF file, you can use one of the following methods:

■ Use the Nios II IDE to generate an objdump file during software compilation

■ Use the nios2-elf-objdump command on the Nios II Shell (nios2-elf-objdump –s <filename>.elf).

To have the Nios II IDE generate an objdump file, perform the following steps:

1. In the Nios II IDE, in the Window menu, click Preferences.

2. In the Project Preferences window, click Nios II to bring up the Nios II options

3. Turn on the Generate objdump file option.

The next time you build your software application, an objdump file will be present in the Debug directory for the project. For more information, refer to “Tutorial: Using the Nios II Plug-In” on page 12.

1 Unlike standard SignalTap II logic analyzer trigger conditions that can be specified by right-clicking on the Trigger Levels column (in the SignalTap II file window) and selecting a trigger pattern, Nios II plug-in trigger conditions should be manually entered for clarity.

Page 6: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

6 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Not specifying an address trigger condition for the plug-in has the same effect as not specifying a trigger condition in a normal SignalTap II capture instance. If there is no trigger condition, the logic analyzer is never stopped.

Multiple Triggers

The Nios II plug-in supports the SignalTap II multiple trigger level feature, and can be incorporated into part of a more complex capture sequence. The Nios II plug-in trigger pattern can be utilized in any SignalTap II trigger level.

Advanced Triggers

Complex triggers can be created using the SignalTap II Advanced Trigger option. However, the Nios II plug-in loses much of its benefit when this option is used. While the signal groupings contained in the Nios II plug-in will appear in the Advanced Trigger Configuration Editor, they will only be treated as normal signals. The Advanced Trigger Configuration Editor lacks the Nios II plug-in's trigger by address or symbol capabilities.

Power-Up Triggers

The Nios II plug-in can be used with the SignalTap II Power-Up trigger feature. Because Power-Up triggers are enabled before the SignalTap II Logic Analyzer is manually started, they are useful for monitoring systems where the Nios II processor is operating in a self-booting mode, that is, right after the FPGA is configured. In these cases, the Nios II processor begins software execution directly from system memory without the aid of a debugger to start, stop, and load the processor's run-time memory.

Assigning the Acquisition Clock

You must specify a clock signal to control the acquisition of samples, which is done through the Signal Configuration Pane of the SignalTap II Logic Analyzer's setup window. Altera recommends that the selected SignalTap II acquisition clock be the same clock signal used by the Nios II CPU, which ensures that the captured instruction trace data accurately corresponds to the instruction execution rate of the Nios II CPU.

Because the Nios II plug-in does not support the incremental compilation option in the Quartus II software, you must assign the acquisition clock using the SignalTap II: pre-synthesis option in the Filter list for the Node Finder.

Page 7: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 7Preliminary

The Nios II Plug-In

Selecting Sample Depth, Memory Type, and Buffer Acquisition Mode

As is the case with configuring the SignalTap II Logic Analyzer, you must specify the sample depth, memory type, and buffer acquisition mode for the capture session. These configuration options behave as they would in a normal SignalTap II Logic Analyzer capture session, and are accessible through the Signal Configuration pane.

Exercise care in selecting the Sample Depth size. The Nios II plug-in requires many signals to be captured for every sample taken, quickly depleting available memory resources. Use the SignalTap II resource estimator to get a better understanding of how adjusting the sample depth parameter impacts your design.

1 While you can select the Enable Debug Ports option when using the Nios II plug-in to capture trace data to a memory or device outside the FPGA, any data captured with this method will not be decoded by the Nios II plug-in into Nios II assembly instructions.

Design Compilation and Programming the Target Device

The Nios II plug-in is compiled into the Quartus II design following the same procedures used by the SignalTap II Logic Analyzer. However, because the Quartus II incremental compilation option is not supported by the Nios II plug-in, you must perform a full compilation of the Quartus II project after adding the plug-in.

After compilation, you must program the FPGA target device, which is done from the SignalTap II Logic Analyzer window. The procedure for programming the FPGA is identical to a normal SignalTap II capture session.

Page 8: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

8 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Running a Capture Session

Data acquisition with the Nios II plug-in is performed in roughly the same way that the SignalTap II Logic Analyzer gathers data. First, the FPGA is programmed with the SOF file generated by the Quartus II software. Next, the SignalTap II analysis is started, either manually through the SignalTap II instance manager, or automatically when the FPGA is programmed and “Power-Up” triggering is selected. Finally, if the trigger conditions are met in the system, the data is acquired and displayed through the SignalTap II results window.

The Nios II plug-in can be used in two different types of data capture sessions, one with the Nios II IDE and the other in stand-alone mode.

Performing Data Capture with the Nios II IDE

When the Nios II plug-in is used with the Nios II IDE, you must manually download a Nios II software image and control the operation of the processor through the debugger. This type of capture session is usually conducted when you are developing and debugging a Nios II software application.

To perform a SignalTap II capture session with the Nios II processor controlled by the Nios II IDE, perform the following steps:

1. Use the SignalTap II interface to program the FPGA target device with the SOF file generated by the Quartus II software.

2. Using the SignalTap II Instance Manager, click Run Analysis to run the analyzer.

3. In the Nios II IDE, right-click on the name of the software project you want to run on the Nios II processor and click Debug As. This action starts the debugger, downloading the ELF file into system memory and halting the processor on the entry point to main().

4. On the Debug tab in the Nios II IDE, click Run to start the software execution.

The SignalTap II Logic Analyzer continues running until the trigger condition specified in the Nios II plug-in is reached. While the SignalTap II Logic Analyzer is running, all of the Nios II IDE debug operations can be used safely (for example, breakpoints can be set, the processor can be halted, and so forth).

When using the Nios II IDE to debug your system software, be aware that launching the debugger may cause the Nios II plug-in to trigger by advancing the processor to the trigger address. This can happen if you chose a start-up breakpoint location that occurs after the trigger address

Page 9: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 9Preliminary

Running a Capture Session

location specified for the Nios II plug-in, causing a “false hit” by the debugger. If you need to change the breakpoint start-up location for the debugger, perform the following steps in the Nios II IDE:

1. From the Run menu, click Debug. The debug configuration window appears.

2. In the debug configuration window, click on the Debugger tab.

3. Select the breakpoint location(s) you want the Nios II IDE debugger to start from, and click Apply.

1 Alternatively, instead of using the Debug As option, you can use the Run As option. Using the Run As option causes the Nios II IDE to download and run the software image from system memory without invoking the debugger feature of the Nios II IDE.

Performing Data Capture without the Nios II IDE

If your Nios II processor based system has been configured to be self-booting, without the need for an external software download, and you have selected the SignalTap II Power-Up Trigger feature, the SignalTap II Logic Analyzer begins running automatically when the FPGA is programmed.

In this case, the SignalTap II may have already have captured data available. To find out if captured data is available, or if the logic analyzer is still running, click Run Analysis in the SignalTap II instance manager.

f For more information about creating a self-booting Nios II processor system, refer to the Nios II Software Developer's Handbook.

Page 10: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

10 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Analyzing Results

The Nios II SignalTap II plug-in allows you to visualize the captured Nios II processor trace data. This section describes several of the post-capture features present in the Nios II SignalTap II plug-in.

Viewing the Data

Captured SignalTap II data is displayed in the Data tab of the SignalTap II file. Every sample captured by the Nios II plug-in displays the following information:

■ Address—The instruction address location is converted to a hexadecimal format. Additionally, if an ELF file was specified during plug-in configuration, the instruction address may be further resolved into symbol name and offset.

■ Assembly Language Mnemonic—The binary op-code for the instruction is converted into its Nios II assembly language equivalent.

If an ELF file was specified during the plug-in configuration, the file is re-examined right after data acquisition has completed, so the instruction addresses can be converted into the symbol name and offset representation. This action helps to safeguard against old software images being used.

By using the SignalTap II Datatab controls, you can scroll through the programmatic execution of the Nios II processor. If the specified acquisition clock corresponds to the Nios II processor clock, every rising clock edge should correspond to a new instruction cycle.

You may notice one or more empty instruction “slots” in the trace data gathered by the Nios II plug-in. These slots indicate that no instruction was executed by the Nios II processor during that particular clock cycle. This behavior is normal, and can occur for the following reasons:

■ Cache Miss—The requested instruction address location have generated a “miss” in the instruction cache, which resulted in additional clock cycles being used to fill the cache line and return the instruction.

■ Memory Contention or Speed—The instruction address location may have been to memory that requires multiple clock cycles to access, or the memory may have been controlled by another peripheral or processor during this time.

You can also view the Nios II plug-in trace data in the SignalTap II list file format, which displays the captured samples in a tabular format. The trace samples are displayed chronologically in rows, decoded by sample number and the associated assembly language mnemonic. The list file

Page 11: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 11Preliminary

Analyzing Results

format is useful because it displays the Nios II instruction trace data in a way that closely mirrors the output format of the nios2-elf-objdump command, simplifying the analysis process. To create the SignalTap II list file, on the File menu, point to Create/Update, and click Create SignalTap II List File.

f Some Nios II processor op-codes (instructions) consume multiple clock cycles when they are executed. For more information about the number of clock cycles required for a particular op-code, refer to section 5 of the Nios II Processor Reference Handbook.

Correlating Trace Data to the Processor's ELF File

You can compare the captured Nios II plug-in instruction trace to the software image executed by the Nios II processor by examining the contents of the objdump file. The Nios II IDE can convert the processor's ELF file into a human-readable format (the objdump file) that contains C/C++ code fragments, symbolic function names, assembly instructions, and address locations. Refer to “Specifying Trigger Conditions” on page 4 for instructions on how to generate the objdump file in the Nios II IDE.

Although the objdump file generated by the Nios II IDE contains vast amounts of information decoded from the ELF file, the Nios II processor's instructions are presented one per line, in the following format:

<Address>: <op-code> <Assembly Mnemonic>

For example, a valid instruction is:

200a8c0: e0800417 ldw r2,16(fp)

To quickly find a particular instruction address in the objdump file, use the Nios II IDE Find/Replace command on the Edit menu.

The nios2-elf-objdump command-line executable, included as a part of the Nios II Embedded Development Suite, can also be used to generate an objdump file from the ELF file. This tool includes a super-set of the functionality found in the Nios II IDE. It is configured through a series of command line options. To get a listing of conversion options found in the nios2-elf-objdump command, type the following command in a Nios II SDK command shell:

nios2-elf-objdump –v r

Page 12: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

12 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Saving and Converting Captured Data

Any data captured by the Nios II plug-in can be saved with the SignalTap II data log feature. Any Nios II plug-in data sets are stored along with the processor's ELF file information. To enable data logging, turn on the Data Log option of the SignalTap II file.

The SignalTap II data conversion feature is also supported by the Nios II plug-in. To export captured data, on the File menu, click Export and specify the File Name, the Export Format, and the Clock Period.

Tutorial: Using the Nios II Plug-In

This tutorial shows you how to use the Nios II plug-in for the SignalTap II Logic Analyzer to trace the transmission of an RS-232 character on a Nios II development board. The tutorial explains how to set up and configure the Nios II plug-in, how to use the plug-in during the Nios II software debug cycle (Nios II IDE), and how to perform an analysis of the data captured using the ELF file as a reference.

Hardware and Software Requirements

To use this design example you must have the following:

■ Quartus II software version 7.1 or higher—Both the Quartus II Web Edition and the fully licensed version will work with the example design.

■ Nios II Development Kit version 7.1 or higher—You can use any Altera® Nios II development kit that supports the full_featured example design. The following development kits support this design:● Stratix® II Edition● Stratix Edition● Stratix Professional Edition● Cyclone® II Edition● Cyclone Edition

■ RS-232 UART Cable—The tutorial can be run without this cable; however, without the cable you won't be able to see the output from the Nios II development board on the Nios II IDE console.

■ Software File—Download the file bit_bang_uart.c to a folder on your hard drive. This software file can be found on the Altera literature page with this application note (AN 446). (www.altera.com/literature/lit-nio2.jsp).

■ JTAG ByteBlaster or USB-Blaster Cable

Page 13: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 13Preliminary

Tutorial: Using the Nios II Plug-In

Hardware Project Set-Up

You must first create the system hardware containing the Nios II processor and configure the Quartus II project for the Nios II plug-in.

Configuring the Hardware

Make sure that your Nios II development board has power and is connected to your workstation through the JTAG download cable. Additionally, verify that your Nios II development board's RS-232 UART port is connected to a working serial port on your workstation.

1 While having the Nios II development board connected to your workstation with a serial cable is ideal, this tutorial can be run without it. However, without the serial cable, you will not be able to see the character being received by the host workstation.

Configuring the Quartus II Software

To configure the Quartus II software, perform the following steps:

1. Copy the Nios II “full_featured” example design for your particular board to a location where it can be edited. This example design is located in the following path:

<install directory>/kits/nios2/examples/verilog/<your-nios2-board-type>/full_featured

2. Open the Quartus II software.

3. On the File menu, click Open Project.

4. Browse to the location where you copied the full_featured example design. Select the full_featured.qpf project file and click Open.

5. On the Assignments menu, click Settings.

6. In the Settings dialog box, under the Compilation Process Settings item, select Incremental Compilation. Set the Incremental compilation option to Off (Figure 1).

1 Incremental compilation is currently not supported by the Nios II plug-in.

7. Click OK.

Page 14: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

14 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Figure 1. Compilation Process Settings

Generating Nios II Hardware

You must regenerate the full_featured example design using SOPC Builder before it will properly compile in the Quartus II software.

1. On the Tools menu, click SOPC Builder. The SOPC Builder dialog box appears (Figure 2).

2. In the SOPC Builder dialog box, click Generate. This action rebuilds the hardware for the full_featured reference design.

1 This operation may take a few minutes to complete.

3. Click Exit.

Page 15: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 15Preliminary

Tutorial: Using the Nios II Plug-In

Figure 2. SOPC Builder View

Nios II Software Set-Up

You can now use the Nios II IDE to compile your software application and generate the ELF file. After the file is generated, you will identify the trigger location that you want to use for the Nios II plug-in.

Building the Nios II Software

To build the software application and generate an objdump file, perform the following steps:

1. Open the Nios II IDE Development Suite. On the Windows Start menu, point to Programs, point to Altera, point to Nios II EDS 7.1, and click Nios II 7.1 IDE.

2. On the File menu, point to New and click Project.

Page 16: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

16 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

3. In the New Project wizard, perform the following actions:

a. In the Wizards field, open the Altera Nios II folder and select the Nios II C/C++ Application icon.

b. Click Next.

c. In the Name text field, type signal_tap_test.

d. Turn off the Specify Location option.

e. In the Select Target Hardware field, click Browse.

f. In the File Browser, navigate to the location you copied the Nios II full_featured example design into and double-click on the file full_2c35.ptf.

g. From the Select Project Template list, select Blank Project.

h. Verify that the SOPC Builder System field, in the Select Target Hardware section, contains the system path to your copy of the full_featured reference design. Your New Project wizard should resemble that in Figure 3.

Page 17: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 17Preliminary

Tutorial: Using the Nios II Plug-In

Figure 3. New Project Dialog Box

i. Click Next.

j. On the system library page, select the radio button called Create a new system library named: signal_tap_test_syslib.

k. Click Finish.

4. On the Nios II C/C++ Projects tab, right-click on the signal_tap_test project and click Import.

1 You may need to minimize the Welcome page first.

5. In the Import wizard, perform the following actions:

a. Expand General and select File System (Figure 4).

Page 18: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

18 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Figure 4. Import Source Dialog Box

b. Click Next.

c. Click Browse to the right of the From directory field.

d. Use the file browser to select the folder that contains the file bit_bang_uart.c. Click OK.

e. In the right-hand pane, turn on the file bit_bang_uart.c (Figure 5).

Page 19: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 19Preliminary

Tutorial: Using the Nios II Plug-In

Figure 5. Import Resources Dialog Box

f. Click Finish.

6. To ensure the Nios II IDE generates an objdump file for the system when it builds the ELF file image, perform the following steps:

a. On the Window menu, click Preferences.

b. In the left column, click Nios II.

c. In the Nios II preferences window, turn on Generate objdump file (Figure 6).

Page 20: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

20 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Figure 6. Generate Objdump Preference Setting

d. Click OK.

7. On the Nios II C/C++ Projects tab, right-click on the signal_tap_test project and click Build Project. This command builds the software application, creating an executable ELF and objdump file.

1 Depending on the speed of your computer, compiling this software project can take a couple of minutes the first time.

Finding the Instruction Trigger Condition

The Nios II plug-in should trigger on the first write to the UART peripheral, directly after the entry point to the main() function. To identify the assembly instruction's address that corresponds to the write to the UART's transmit register, you can use the objdump file generated during the software compilation step.

The objdump file format contains a human-readable version of the program you just compiled. It shows the corresponding C instructions in a “decomposed” format that consists of assembly instructions and their location in the Nios II processor's address space. By locating the C instruction responsible for the write operation to the UART's transmit

Page 21: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 21Preliminary

Tutorial: Using the Nios II Plug-In

register, and then examining the assembly instructions that correspond to the C instruction, you can get the address for the assembly instruction responsible for the write to the UART's transmit register. Follow these steps:

1. Expand the signal_tap_test folder in the Nios II C/C++ Projects tab and open the Debug directory.

2. In the Debug directory, right-click on the signal_tap_test.elf.objdump file and click Open.

3. On the Edit menu, click Find/Replace.

4. In the Find field of the Find/Replace dialog box, type IOWR(0x12110a0,1,'*'). This string is the C function call to write the UART's transmit register.

5. Click Find. This action brings you to the line containing IOWR(0x12110a0,1,'*') (Figure 7).

Page 22: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

22 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Figure 7. Nios II Objdump View

6. Scroll down a couple of lines until you find the line containing the stwio r2,0(r3) assembly instruction, and note the address to the left of it. This instruction corresponds to the Nios II processor's write to the UART's transmit register. In this example, the address for this instruction is 0x2000270 (hexadecimal). However, in your particular case this address may be different. You can use the address of this instruction as a trigger for the Nios II plug-in to begin capturing instruction trace data.

In this example, when the Nios II processor executes the assembly instruction stwio r2,0(r3), it writes to the UART transmit control register, which then transmits a character. You can tell that this particular instruction is responsible for the write for the following reasons:

■ The instruction is contained in the block of assembly instructions that correspond to the C instruction IOWR(0x12110a0,1,'*').

Page 23: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 23Preliminary

Tutorial: Using the Nios II Plug-In

■ The other assembly instructions contained in the block are performing operations on the Nios II CPU's registers, and are not writing any information to a peripheral on the bus.

■ The defined behavior of the function stwio is to perform a store word operation to a peripheral (refer to the Instruction Set Reference chapter of the Nios II Processor Reference Handbook).

For these reasons, this assembly instruction in the program is responsible for the write to the UART's transmit register.

Configuring the Hardware Project

Next, configure the Nios II plug-in for operation in the SignalTap II Logic Analyzer. Perform the following actions in the Quartus II software:

1. On the Processing menu, point to Start and click Start Analysis & Elaboration.

2. On the Tools menu, click SignalTap II Logic Analyzer to bring up the SignalTap II file window.

3. In the Instance Manager for the SignalTap II Logic Analyzer, ensure that the Incremental Compilation option is turned off (Figure 8).

Figure 8. Instance Manager Pane

4. Right-click in the Node List pane. Point to Add Nodes with Plug-In and click Nios II.

5. In the Select Hierarchy Level dialog box, select full_2C35:inst|cpu:the_cpu.

6. Click OK.

7. In the Plug-In Options dialog box, click on the browse button .

Page 24: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

24 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

8. In the Select File dialog box, browse to the location for the ELF file you compiled in the Nios II IDE. This ELF file should be present in the full_featured/software/signal_tap_test/Debug directory and named signal_tap_test.elf. Select the file.

9. Click Open. The Select File dialog box closes.

10. Click OK. The Plug-In Options dialog box closes.

11. In the Trigger Levels column for the Nios II plug-in, enter the address that corresponds to the write of the UART's transmit register. In this example, the address was 0x2000270 for the trigger condition (refer to Figure 7 on page 22).

12. Add the RS-232 UART's transmit data signal into the node list by performing the following steps:

a. Right-click on the node list pane and click Add Nodes.

b. Make sure that the Look in field is set to |full_featured| and the Named field is set to an asterisk (*).

c. Click List.

d. In the Nodes Found pane, double-click on the node txd_from_the_uart to add it to the Selected Nodes pane. You view should now resemble Figure 9.

e. Click OK.

Page 25: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 25Preliminary

Tutorial: Using the Nios II Plug-In

Figure 9. UART TXD Signal in Node Finder

13. In the Signal Configuration pane, click on the browse button next to the Clock text field to bring up the Node Finder dialog box. In the Node Finder, perform the following actions:

a. Click on the browse button to bring up the Select Hierarchy Level dialog box.

b. Expand the hierarchy list under full_2c35:inst by clicking on

the icon.

c. In the expanded hierarchy list, click on the entity pll:the_pll.

d. Click OK to close the list.

e. In the Node Finder, click on List to list all of the nodes.

f. Double-click on the node c0 to add it to the Selected Nodes field. Your Node Finder window should now look like Figure 10.

Page 26: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

26 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

Figure 10. Clock Signal in Node Finder

g. Click OK to close the Node Finder.

14. In the Signal Configuration pane, set the Sample Depth field to 256. Your view should now resemble Figure 11.

Page 27: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 27Preliminary

Tutorial: Using the Nios II Plug-In

Figure 11. SignalTap II Setup

15. You can now build the hardware for the project. On the Processing menu, click Start Compilation. If you are prompted to save the SignalTap II instance, click Yes.

1 The Quartus II hardware design may take a long time to compile.

Running the Trace Capture Session

The next step is to use the generated system to run a trace capture session with the Nios II plug-in by performing the following steps:

1. From the Quartus II software, in the JTAG Chain Configuration pane for the SignalTap II Logic Analyzer, perform the following steps:

Page 28: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

28 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

a. On the Hardware pull-down menu, select the programming cable that is connected to your Nios II development board.

b. In the SOF Manager field, click on the browse button .

c. In the Select Programming File dialog box, open the full_featured directory and select the SOF file full_featured.sof. Click Open.

d. Click the Program Device button to download the SOF file into

the FPGA.

2. In the Instance Manager pane for the SignalTap II Logic Analyzer, click the Run Analysis button to start the logic analyzer capture

session.

The analysis should stop with the Status in the Instance Manager pane set to Waiting for trigger.

3. In the Nios II IDE, select the project signal_tap_test in the Projects list.

4. In the Nios II IDE, on the Run menu, click Debug. The Debug dialog box appears.

5. Perform the following actions in the Debug dialog box:

a. Click Nios II Hardware in the left-hand pane.

b. Click the New launch configuration button to create a new

debug launch configuration.

c. In the Project text field, type the name signal_tap_test. Your debug configuration window should now look like Figure 12.

Page 29: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 29Preliminary

Tutorial: Using the Nios II Plug-In

Figure 12. Debug Configuration Setup

d. In the Target Connection tab, set the Nios II Terminal communication device to uart and verify that the Host COM port field contains the correct setting for the serial port connected to your development board.

This step is necessary if you want to see the characters coming through the serial port. If you omit this step, the SignalTap II Logic Analyzer will still be able to capture the data, but you won’t see the characters in the console window of the Nios II IDE.

e. In the Debugger tab, in the Breakpoints at Start-up field, turn on the Break at program entry point option. Turn off the other options.

Page 30: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

30 Altera CorporationPreliminary

Debugging Nios II Systems with the SignalTap II Logic Analyzer

f. Click Apply, followed by Debug. The ELF file is downloaded to the board, followed by a launch of the debugger.

g. In the Confirm Perspective Switch dialog box, click Yes.

6. In the Nios II IDE, in the Debug pane, click the Resume button to

start the Nios II processor execution.

If the serial port is connected, the following message appears in the console window:

*BIT BANG

7. Check the SignalTap II pane in the Quartus II design to verify that the capture session has terminated because the Nios II plug-in's trigger conditions were met. Your SignalTap II dialog box should resemble Figure 13.

Figure 13. SignalTap II Post Capture Dialog Box

Page 31: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

Altera Corporation 31Preliminary

Conclusion

Analyzing the Captured Data

You can now analyze the data captured by the Nios II plug-in and compare it to the objdump of the Nios II ELF file. The data samples from the Nios II plug-in should match up to the signal_tap_test.elf.objdump file results on a one-for-one basis.

Figure 13 demonstrates the following results:

■ The 0th sample captured by the Nios II plug-in matches the trigger condition you set up, capturing instruction stwio r2, 0(r3).

■ The RS-232 UART's transmit data signal began two clock cycles after the stwio instruction, which corresponds to the Nios II IDE writing to the transmit register of the UART.

■ The entire eight-bit, serial transmit sequence for the UART could not be captured because the SignalTap II Logic Analyzer filled its sample buffers before the UART could complete the transmission of the character. Therefore, only the first bit of the eight-bit character sequence was captured.

Conclusion As FPGA designs continue to increase in size and complexity, including one or more embedded processors, peripherals, and buses, more comprehensive debugging tools are needed to reduce system development time. The Nios II plug-in provides you with an easy way to monitor and capture the programmatic execution of a Nios II processor in the FPGA. Also, because the Nios II plug-in is used within the SignalTap II Logic Analyzer's framework, the instruction trace from the Nios II processor can be captured along with other hardware events, providing you with a way to find system design problems in the shortest amount of time.

Document Revision History

Table 1 shows the revision history for this application note.

Table 1. Document Revision History

Date and Document Version Changes Made Summary of Changes

May 2007v1.0

Initial release. —

Page 32: AN 446: Debugging Nios II Systems with the …extras.springer.com/2008/978-0-387-72671-7/Altera...Altera Corporation 1 AN-446-1.0 Preliminary Application Note 446 Debugging Nios II

32 Altera CorporationPreliminary

101 Innovation DriveSan Jose, CA 95134www.altera.comTechnical Support:www.altera.com/support/Literature Services:[email protected]

Copyright © 2007 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company,the stylized Altera logo, specific device designations, and all other words and logos that are identified astrademarks and/or service marks are, unless noted otherwise, the trademarks and service marks of AlteraCorporation in the U.S. and other countries. All other product or service names are the property of their re-spective holders. Altera products are protected under numerous U.S. and foreign patents and pendingapplications, maskwork rights, and copyrights. Altera warrants performance of its semiconductor productsto current specifications in accordance with Altera's standard warranty, but reserves the right to make chang-es to any products and services at any time without notice. Altera assumes no responsibility or liabilityarising out of the application or use of any information, product, or service describedherein except as expressly agreed to in writing by Altera Corporation. Altera customersare advised to obtain the latest version of device specifications before relying on any pub-lished information and before placing orders for products or services.

Debugging Nios II Systems with the SignalTap II Logic Analyzer