DE0_Nano_User_Manual_v1.9 (1162589), страница 9
Текст из файла (страница 9)
(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. In the Linker Script box, observe which memory has been assigned for Programmemory(.text), Read-only data memory(.rodata), Read/write data memory(.rwdata), Heapmemory, and Stack memory, see Figure 7-61.
These settings determine which memory is used tostore the compiled executable program. You can also specify which interface you want to use forstdio , stdin, and stderr. You can also add and configure an RTOS for your application and configurebuild options to support C++, reduced device drivers, etc.4. Select onchip_memory2 for all the memory options in the Linker Script box, as shown inFigure 7-61.128Figure 7-61 Configuring System Library Properties5. Click OK to close the Properties for hello_world_0_syslib dialog box and return to the IDEworkbench.Note: If you make changes to the system properties you must rebuild your project. To rebuild,right-click the hello_world_0 project in the Nios II C/C++ Projects tab and select Build Project.129Chapter 8DE0DE0-Nano Demonstrations8.1 System RequirementsMake sure Quartus II and NIOS II are installed on your PC.8.2 Breathing LEDsThis demonstration shows how to use the FPGA to control the luminance of the LEDs by means ofpulse-width modulation (PWM) scheme.