DE0_Nano_User_Manual_v1.9 (1162595), страница 8
Текст из файла (страница 8)
A dialog box will appear upon successful completion of the compile, as shown in Figure 7-49.Figure 7-49 Compile project completely38. Now, we will assign the inputs and outputs of the circuit to specific pins. Select Assignments >Pin Planner from the menubar, as shown in Figure 7-50. The pin planner is shown in Figure 7-51.Figure 7-50 Pins menu116Figure 7-51 Blank Pins39. Input Location values as shown in Figure 7-52.Figure 7-52 Set Pins40.
Close the pin planner and recompile the project.7.3 Download the Hardware DesignThis section describes how to download the configuration file to the board.Download the FPGA configuration file (i.e. the SRAM Object File (.sof) that contains the NIOS IIbased system) to the board by performing the following steps:1. Connect the board to the host computer via the USB download cable.2. Start the NIOS II IDE.3. After the welcome page appears, click Workbench.4.
Select Tools > Quartus II Programmer.5. Click Auto Detect. The device on your development board should be detected automatically.6. Click the top row to highlight it.1177. Click Change File.8. Browse to the myfirst_niosii project directory.9. Select the programming file (myfirst_niosii.sof).10. Click OK.11.
Click Hardware Setup in the top, left comer of the Quartus II programmer window. TheHardware Setup dialog box appears.12. Select USB-Blaster from the currently selected hardware drop-down list box, as shown inFigure 7-53.Note: If the appropriate download cable does not appear in the list, you must first install driversfor the cable. Refer to Quartus II Help for information on how to install the driver.Figure 7-53 Hardware Setup Window13. Click Close.14. Make sure the Program/Configure option for the programming file (see Figure 7-54 for anexample).15. Click Start.118Figure 7-54 Quartus II ProgrammerThe Progress meter sweeps to 100% after the configuration finished. When configuration iscomplete, the FPGA is configured with the Nios II system, but it does not yet have a C program inmemory to execute.The Nios II IDE build flow is an easy-to-use graphical user interface (GUI) that automates buildand makefile management. The Nios II IDE integrates a text editor, debugger, the Nios II flashprogrammer, the Quartus II Programmer, and the Nios II C-to-Hardware (C2H) compiler GUI.
Theincluded example software application templates make it easy for new software programmers to getstarted quickly. In this section you will use the Nios II IDE to compile a simple C language examplesoftware program to run on the Nios II system on your development board. You will create a newsoftware project, build it, and run it on the target hardware. You will also edit the project, re-build it,and set up a debug session.1197.4 Create a hello_world Example ProjectIn this section you will create a new NIOS II C/C++ application project based on an installedexample.
To begin, perform the following steps in the NIOS II IDE:1. Return to the NIOS II IDE.Note: you can close the Quartus II Programmer or leave it open in the background if you want toreload the processor system onto your development board quickly.2. Select File > New > NIOS II C/C++ Application to open the New Project Wizard.3.
In the New Project wizard, make sure the following things:a. Select the Hello World project template.b. Give the project a name. (hello_world_0 is default name)c. Select the target hardware system’s PTF file that is located in the previously created hardwareproject directory, as shown in Figure 7-55.120Figure 7-55 Nios II IDE New Project Wizard5.
Click Finish. The NIOS II IDE creates the hello_world_0 project and returns to the NIOS IIC/C++ project perspective, as shown in Figure 7-56.121Figure 7-56 Nios II IDE C++ Project Perspective for hello_world_0When you create a new project, the NIOS II IDE creates two new projects in the NIOS II C/C++Projects tab:■ hello_world_0 is your C/C++ application project. This project contains the source and headerfiles for your application.■ hello_world_0_syslib is a system library that encapsulates the details of the Nios II systemhardware.Note: When you build the system library for the first time the NIOS II IDE automatically generatesfiles useful for software development, including:● Installed IP device drivers, including SOPC component device drivers for the NIOS II hardwaresystem● Newlib C library: a richly featured C library for the NIOS II processor.● NIOS II software packages which includes NIOS II hardware abstraction layer, NichestackTCP/IP Network stack, NIOS II host file system, NIOS II read-only zip file system and Micrium’sµC/OS-II realtime operating system (RTOS).● system.h: a header file that encapsulates your hardware system.122● alt_sys_init.c: an initialization file that initializes the devices in the system.● Hello_world_0.elf: an executable and linked format file for the application located inhello_world_0 folder under the Debug directory.7.5 Build and Run the ProgramIn this section you will build and run the program.To build the program, right-click the hello_world_0 project in the Nios II C/C++ Projects tab andselect Build Project.
The Build Project dialog box appears and the IDE begins compiling theproject. When compilation completes, a message ‘Build complete’ will appear in the Console tab, asshown in Figure 7-57.Figure 7-57 Nios II IDE hello_world_0 Build CompletedNote: If there appears in the console tab, an error, “region onchip_memory2 isfull(hello_world_0.elf section .text). Region needs to be XXX bytes larger.” , please right-clickhello_world_0 , select System Library Properties menu, then pop a window. In the System LibraryProperties window, select Small C Library, then click OK to close the window.
Rebuild the project.123After a successful compilation, right-click the hello_world_0 project, select Run As > NIOS IIHardware. The IDE will download the program to the target FPGA development board and beginexecution. When the target hardware begins executing the program, the message ’Hello from NiosII!’ will appear in the NIOS II IDE Console tab, as shown in Figure 7-58 for an example.Figure 7-58 Hello_World_0 Program OutputNow you have created, compiled, and run your first software program based on NIOS II. And youcan perform additional operations such as configuring the system properties, editing and re-buildingthe application, and debugging the source code.7.6 Edit and Re-Run the ProgramYou can modify the hello_world.c program file in the IDE, build it, and re-run the program toobserve your changes, as it executes on the target board.
In this section you will add code that willmake the green LEDs, on the DE0-Nano board, blink.Perform the following steps to modify and re-run the program:1. In the hello_world.c file, add the text shown in blue in the example below:#include <stdio.h>124#include "system.h"#include "altera_avalon_pio_regs.h"int main(){printf("Hello from Nios II!\n");int count = 0;int delay;while(1){IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, count & 0x01);delay = 0;while(delay < 2000000){delay++;}count++;}return 0;}2. Save the project.3. Recompile the project by right-clicking hello_world_0 in the NIOS II C/C++ Projects tab andchoosing Run > Run As > Nios II Hardware.Note: You do not need to build the project manually; the Nios II IDE automatically re-builds theprogram before downloading it to the FPGA.4.
Orient your development board so that you can observe LEDs blinking.1257.7 W hy the LED BlinksThe Nios II system description header file, system.h, contains the software definitions, name,locations, base addresses, and settings for all of the components in the Nios II hardware system. Thesystem.h file is located in the in the hello_world_0_syslib\Debug\system_description directory,and is shown in Figure 7-59.Figure 7-59 The system.h fileIf you look in the system.h file for the Nios II project example used in this tutorial, you will noticethe pio_led function. This function controls the LEDs. The Nios II processor controls the PIO ports(and thereby the LEDs) by reading and writing to the register map.
For the PIO, there are fourregisters: data, direction, interruptmask, and edgecapture. To turn the LED on and off, theapplication writes to the PIO’s data register.The PIO core has an associated software file altera_avalon_pio_regs.h. This file defines the core’sregister map, providing symbolic constants to access the low-level hardware. Thealtera_avalon_pio_regs.h file is located in the directory,altera\10.1\ip\sopc_builder_ip\altera_avalon_pio.When you include the altera_avalon_pio_regs.h file, several useful functions that manipulate thePIO core registers are available to your program. In particular, the macroIOWR_ALTERA_AVALON_PIO_DATA(base, data)126can write to the PIO data register, turning the LED on and off. The PIO is just one of many SOPCperipherals that you can use in a system. To learn about the PIO core and other embedded peripheralcores, refer to Quartus II Version 10.1 Handbook Volume 5: Embedded Peripherals.When developing your own designs, you can use the software functions and resources that areprovided with the Nios II HAL.
Refer to the Nios II Software Developer’s Handbook for extensivedocumentation on developing your own Nios II processor-based software applications.7.8 Debugging the ApplicationBefore you can debug a project in the NIOS II IDE, you need to create a debug configuration thatspecifies how to run the software.
To set up a debug configuration, perform the following steps:1. In the hello_world.c , double-click the front of the line where you would like to set breakpoint,as shown in Figure 7-60.Figure 7-60 Set Breakpoint2. To debug your application, right-click the application, hello_world_0, and select Debug as >Nios II Hardware.3. If the Confirm Perspective Switch message box appears, click Yes.After a moment, the main() function appears in the editor. A blue arrow next to the first line of codeindicates that execution stopped at that line.1275. Select Run > Resume to resume execution.When debugging a project in the Nios II IDE, you can pause, stop or single step the program, setbreakpoints, examine variables, and perform many other common debugging tasks.Note: To return to the Nios II C/C++ project perspective from the debug perspective, click the twoarrows >> in the top right corner of the GUI.7.9 Configure System Librar yIn this section you will learn how to configure some advanced options in the Nios II IDE.
Byperforming the following steps, you can change all the available settings:1. In the Nios II IDE, right-click hello_world_0 and select System Library Properties. TheProperties for hello_world_0_syslib dialog box opens.2. Click System Library in the tree on the left side. The System Library page contains settingsrelated to how the program interacts with the underlying hardware. The settings have names thatcorrespond to the targeted NIOS II hardware.3.















