Monitor Tutorial
Monitor Tutorial
This tutorial presents an introduction to the Altera Monitor Program, which can be used to compile, assemble,
download and debug programs for Altera’s Nios II processor. The tutorial gives step-by-step instructions that
illustrate the features of the Altera Monitor Program.
The process of downloading and debugging a Nios II application requires the presence of an actual FPGA
device to implement the Nios II processor. For the purposes of this tutorial, it is assumed that the user has access
to the Altera DE2 Development and Education board connected to a computer that has Quartus II (version 9.0 or
higher) and Nios II EDS software installed.
The screen captures in the tutorial were obtained using version 4.1 of the Altera Monitor Program; if other
versions of the software are used, some of the images may be slightly different.
1
Contents
1 Installing the Altera Monitor Program 3
9 Single step 18
10 Using Breakpoints 18
2
Introduction
The Altera Monitor Program is a software application that runs on a host PC connected to a Nios II system. It
allows the user to compile or assemble a Nios II application, download the application to the Nios II system, and
then debug the running application. The Monitor Program provides functionality that allows the user to:
• Set watch expressions and watch their values at different points in the execution of the program.
• Examine a graphical view of an instruction trace that records the set of recently executed instructions.
• Perform terminal input/output via the JTAG UART component.
1. Download the Altera UPDS from the University Program section of Altera’s website. It can be found by
going to www.altera.com and clicking on University Program under Education & Events. Once in the Uni-
versity Program section, click on Design Software under Educational Materials, and select Altera Monitor
Program. Download the EXE Install Package and extract it to a directory of your choice. In this tutorial, we
have chosen D:\Altera_UPDS. As shown in Figure 1, the folder will contain a single executable file named
altera_upds_setup.exe.
2. Double-click on the altera_upds_setup.exe executable file. This will bring up the first screen of the installer
as illustrated in Figure 2. Click on the Next button and proceed to the next step.
3. The installer will display the License Agreement; click I Agree to continue.
4. On the next screen, you will see the components that will be installed, as shown in Figure 3.
The Altera Monitor Program component will be installed to the location %ALTERA_HOME%\
University_Program\Monitor_Program, where %ALTERA_HOME% is the directory that is one level above
the Quartus II installation directory.
The tutorial files will be installed to the %ALTERA_HOME%\University_Program\Monitor_Program\tutorial
directory, and we will refer to this path as <TUTORIAL_FILES> throughout the remainder of this tutorial.
Click Next to continue.
3
Figure 2. Altera UPDS Install Wizard.
5. The installer is now ready to begin copying files. Click Install to install the Altera UPDS, along with the
Monitor Program. During the installation process, you will be asked if you would like a shortcut to the
Altera Monitor Program to be placed on your Windows Desktop. Answering yes will place an icon similar
to the one shown in Figure 4 on your desktop.
6. Assuming that the installation was successful, the screen shown in Figure 5 will be displayed. Click on the
Finish button to complete the installation. Should an error occur, a window will suggest the appropriate
action. Errors include:
4
Figure 5. Altera UPDS installation finished.
5
Figure 6. The Altera Monitor Program at startup.
6
3 Creating a New Project
To use the Monitor Program, you first have to create a project. The project stores the information that the Monitor
Program needs to compile, assemble, execute, and debug your application.
To create a new project, click the File > New Project... menu item. The New Project Wizard window will
appear, as shown Figure 8. Using this wizard, we will specify the project’s name and location, the Nios II system
that will be used to run our program, and the program itself.
The window consists of a content area, a message area, and navigation buttons. The content area contains
the fields that are used to input information about the project. The message area displays error and information
messages. Double-clicking on an error message will select the field causing the error. The navigation buttons are
used to move between the different steps of the wizard.
Proceed with the steps below to configure the new project.
7
Figure 9. New Project Wizard: Specify a project name and directory.
Specify a system
The next step is to specify a Nios II system for your program to run on. Nios II-based systems are described by a
.ptf file, which is generated by the Altera SOPC Builder tool1 when the system is created. An optional .sof file,
if specified, allows the Monitor Program to download the Nios II-based system onto the board. If this file is not
specified, you will have to use some other method (such as the Quartus II software) to do this.
The drop-down list on the Select a system pane allows you to select one of the sample systems provided with
the Monitor Program, or <Custom System> that allows you to specify your own system. Both the .ptf and the
.sof files are automatically filled in by the Monitor Program if a sample system is selected. However, if <Custom
System> is selected, then the files need to be specified manually in the System details pane.
In this tutorial, select <Custom System> from the drop-down list at the top of the window, since we will use a
system designed specifically for this tutorial. To specify the .ptf file for the system, click on the Browse... button
next to the System description (PTF) file field, and navigate to <TUTORIAL_FILES>\example\hw. Select
system.ptf, and click Select. To allow us to use the Monitor Program to download the system onto the board, we
will also specify the .sof file for the system. Click on the Browse... button next to the Quartus II programming
(SOF) file (optional) field, and select system.sof, which is located in the same directory as the .ptf file. This
directory should be selected by default.
In addition to specifying a custom system, you can select one of the sample systems provided with the Monitor
Program. You can later experiment with the sample systems, whose documentation can be accessed by selecting
the system of interest and clicking on the Documentation button.
The window with the settings filled in is shown in Figure 10. Click Next > to continue.
1 More information about creating systems using SOPC Builder can be found in the tutorial called Introduction to the Altera SOPC Builder,
8
Specify a program type
The next step is to select the type of program that you would like to compile, assemble, debug, and run using the
Monitor Program. The Program Type drop-down list allows you to choose from among the following program
types:
1. No Program: Use this option if you want to connect to the Nios II system, without loading a program
first. This is useful for running and debugging a program that was loaded into the system using some other
method. It can also be used to read from and write to the system’s address space, to access its memory-
mapped devices.
If you select a sample Nios II system for running your program, it may have sample programs bundled with it.
Sample programs range from very simple examples that demonstrate basic concepts, to complete demonstrations
that exercise many aspects of a system. They include the required source files and any settings that are needed
for the program to run properly. You may extend or modify a sample program if you choose to. If you select a
program type that has sample programs available for your sample system, you can check the Include a sample
program with the project check box to display a list of all the available sample programs, and choose one for
your project. This feature will not be used in this tutorial.
For this tutorial, select Assembly Program under Program Type. We will specify an assembly program
written specifically for this tutorial in the next step. The window with the settings filled in is shown in Figure 11.
Click Next > to continue.
9
The only program option in this step that is available for assembly programs is the Start symbol option. The
start symbol of an assembly-language program identifies the label that corresponds to the first instruction of the
program.
To add the single assembly code file that is needed by this tutorial, click on the Add... button. In the file
selection dialog that pops up, navigate to the <TUTORIAL_FILES>\example\sw\main_tutorial_src directory,
select the main_tutorial.s file, and click Select.
Leave the Start symbol program option at its default value. The default start symbol is _start and this is
the symbol that is used in main_tutorial.s.
Note that this wizard step is not displayed if you select the No Program program type.
The window with the settings filled in is shown in Figure 12. Click Next > to continue.
1. Select the cable used to connect your host computer to the DE2 board from the Host connection drop-down
list. The DE2 board is connected via a USB-Blaster cable.
2. The system used in this tutorial only has a single processor named cpu. It should already be selected in
the Processor list. The addresses of the selected processor’s reset and exception vectors are shown for
reference.
3. The system used in this tutorial only has a single terminal device, named jtag_uart, which should
already be selected in the Terminal device list. It will be connected to the terminal in the Monitor Program.
The window with the settings filled in is shown in Figure 13. Click Next > to continue.
10
Figure 13. New Project Wizard: Specify system parameters.
• .text section
– Memory device: memory/s1 (0h - 7fffh), corresponding to the on-chip memory of the Nios
II system (this is the default and only choice in our example system)
– Start offset in device: 1000, corresponding to a 4096-byte offset into the on-chip memory to start the
.text section
• .data section
– Memory device: memory/s1 (0h - 7fffh), corresponding to the on-chip memory of the Nios
II system (this is the default and only choice in our example system)
– Start offset in device: 1000, corresponding to a 4096-byte offset into the on-chip memory to start the
.data section.
The window with the settings filled in is shown in Figure 14.
Note that the .text and .data offsets are the same, which would lead to an overlap of the two sections in
memory. However, because the two offsets are exactly the same, the linker script used to produce the program
executable will instead automatically place the .data section immediately after the .text section.
To make full use of these settings in your code, you will need to explicitly place the .text and .data
assembler directives in your code. If you do not, the settings for the .text section will be used to locate the first
instruction of your program. You should always use these directives if you want to separate your program text and
data (for example, by placing each in a different memory device). Simply using .org directives for this purpose
can cause the ELF and SREC files generated by assembling your program to be very large, especially if there is a
wide gap between the text and data sections.
Note that the program memory settings are only available for the assembly and C program types.
Click Finish to create the new project and exit the wizard. At this point, you will be presented with a prompt,
shown in Figure 15. This prompt appears whenever you create a new project (or open an existing project) that
has the .sof file for the Nios II system specified. Clicking Yes will instruct the Monitor Program to attempt to
download the Nios II system associated with the project onto the DE2 board. You can also choose to download
the system at a later time, by following the instructions in Section 5.
The next section describes how to modify the settings of a project after it is created.
11
Figure 14. New Project Wizard: Specify program memory settings.
12
Figure 16. The Project Settings window.
1. Click on Actions > Download SOPC Builder System. The window shown in Figure 17 will pop up,
displaying the name of the .sof file that we specified earlier when creating the project. This file contains the
data that will be downloaded onto the board, representing the Nios II system that we selected. You have the
option of specifying a different file by clicking on Specify Different File..., but in this tutorial we will just
use the file that we specified earlier (which will be the case most of the time).
2. Click on the Download button. The system will be downloaded onto the board, and after a short while you
should get a success message. If the download failed, make sure that the board is powered up and properly
connected via the cable that was specified in the Host connection list in the New Project Wizard.
13
6 Compiling and Loading the Program
After successfully creating a project, the program can be compiled and downloaded onto the DE2 board. There
are three different commands that can be used to compile and/or load a program:
In this example, the program has not yet been compiled, so it cannot be loaded (the Load option is disabled).
Click the Actions > Compile & Load menu item or click the toolbar button to begin the compilation and
loading process. Throughout the process, messages are displayed in the Info & Errors window. The messages
should resemble those shown in Figure 18.
Figure 18. Compilation and loading messages (the Info & Errors window has been maximized).
After successfully completing this step, your Monitor Program display should look similar to Figure 19. At
this point, the program is paused at its first instruction.
Compilation errors
During the process of developing software, you will likely encounter compilation errors. Error messages from the
Nios II assembler or from the C compiler are displayed in the Info & Errors window. An example of a compiler
error message is shown in Figure 20. The file name and the line number corresponding to the source of the error
are displayed, in addition to an indication of the cause of the error. You may be able to deduce the real cause of
the error from the message or you may need to do some additional searching.
14
Figure 19. The Altera Monitor Program window after loading the example program.
15
Figure 21. Disassembly window after the program has been stopped.
Figure 22. Pop-up menu to configure the display of the Disassembly window.
By scrolling using the vertical scrollbar on the right side of the Disassembly window or by using a mouse scroll
wheel, different regions of memory can be disassembled and displayed. It is also possible to scroll to a memory
address or an instruction symbol directly by using the Goto instruction panel in the Disassembly window. Access
this panel through the Actions > Goto instruction... menu item and enter a symbol name or an instruction address
in hexadecimal format. The instruction address must be a multiple of 4 because every instruction address is aligned
16
Color Description
Brown Source code
Green Disassembled instruction name
Blue Registers
Orange Immediate & offset values
Dark blue Address values & labels
Purple Clickable link
Gray Machine encoding of the instruction
on a 32-bit word boundary. For example, enter _start or 1000 and press Go. The Disassembly window will
show the 0x00001000 address as its first instruction, as shown in Figure 23, which also corresponds to the
_start symbol. Also note that the instruction is highlighted with a pink background.
Register and memory values can be examined in the Disassembly window while the program is in a Paused
state. This is done by hovering your mouse over a register or a register + offset in the window, as shown in Figure
24.
The Disassembly window also produces special clickable links in its display of branch instructions. Clicking
one of these links will display the instruction that the processor would jump to if the branch was taken. Figure 25
shows one example of a link associated with a call instruction.
17
Assembly Language and Machine Instructions
The Disassembly window is a good place to examine what machine instructions are produced by the compiler from
your assembly-language instructions or C code. The translation from assembly-language instructions to machine
instructions is handled by the Nios II assembler and it is a transparent process to the programmer. However, it is
beneficial to examine the disassembled code and compare it with the source code. This is readily done because
the Monitor Program displays both the source statements and the disassembled code in different colors. Observe
that pseudoinstructions are implemented as different machine instructions. For example, the movia pseudoin-
struction is implemented by the two instructions orhi and ori, as shown at the address values 0000102c and
00001030, respectively, in Figure 21.
9 Single step
Before discussing the single step action, it is convenient (for demonstration purposes) to restart execution of the
program from the beginning. Click the Actions > Restart menu item or click the toolbar button to restart
the program. Notice that the pc register value displayed in the Registers window is 0x00001000 and the
Disassembly window is highlighting that instruction.
The Monitor Program has the ability to perform single step actions. Each single step consists of executing a
single machine instruction and returning control to the Monitor Program. Note that if the program being debugged
was written in C, each individual single step will still correspond to one assembly language instruction generated
from the C code. The ability to step through statements in the high-level source code is not supported by the
Monitor Program; however, Altera’s Nios II Integrated Development Environment supports this advanced feature.
The single step action is invoked by clicking on the Actions > Single step menu item or by clicking on the
toolbar button. The instruction that is executed by the processor is the one highlighted by the Disassembly
window before the single step.
Since the first step in this section was to restart the program, the first single step will execute the instruction at
0x1000, which will zero out the upper 16-bits of the sp register. Subsequent single steps will continue to execute
one instruction at a time, in sequential order. Single stepping at a branch instruction may jump to a non-sequential
instruction address if the branch is taken. You can observe this behavior by single stepping to 0x00001028,
which is a call instruction. Single stepping at this instruction will set the pc value to 0x000011b0, which is
the location of the UPDATE_HEX_DISPLAY label.
The Step Over Subroutine option in the Actions menu performs the Single Step operation unless the current
instruction is a call instruction. In this case the program will run until the subroutine called is completed.
10 Using Breakpoints
Breakpoints are special conditions that are checked by dedicated hardware in the Nios II processor as the applica-
tion is running in real-time. Breakpoints can be triggered in four different ways:
Note that trigger types 2-4 require the Nios II processor to be compiled with JTAG Debug Level 2 or higher.
This section of the tutorial will cover the process of setting an instruction breakpoint (trigger type 1). There are
two ways to set an instruction breakpoint. The first method can be used to set a simple instruction breakpoint as
follows:
18
2. Navigate to the instruction address that will have the breakpoint. For this example, display the check_shift
instruction label.
3. Click on the gray bar to the left of the address 0000103c (address value of the check_shift label) to
set an instruction breakpoint at this location. See Figure 26 for an illustration of what a breakpoint in the
Disassembly window looks like. Clicking the same location again will remove the breakpoint.
Once the instruction breakpoint has been set, run the program and the breakpoint should trigger when the pc
register value equals 0x0000103c. The Monitor Program will look similar to Figure 27; notice the message in
the Info & Errors window indicating that an instruction breakpoint has been triggered.
Figure 27. The Monitor Program after the breakpoint has been triggered.
The second method of setting a breakpoint can be used for all four trigger types as follows:
19
Figure 28. Breakpoints window.
3. Right-click on the header corresponding to the breakpoint type you want to add. For example, to set a
breakpoint that triggers when the processor writes to a particular address, right-click on the write watch-
points table, as shown in Figure 29.
Figure 29. Adding a breakpoint, in this case a write watchpoint, in the Breakpoints window.
4. Click Add. A new entry will appear in the corresponding table. Enter the desired breakpoint address.
The Monitor Program also supports a more advanced form of a breakpoint, called a conditional breakpoint.
A conditional breakpoint is an instruction breakpoint that only triggers when the usual instruction breakpoint
condition is met and an additional user-specified condition is met. For this example, you will use the same
breakpoint from before but with the condition r2 == 0, which in this program’s context is when the scroll
direction is to the left. The process to set this conditional breakpoint is as follows:
The conditional breakpoint is now set. Run the program and as the dE2 digits on the hexadecimal display
disappear and the program begins to shift the digits to the left, the breakpoint will trigger. The Info & Errors
window will again have a message about the cause of the breakpoint, including the trigger condition that was
satisfied, as shown in Figure 31.
20
Figure 30. Edit breakpoint condition window.
Figure 31. Message displayed in the Info & Errors window due to a triggered conditional breakpoint.
21
Figure 32. Changing the number format of the register values in the Registers window.
Figure 33. Register values after the breakpoint trigger; editing the value of the r2 register.
5. Press Enter or click away from the text box to apply the change.
6. Resume the execution of the program and you should see that the value on the hexadecimal display is
scrolling left now.
7. Eventually the conditional breakpoint that was set in step 2 will trigger again. Continue on to the next
section of the tutorial when this occurs.
22
The colour of the contents displayed depends on whether that memory location corresponds to an actual mem-
ory device, a non-memory device, or is not mapped at all in the system. A memory location that corresponds to
a memory device will be coloured black. A location that corresponds to a non-memory device will be coloured
blue. A non-mapped memory location will be coloured grey. If in the last time the memory location was refreshed
the value changed, the value in that memory location will be displayed in red.
Click the Refresh Memory button located in the Goto memory address panel of the memory window to
refresh the current contents in memory. If a memory location being displayed corresponds to a non-memory
device, it will only be updated if the Query All Devices checkbox is checked.
• Memory element size: the display can format the memory contents as bytes, half-words (2-bytes), or words
(4-bytes). This can be configured from the context menu accessible by right-clicking on the Memory
window, as shown in Figure 35.
Figure 35. View as menu used to select the memory element size in the Memory window.
• Number of words per line: the number of words per line can be configured to make it easier to find memory
addresses. This can be configured from the context menu accessible by right-clicking on the Memory
window, as shown in Figure 36.
• Number format: this is similar to the number format option in the Register window. This can also be
configured from the context menu accessible by right-clicking on the Memory window.
• Display order: the display can display addresses increasing from left-to-right or right-to-left. Configure this
option by right-clicking on the Memory window, as shown in Figure 37.
23
Figure 36. Number of words per line menu in the Memory window.
Similar to the Disassembly window, you can view different memory regions by scrolling using the vertical
scroll bar on the right or by using a mouse scroll wheel. There is also a Goto memory address panel in the
Memory window analagous to the Goto instruction window. Click the Actions > Goto memory address...
menu item to display the Goto memory address panel. As shown in Figure 38, you can enter any address in
hexadecimal, press Go, and the Memory window will display that address. In this example, display the 11f8
address, which is where the buffer used by the program is stored.
Since the program reads from this buffer and passes the value to the hexadecimal display, the value shown on
the hexadecimal display can be changed by changing the memory value. Proceed as follows:
1. In the row starting at the address 000011f0, double-click the word under the +0xc column. This will
bring up a text box to edit the word value at the address 000011fc.
24
2. Type in abcd, as in Figure 39.
3. Press Enter or click away from the text box to apply the memory change.
Upon resuming program execution, you will see that the hexadecimal display is now scrolling abCd.
Character display
The Memory window can also be configured to interpret memory byte values as ASCII characters. This can
be done by checking the Show equivalent ASCII characters menu item, accessible by right-clicking on the
Memory window, as shown in Figure 40.
Figure 40. Checking the Show equivalent ASCII characters menu item.
The right side of the figure shows a sample ASCII character display. Usually, it is more convenient to view the
memory in bytes and characters simultaneously so that the characters appear in the correct sequence. This can be
accomplished by clicking the Switch to character mode menu item, which can be seen in Figure 40. A sample
character display in the character mode is shown in Figure 41.
25
You can return to the previous memory view mode by right-clicking and clicking the Revert to previous mode
menu item.
Memory fill
Memory fills can be performed in the Memory window. Click the Actions > Memory fill... menu item or right-
click on the Memory window and click the Memory fill... menu item. The Memory fill panel will appear on
the left-side of the Memory window. Simply fill in the desired values and click Fill. An example memory fill is
shown in Figure 42, which starts at address 0x2000 and ends at 0x2020. The fill value is 2-bytes in length and
has a value of 0xabcd.
Figure 42. Memory fill panel being used to perform a memory fill.
1. Delimited hexadecimal value files: These files are plain ASCII files aimed at loading numerical data into
memory. The file format is defined as follows:
• All memory values are specified as hexadecimal values, with an optional sign in front of the value.
• Individual memory values are separated by a delimiter character.
• There can be multiple lines of delimited values in the file.
For the purpose of this tutorial, select the <TUTORIAL_FILES>\sample.csv file. This file is a comma-
delimited hexadecimal value file.
2. Intel HEX-format files: These files are in another special format aimed at loading numerical data into mem-
ory. You can use the Quartus II software to create Intel HEX-format files. When doing so, ensure that the
word size is set to 8-bits.
3. Binary files: These files are loaded byte-by-byte without any interpretation. This is useful for loading binary
data, such as audio or image files.
26
After selecting a file, a start address needs to be specified to indicate where to start loading the file data. In
this example, specify 2000. In the case of delimited hexadecimal value files, two additional parameters need to
be specified:
1. Delimiter character: This is the character that separates consecutive values in the file. In this example, a
comma (,) separates the values in the file.
2. Value byte size: The byte size of each value element. The Monitor Program will truncate values to be within
the specified byte size. Specify a value of 4.
After all the parameters have been specified, click Load and you should see the loaded values in the Memory
window, as shown in Figure 43.
Figure 43. Load file panel being used to load a delimited hexadecimal value file into memory.
Figure 44. Adding a watch expression via the Add menu item.
3. The Edit Watch Expression window will appear, like in Figure 45. Enter the desired watch expression,
such as mem32(sp), which will display the full-word value at the current stack pointer address.
4. Click Ok. The watch expression and its current value will show up in the table.
5. The number format of the displayed value can be changed by right-clicking on the row for that value, as
shown in Figure 46.
6. As you repeatedly run the program and stop it at various points, the watch expression will be re-evaluated
each time and its value shown in the table of watch values.
27
Figure 45. The Edit Watch Expression window.
1. Switch to the Trace window. There is probably already something there because the instruction trace has
been running since the program was loaded.
2. For this part of the tutorial, first clear the trace by right-clicking in the Trace window and clicking Clear
trace sequences, as shown in Figure 47.
2 See chapter 4 in the Nios II Processor Reference Handbook for more information about the configuration settings of the JTAG Debug
Module. The Handbook can be found in the Nios II Literature section of Altera’s web site.
28
Figure 47. Clear the trace sequences.
3. Remove all existing breakpoints and add two new instruction breakpoints at 1030 and 103c. These two
breakpoints will be used to skip the delay_loop section of the code, which does not produce very inter-
esting results for the instruction trace.
4. Run the program until the breakpoint at 103c is triggered. Your Disassembly window should look similar
to Figure 48 with the breakpoints set and the instruction at 103c highlighted.
5. Continue the program’s execution; it will execute the code to do some checks on the buffer as well as
actually shift the contents of the buffer by one hexadecimal digit. The hexadecimal display will also be
updated by a call to UPDATE_HEX_DISPLAY before the breakpoint at 1030 is triggered.
6. Switch back to the Trace window. The window will now be displaying all the instructions executed starting
from the first breakpoint to the second breakpoint, as indicated in Figure 49. As seen in the figure, the trace
is divided into instruction blocks. Although it is not evident in this trace, the Monitor Program will try to
find repeated instruction blocks and common sequences to reduce the length of the trace on the screen.
29
Figure 49. A partial view of the trace between the two breakpoints.
1. New Project: Opens the New Project Wizard, which allows you to create a new project. Any previously
opened project will be closed.
2. Open Project: Displays a window to select an existing project file and loads it.
3. Open Recent Project: This submenu will display the five most recently-used project files. Use this menu
to open an existing project.
4. Save Project: Saves the current project. This is used to save the project’s settings when they are modified
via the Project Settings window.
30
16 Using the Terminal
This section of the tutorial demonstrates the functionality of the Terminal window. The Terminal window allows
a program to interact with the user using character I/O. The window will interact with the program using a terminal
device connected to the Nios II system. The terminal device can be selected in the Terminal device drop-down
list, available in the New Project Wizard and the Project Settings windows.
This section uses a different source file, and thus the program needs to be reconfigured. A project file is
provided to automatically load the correct settings for running the terminal example program. To load the project
file, proceed as follows:
1. Click the Actions > Disconnect menu item or click the toolbar button to end the current GDB debugging
session.
2. Click the File > Open Project... menu item.
3. Select the file located at <TUTORIAL_FILES>\example\sw\terminal_tutorial.ncf and click Open.
4. This step is not required but it is useful as a demonstration to verify that the correct program is now specified.
Open the Project Settings window by clicking on the Settings > Program Settings... menu item, or by
clicking on the toolbar button. You should see one source file listed, similar to Figure 51.
Figure 51. Project Settings window for the Terminal window tutorial.
Now that the project for the terminal example program was opened, this section of the tutorial will demonstrate
the functionality of the Terminal window in the Monitor Program.
1. Compile & Load the program. If the compilation fails, make sure that you have write permissions to the
directory where the terminal example program resides. This may be the case if you are running the Monitor
Program from a shared location on a public computer, such as in a university laboratory. In this case, try
copying the tutorial example directory (<TUTORIAL_FILES>\example) to another location, and re-open
the project from there. The project file stores the paths to all files (such as the system PTF file and the
program source files) relative to itself, so as long as the location of the system and program files remains the
same relative to the project, it can be opened from any location.
2. Once the program has been successfully loaded, the Terminal window will indicate that a connection has
been established, similar to Figure 52.
3. Run the program. The program will clear the Terminal window and write the string
Hello Altera Monitor Program, as shown Figure 53.
31
Figure 52. The Terminal window after a connection has been established to the JTAG UART on the board.
4. At this point of the program’s execution, the program is ready to accept terminal input and echo it back.
Click on the Terminal window and type something. You will see that what you type shows up in the
window. This is done by the code in the program; the Terminal window, by default, does not automatically
echo what is typed.
As mentioned in step 3, the program clears the Terminal window. This is accomplished through a special
character sequence that is interpreted by the Monitor Program to be a terminal command. The Monitor Program’s
Terminal window supports a subset of the VT100 terminal commands. The supported commands are listed in
Table 2. Note that <ESC> is actually one character, with the ASCII value 0x1B.
Table 2. VT100 commands supported by the Terminal window in the Monitor Program.
32
17 Using Device Drivers (Advanced)
Many of the IP cores that are used by the Altera SOPC Builder to create systems (including the University Program
IP Cores) come bundled with device drivers that can be used by programmers to access their functionality. The
device drivers are based on the hardware abstraction layer (HAL) system library. To use the HAL, the Nios II
Software Build Tools generate a special Board Support Package (BSP) for the selected Nios II system. This
allows easy access to the functionality of the HAL that is relevant to the specific system.
To make use of this feature, create a Monitor Program project, specifying Program with Device Driver
Support as the program type. Usually, you will write C or C++ programs to take advantage of the HAL, but you
can also specify assembly language source files if required.
When you compile your program, a BSP will be generated for your system in the \BSP subdirectory of the
project directory. Your compiled program will then be linked with the BSP to produce the final binary program
executable. Upon subsequent program compilations, the BSP will be re-generated and re-compiled only if the
Nios II system has changed since the last compilation.
To re-generate the BSP manually, use the Actions > Regenerate Device Drivers (BSP) menu item. This is
useful if the system has not changed, but the device drivers for some of the IP cores used by the system have
changed. Re-generating the BSP in this case is the only way to ensure that your program uses the latest drivers.
To get access to the functionality of the HAL in your program, you will need to include the relevant header
files. In addition to providing access to device drivers, the HAL supports a lot of other useful functionality. For
detailed information about using the HAL, consult the Nios II Software Developer’s Handbook, which can be
found in the Nios II Processor subsection of the Literature section of Altera’s website.
33
responses that GDB sends back. The Monitor Program provides the option of sending your own GDB commands
to the debugger. Consult online resources to learn what commands are available.
34
Copyright ©2009 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 as trademarks
and/or service marks are, unless noted otherwise, the trademarks and service marks of Altera Corporation in
the U.S. and other countries. All other product or service names are the property of their respective holders.
Altera products are protected under numerous U.S. and foreign patents and pending applications, mask work
rights, and copyrights. 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 Corporation.
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.
This document is being provided on an “as-is” basis and as an accommodation and therefore all warranties, rep-
resentations or guarantees of any kind (whether express, implied or statutory) including, without limitation, war-
ranties of merchantability, non-infringement, or fitness for a particular purpose, are specifically disclaimed.
35