Lab1 Tutorial
Lab1 Tutorial
C7 Technology
1. Hardware Design
1.1. Required Features
The Nios II processor core is a soft-core central processing unit that you could program onto
an Altera field programmable gate array (FPGA). This tutorial illustrates you to the basic flow
covering hardware creation and software building. You are assumed to have the latest Quartus
II and NIOS II EDS software installed and quite familiar with the operation of Windows OS. If
you use a different Quartus II and NIOS II EDS version, there will have some small difference
during the operation. You are also be assumed to possess a DE2i-150 development board
(other kinds of dev. Board based on Altera FPGA chip also supported).
The example NIOS II standard hardware system provides the following necessary components:
Nios II processor core, that’s where the software will be executed
On-chip memory to store and run the software
JTAG link for communication between the host computer and target
hardware (typically using a USB-Blaster cable)
LED peripheral I/O (PIO), be used as indicators
Leave the EDA Tools Settings options with their default configuration.
Click Finish.
1.3.4. Close the pop up window created by saving the new system.
1.3.7. Double click or just click on the ‘Add’ button. The Nios II Processor configuration
window will come up. Select the ‘Nios II/e’ version. Then click ‘Finish’.
1.3.10. Connect the clk, clk_in_reset and clk_reset between the clk_50 and the
nios2_qsys components as shown in the following figure. Connections are done
by clicking the hollow dots on the connection line. The dots become solid
indicating the ports are connected.
1.3.13. Now, connect the jtag_uart clk to the clk signal, the reset to the clk_reset and
to the clk_in_reset. Likewise, connect avalon_jtag_slave to data_master.
1.3.18. Click the nios2_qsys component. Then, on the right pane the configuration
options should come up. Select the Vectors tab. Update Reset Vector and
Exception Vector as shown in the following figure. Then click Finish.
1.3.21. Rename the sysid_qsys_0 peripheral to sysid_qsys. Then connect the clk,
clk_reset and data_master as shown in the following figure.
1.3.26. Let’s also create an external connection for the reset input. In the clk_in_reset
row, click on the ‘Double-click to export’ in the Export column, and name it
‘reset’.’
1.3.29. The tool will reassign the addresses in such a way that there will not be any
overlap. Cambiar figura, debe aparecer LED y no PIO
1.3.31. In the IRQ column, connect the IRQ31 to the JTAG irq, Interrupt Sender.
1.3.32. After assigning the interrupt, there should be not warnings in the message
window.
1.3.34. Go to Generate -> Generate HDL. In the pop up Generation window, select
VHDL as ‘Create HDL design files for Synthesis’. Then click Generate.
1.3.36. Click Close. Then exit from the Platform Designer, File->Exit, to return to the
main Quartus window.
1.4.2. Leave that template open. Now, create a new VHDL file by doing File -> New,
then select VHDL file.
1.4.4. Type in the following piece of code (use the template previously open to write
the component declaration and the component instantiation).
1.4.6. After saving the .vhd file, you will get an error message similar to the following:
This is to the fact that the component DE2i_150Qsys is not still part of the project.
It is necessary to add it.
1.4.7. To add a file to a project it can be done by selecting Files in the Project
Navigator pane. Then right click over the Files icon and select Add/Remove Files
in Project.
1.4.10. Configure the My_First_NioII.vhd file as Top-Level entity, by right click on the
file name and click on the Set as Top-Level Entity option.
1.4.12. Next step, we will assign the I/O pins. Do Assignments -> Pin Planner. Make the
assignments according to the following table (the I/O pins information is detailed
in the DE2-115 User Manual document).
1.4.14. Recompile.
2.4. In the New Project wizard, make sure the following configurations:
2.4.1. Under Target hardware information, next to SOPC Information File name,
browse to locate the <design files directory> where the previously created
hardware project resides.
2.5. When getting back to the main window, there are now two new project created
shown in the Project Explorer pane.
Note: When you build the system library for the first time the NIOS II SBT for
Eclipse automatically generates files useful for software development, including:
Installed IP device drivers, including SOPC component device drivers for
the NIOS II hardware system.
Newlib C library, which is a richly featured C library for the NIOS II
processor.
NIOS software packages which includes NIOS II hardware abstraction
layer, NicheStack TCP/IP Network stack, NIOS II host file system, NIOS II
read-only zip file system and Micrium’s μC/OS-II real time operating
system(RTOS).
system.h, which is a header file that encapsulates your hardware system.
alt_sys_init.c, which is an initialization file that initializes the devices in
the system
2.6. Double click on the ‘hello_world.c’ file. To just take a look at the ‘C’ code for the
example.
2.10. Now the whole system just created is ready to be downloaded to the board. At
this point be sure you have already configured the FPGA with the configuration file as
it was explained in 1-5.
If you have not download the configuration file from Quartus Prime environment, you
still can do it from the SBT console by doing Nios II -> Quartus Prime Programmer.
2.11. To download the program to the FPGA and immediately execute it, right-click
the My_First_NiosII project, select Run As, and then select Nios II Hardware.
3.1. Re-write the hello_word.c file with the following ‘C’ code.
In case you get an error message regarding LED_BASE, it means that the symbolic
name for the LED address base is other than LED_BASE.
Open the system.h file (which functionality is explained in 3.4), and do a search for LED
and find the mnemonic for LED BASE.
3.3. There is no need to build the project again before downloading it to the board, since
that task, re-build the project, is done automatically when we select run the Nios II in
hardware. Hence, do right-click in My_First_NiosII Project, then Run->Run As -> Nios
II Hardware.
If you have power off the board before starting step 3, you should configure the FPGA
again before run the ‘C’ code in hardware
3.4.1. Line 2 of the hello_word.c code, include the system.h header file. This file
contains a lot of definitions of the Nios II hardware system just created. Among
them are the mnemonics, memory locations, base addresses, settings for the
hardware components, etc. Let’s open the system.h file, underneath the
My_Fisrt_NiosII_bsp folder, to take a look at it.
3.4.2. If you remember, when we create the hardware system in Platform Designer,
we add to the system a peripheral, pio_0, that we named led, step 1.3.23 and
followings. The Nios II processor controls the PIO ports, in this case LEDs port, by
reading and writing to a specific memory location. The memory locations was set
by Platform Designer, step 1.3.29. Any PIO peripheral has four registers: data,
direction, interrupt mask, and edge capture. To turn the LEDs on and off, we will
write the data register from the ‘C’ code.
3.4.3. On the other hand, line 3 of the ‘C’ code include the header file
altera_avalon_pio_regs.h. This file is located in
G:\intelFPGA_lite\17.1\ip\altera\sopc_builder_ip\altera_avalon_pio\inc
The altera_avalon_pio_regs.h file has several definitions that used along with
read and write functions defined in the io.h file to easily have access to the low
level hardware from the Nios II processor. The most important functions are:
By using these functions it is possible to read and write the PIO data register. In
this exercise we will write this register to turn on (write ‘1’) and off (write ‘0’) the
LEDs associated to this memory registers.
4.1. To use the debug tool it is necessary to change the perspective of the tool to ‘NiosII
Debug’. Do Run -> Debug to open the Debug perspective.
4.2. To place a breakpoint in a specific statement, just place the cursor on the left side of
the line number, and do a double-click, a light-blue circle should show up.
4.3. The ‘C’ code variables are visible in the ‘Variables’ tab (upper right side).
4.5. To debug the ‘C’ code there are multiple options, which are displayed in the following
figures.
5.3. In the Linker Script tab, observe which memory has been assigned for Program
memory (.text), Read-Only data memory (.rodata), Read/Write data memory
(.rwdata), Heap memory, and Stack memory.
5.4. You can use the memory options in the Linker Script box to change the memory target
when you have more than one option.
5.5. Click Exit to get out of the BSP Editor and return to the SDT main window.