Download: nios2lab1.zip.
The purpose of this lab is to learn how to create and use a simple reconfigurable computer system. The system will consist of an Altera Nios II processor and an application program. You will use the Quartus II and SOPC Builder software to generate the hardware portion of the system. You will use the Altera Nios II IDE software to compile, load and run the application program.
First, you will use the SOPC Builder to create a system consisting of a Nios II/f processor, an on-chip memory block, a JTAG UART, an interval timer, and a parallel I/O interface..
Implement the system as follows:
nios2lab.v
the top-level
module. Check the module name and parameter list generated by SOPC
with the values assumed in nios2lab.v
. Edit the file
nios2lab.v
, if necessary, to agree with the names
assigned by the SOPC tool.
DE2_pin_assignments.csv
.
See the documentation from the Quartus compilation: nios2lab1 document
To create a simple Hello World project, perform the following steps:
When the build finishes, the Console view at the bottom of the workbench displays the message "Build completed." If the Console view is not visible, click the Console tab.
To download executable code to the Nios development board do the following:
See: program source
Edit the hello_world_small.c program so that the printf argument includes your name. Rebuild the project, download the new program to the Nios board, and use Alt-PrintScreen to capture the screen. Paste this image into your lab report to verify completion of the lab. Also submit your revised program source file.
When you start the SOPC ("System on a Programmable Chip") tool, you get the following dialog.
Selecting a processor brings up the following dialog:
This next dialog adds On-Chip Memory:
The next dialog adds an Interval Timer:
Here is the dialog for a PIO unit. Note that a port width of 32-bits is selected and both input and output ports are selected.
The JTAG UART provides serial communication between the board and the host computer (through a console window within the IDE).
The completed SOPC tool dialog page summarizes the configured system.
Here is the system generation dialog window:
Finally, here are the dialogs from choosing a NIOS II IDE project:
Following is an example of a modified version of the
hello_world_small
project.
hello_world_small.c
/* * "Small Hello World" example. * * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example * designs. It requires a STDOUT device in your system's hardware. * * The purpose of this example is to demonstrate the smallest possible Hello * World application, using the Nios II HAL library. The memory footprint * of this hosted application is ~3124 bytes by default using the standard * reference design. For a more fully featured Hello World application * example, see the example titled "Hello World". * * The memory footprint of this example has been reduced by making the * following changes to the normal "Hello World" example. * Check in the Nios II Software Developers Manual for a more complete * description. * * In the SW Application project (small_hello_world): * * - In the C/C++ Build page * * - Set the Optimization Level to -Os * * In System Library project (small_hello_world_syslib): * - In the C/C++ Build page * * - Set the Optimization Level to -Os * * - Define the preprocessor option ALT_NO_INSTRUCTION_EMULATION * This removes software exception handling, which means that you cannot * run code compiled for Nios II cpu with a hardware multiplier on a core * without a the multiply unit. Check the Nios II Software Developers * Manual for more details. * * - In the System Library page: * - Set Periodic system timer and Timestamp timer to none * This prevents the automatic inclusion of the timer driver. * * - Set Max file descriptors to 4 * This reduces the size of the file handle pool. * * - Uncheck Clean exit (flush buffers) * This removes the call to exit, and when main is exitted instead of * calling exit the software will just spin in a loop. * * - Check Small C library * This uses a reduced functionality C library, which lacks * support for buffering, file IO, floating point and getch(), etc. * Check the Nios II Software Developers Manual for a complete list. * * - Check Reduced device drivers * This uses reduced functionality drivers if they're available. For the * standard design this means you get polled UART and JTAG UART drivers, * no support for the LCD driver and you lose the ability to program * CFI compliant flash devices. * * * */ #include <stdio.h> int main() { printf("Hello from Nios II!\n"); printf("University of Dayton\n"); return 0; }
Version 7.2 of the Altera tools creates a smaller Hello World application
/* * "Small Hello World" example. * * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example * designs. It requires a STDOUT device in your system's hardware. * * The purpose of this example is to demonstrate the smallest possible Hello * World application, using the Nios II HAL library. The memory footprint * of this hosted application is ~332 bytes by default using the standard * reference design. For a more fully featured Hello World application * example, see the example titled "Hello World". * * The memory footprint of this example has been reduced by making the * following changes to the normal "Hello World" example. * Check in the Nios II Software Developers Manual for a more complete * description. * * In the SW Application project (small_hello_world): * * - In the C/C++ Build page * * - Set the Optimization Level to -Os * * In System Library project (small_hello_world_syslib): * - In the C/C++ Build page * * - Set the Optimization Level to -Os * * - Define the preprocessor option ALT_NO_INSTRUCTION_EMULATION * This removes software exception handling, which means that you cannot * run code compiled for Nios II cpu with a hardware multiplier on a core * without a the multiply unit. Check the Nios II Software Developers * Manual for more details. * * - In the System Library page: * - Set Periodic system timer and Timestamp timer to none * This prevents the automatic inclusion of the timer driver. * * - Set Max file descriptors to 4 * This reduces the size of the file handle pool. * * - Check Main function does not exit * - Uncheck Clean exit (flush buffers) * This removes the unneeded call to exit when main returns, since it * won't. * * - Check Don't use C++ * This builds without the C++ support code. * * - Check Small C library * This uses a reduced functionality C library, which lacks * support for buffering, file IO, floating point and getch(), etc. * Check the Nios II Software Developers Manual for a complete list. * * - Check Reduced device drivers * This uses reduced functionality drivers if they're available. For the * standard design this means you get polled UART and JTAG UART drivers, * no support for the LCD driver and you lose the ability to program * CFI compliant flash devices. * * - Check Access device drivers directly * This bypasses the device file system to access device drivers directly. * This eliminates the space required for the device file system services. * It also provides a HAL version of libc services that access the drivers * directly, further reducing space. Only a limited number of libc * functions are available in this configuration. * * - Use ALT versions of stdio routines: * * Function Description * =============== ===================================== * alt_printf Only supports %s, %x, and %c ( < 1 Kbyte) * alt_putstr Smaller overhead than puts with direct drivers * Note this function doesn't add a newline. * alt_putchar Smaller overhead than putchar with direct drivers * alt_getchar Smaller overhead than getchar with direct drivers * */ #include "sys/alt_stdio.h" int main() { alt_putstr("Hello from Nios II!\n"); /* Event loop never exits. */ while (1); return 0; }
Maintained by John Loomis, last updated 15 January 2008