n2sw Nii52017
n2sw Nii52017
n2sw Nii52017
The Nios II Software Build Tools (SBT) for Eclipse is a set of plugins based on the Eclipse framework and the Eclipse C/C++ development toolkit (CDT) plugins. The Nios II SBT for Eclipse provides a consistent development platform that works for all Nios II embedded processor systems. You can accomplish all Nios II software development tasks within Eclipse, including creating, editing, building, running, debugging, and profiling programs. This chapter familiarizes you with the features of the Nios II SBT for Eclipse. This chapter contains the following sections:
Getting Started with Nios II Software in Eclipse Makefiles and the Nios II SBT for Eclipse on page 29 Using the BSP Editor on page 212 Run Configurations in the SBT for Eclipse on page 220 Optimizing Project Build Time on page 221 Importing a Command-Line Project on page 222 Packaging a Library for Reuse on page 225 Creating a Software Package on page 226 Programming Flash in Altera Embedded Systems on page 229 Creating Memory Initialization Files on page 231 Managing Toolchains in Eclipse on page 235 Running a Nios II System with ModelSim on page 233 Eclipse Usage Notes on page 236
2011 Altera Corporation. All rights reserved. ALTERA, ARRIA, CYCLONE, HARDCOPY, MAX, MEGACORE, NIOS, QUARTUS and STRATIX are Reg. U.S. Pat. & Tm. Off. and/or trademarks of Altera Corporation in the U.S. and other countries. All other trademarks and service marks are the property of their respective holders as described at www.altera.com/common/legal.html. Altera warrants performance of its semiconductor products to current specifications in accordance with Alteras 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. 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.
22
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
This section guides you through the most fundamental operations in the Nios II SBT for Eclipse in a tutorial-like fashion. It shows how to create an application project for the Nios II processor, along with the board support package (BSP) project required to interface with your hardware. It also shows how to build the application and BSP projects in Eclipse, and how to run the software on an Altera development board.
Creating a Project
In the Nios II perspective, on the File menu, point to Nios II Application and BSP from Template. The Nios II Application and BSP from Template wizard appears. This wizard provides a quick way to create an application and BSP at the same time. Alternatively, you can create separate application, BSP and user library projects.
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
23
May 2011
Altera Corporation
24
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
On the second page, you specify the BSP to link with your application. You can create a new BSP for your application, or select an existing BSP. Creating a new BSP is often the simplest way to get a project running the first time. You optionally specify the name and location of the BSP. Specifying the BSP Project Name By default, if your application project name is <project>, the BSP is named <project>_bsp. You can type in a different name if you prefer. The SBT creates a directory with this name, to contain the BSP project files. BSP project names are subject to the same restrictions as application project names, as described in Specifying the Project Name. Specifying the BSP Project Location The BSP project location is the parent directory in which the SBT creates the folder. The default project location is the same as the default location for an application project. To place your BSP in a different folder, turn off Use default location, and specify the BSP location in the Project location box. Selecting an Existing BSP As an alternative to creating a BSP automatically from a template, you can associate your application project with a pre-existing BSP. Select Select an existing BSP project from your workspace, and select a BSP in the list. The Create and Import buttons to the right of the existing BSP list provide convenient ways to add BSPs to the list.
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
25
If the project has a dependency on another project, such as a BSP or a user library, the SBT builds the dependency project first. This feature allows you to build an application and its BSP with a single command.
f A Nios II instruction set simulator is available through the Lauterbach GmbH website (www.lauterbach.com).
May 2011
Altera Corporation
26
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
To run a software project, right-click the application project name, point to Run As, and click Nios II Hardware. This command carries out the following actions:
Creates a Nios II run configuration. For details about run configurations, refer to Run Configurations in the SBT for Eclipse on page 220. Builds the project executable. If all target files are up to date, nothing is built. Establishes communications with the target, and verifies that the FPGA is configured with the correct hardware design. Downloads the Executable and Linking Format File (.elf) to the target memory Starts execution at the .elf entry point.
Program output appears in the Nios II Console view. The Nios II Console view maintains a terminal I/O connection with a communication device connected to the Nios II processor in the hardware system, such as a JTAG UART. When the Nios II program writes to stdout or stderr, the Nios II Console view displays the text. The Nios II Console view can also accept character input from the host keyboard, which is sent to the processor and read as stdin. To disconnect the terminal from the target, click the Terminate icon in the Nios II Console view. Terminating only disconnects the host from the target. The target processor continues executing the program.
Creates a Nios II run configuration. For details about run configurations, refer to Run Configurations in the SBT for Eclipse on page 220. Builds the project executable. If all target files are up to date, nothing is built. If debugging on hardware, establishes communications with the target, and verifies that the FPGA is configured with the correct hardware design. Downloads the .elf to the target memory. Sets a breakpoint at the top of main(). Starts execution at the .elf entry point.
The Eclipse debugger with the Nios II plugins provides a Nios II perspective, allowing you to perform many common debugging tasks. Debugging a Nios II program with the Nios II plugins is generally the same as debugging any other C/C++ program with Eclipse and the CDT plugins. f For information about debugging with Eclipse and the CDT plugins, refer to the Eclipse help system.
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
27
The debugging tasks you can perform with the Nios II SBT for Eclipse include the following tasks:
Suspend (pause) Resume Terminate Step Into Step Over Step Return
Setting breakpoints and watchpoints Viewing disassembly Instruction stepping mode Displaying and changing the values of local and global variables in the following formats:
Displaying watch expressions Viewing and editing registers in the following formats:
Just as when running a program, Eclipse displays program output in the Console view of Eclipse. The Console view maintains a terminal I/O connection with a communication device connected to the Nios II processor in the hardware system, such as a JTAG UART. When the Nios II program writes to stdout or stderr, the Console view displays the text. The Console view can also accept character input from the host keyboard, which is sent to the processor and read as stdin. To disconnect the terminal from the target, click the Terminate icon in the Console view. Terminating only disconnects the host from the target. The target processor continues executing the program.
May 2011
Altera Corporation
28
Chapter 2: Getting Started with the Graphical User Interface Getting Started with Nios II Software in Eclipse
If your project was created with version 10.1 or earlier of the Nios II SBT, you must re-import it to create the Nios II launch configuration correctly.
Chapter 2: Getting Started with the Graphical User Interface Makefiles and the Nios II SBT for Eclipse
29
The operating system and version 1 You can select the operating system only at the time you create the BSP. To change operating systems, you must create a new BSP.
Additional arguments to the nios2-bsp script If you intend to run the project in the Nios II ModelSim simulation environment, use the Additional arguments parameter to specify the location of the testbench Simulation Package Descriptor File (.spd). The .spd file is located in the Quartus II project directory. Specify the path as follows:
--set QUARTUS_PROJECT_DIR=<relative path>
Altera recommends that you use a relative path name, to ensure that the location of your project is independent of the installation directory. f For details about nios2-bsp command arguments, refer to Details of BSP Creation in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook. After you have created the BSP, you have the following options for GUI-based BSP editing:
To access and modify basic BSP properties, right-click the BSP project, point to Properties and click Nios II BSP Properties. To modify parameters and settings in detail, use the Nios II BSP Editor, described in Using the BSP Editor.
May 2011
Altera Corporation
210
Chapter 2: Getting Started with the Graphical User Interface Makefiles and the Nios II SBT for Eclipse
You can examine and modify many makefile properties in the Nios II Application Properties or Nios II Library Properties dialog box. To open the dialog box, right-click the project, click Properties, and click Nios II Application Properties or Nios II Library Properties. Table 21 lists GUI actions that make changes to an application or user library makefile under Eclipse source management.
Table 21. Modifying a Makefile with Eclipse Source Management Modification Specifying the application or user library name Adding or removing source files Specifying a path to an associated BSP Specifying a path to an associated user library Enabling, disabling or modifying compiler options Where Modified Nios II Application Properties or Nios II Library Properties dialog box. Refer to the Eclipse help system. Project References dialog box. Project References dialog box. Nios II Application Properties or Nios II Library Properties dialog box.
After the SBT has created a makefile, you can modify the makefile in the following ways:
With the Nios II SBT for Eclipse, as described in Table 21. With Nios II SBT commands from the Nios II Command Shell.
When modifying a makefile, the SBT preserves any previous nonconflicting modifications, regardless how those modifications were made. After you modify a makefile with the Nios II Command Shell, in Eclipse you must right-click the project and click Update linked resource to keep the Eclipse project view in step with the makefile. When the Nios II SBT for Eclipse modifies a makefile, it locks the makefile to prevent corruption by other processes. You cannot edit the makefile from the command line until the SBT has removed the lock. If you want to exclude a resource (a file or a folder) from the Nios II makefile temporarily, without deleting it from the project, you can use the Remove from Nios II Build command. Right-click the resource and click Remove from Nios II Build. When a resource is excluded from the build, it does not appear in the makefile, and Eclipse ignores it. However, it is still visible in the Project Explorer, with a modified icon. To add the resource back into the build, right-click the resource and click Add to Nios II Build. 1 Do not use the Eclipse Exclude from build command. With Nios II software projects, you must use the Remove from Nios II Build and Add to Nios II Build commands instead.
Chapter 2: Getting Started with the Graphical User Interface Makefiles and the Nios II SBT for Eclipse
211
An Eclipse linked resource can be either a file or a folder. With a linked folder, all source files in the folder and its subfolders are included in the build. When you add a linked resource (file or folder) to your project, the SBT for Eclipse adds the file or folder to your makefile with an absolute path name. You might use a linked resource to refer to common source files in a fixed location. In this situation, you can move the project to a different directory without disturbing the common source file references. A linked resource appears with a modified icon (green dot) in the Project Explorer, to distinguish it from source files and folders that are part of the project. You can use the Eclipse debugger to step into a linked source file, exactly as if it were part of the project. You can reconfigure your project to refer to any linked resource either as an individual file, or through its parent folder. Right-click the linked resource and click Update Linked Resource. You can use the Remove from Nios II Build and Add to Nios II Build commands with linked resources. When a linked resource is excluded from the build, its icon is modified with a white dot. You can use Eclipse to create a path variable, defining the location of a linked resource. A path variable makes it easy to modify the location of one or more files in your project. f For information about working with path variables and creating linked resources, refer to the Eclipse help system.
Linked resources The Add to Nios II Build command The Remove from Nios II Build command
May 2011
Altera Corporation
212
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
Table 22 lists GUI actions that make changes to an application or user library makefile under user source management.
Table 22. Modifying a Makefile with User Source Management Modification Specifying the application or user library name Specifying a path to an associated BSP Specifying a path to an associated user library Enabling, disabling or modifying compiler options Where Modified Nios II Application Properties or Nios II Library Properties dialog box Project References dialog box Project References dialog box Nios II Application Properties or Nios II Library Properties dialog box
With user source management, the source files shown in the Eclipse Project Explorer view do not necessarily reflect the sources built by the makefile. To update the Project Explorer view to match the makefile, right-click the project and click Sync from Nios II Build.
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
213
Right-click an existing project, point to Nios II, and click BSP Editor. The editor loads the BSP Settings File (.bsp) associated with your project, and is ready to update it. On the Nios II menu, click Nios II BSP Editor. The editor starts without loading a .bsp file. Right-click an existing BSP project and click Properties. In the Properties dialog box, select Nios II BSP Properties, and click BSP Editor. The editor loads your .bsp file for update.
The Main tab The Software Packages tab The Drivers tab The Linker Script tab The Enable File Generation tab The Target BSP Directory tab
Each tab allows you to view and edit a particular aspect of the .bsp, along with relevant command line parameters and Tcl scripts. The settings that appear on the Main, Software Packages and Drivers tabs are the same as the settings you manipulate on the command line. f For detailed descriptions of settings defined for Altera-provided operating systems, software packages, and drivers, refer to the Nios II Software Build Tools Reference chapter of the Nios II Software Developers Handbook.
May 2011
Altera Corporation
214
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
The path to the .sopcinfo file specifying the target hardware The processor name The operating system and version 1 You cannot change the operating system in an existing BSP. You must create a new BSP based on the desired operating system.
The BSP target directorythe destination for files that the SBT copies and creates for your BSP. BSP settings
BSP settings appear in a tree structure. Settings are organized into Common and Advanced categories. Settings are further organized into functional groups. The available settings depend on the operating system. When you select a group of settings, the controls for those settings appear in the pane to the right of the tree. When you select a single setting, the pane shows the setting control, the full setting name, and the setting description. Software package and driver settings are presented separately, as described in The Software Packages Tab and The Drivers Tab.
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
215
General settings, operating system settings, and driver settings are presented separately, as described in The Main Tab and The Drivers Tab.
May 2011
Altera Corporation
216
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
Linker Section Mappings At the top of the Linker Script tab, the Linker Section Mappings table shows the mapping from linker sections to linker regions. You can edit the BSP linker section mappings using the following buttons located next to the linker section table:
AddAdds a linker section mapping to an existing linker region. The Add button opens the Add Section Mapping dialog box, where you specify a new section name and an existing linker region. RemoveRemoves a mapping from a linker section to a linker region. Restore DefaultsRestores the section mappings to the default configuration set up at the time of BSP creation.
Linker Regions At the bottom of the Linker Script tab, the Linker Memory Regions table shows all defined linker regions. Each row of the table shows one linker region, with its address range, memory device name, size, and offset into the selected memory device. You reassign a defined linker region to a different memory device by selecting a different device name in the Memory Device Name column. The Size and Offset columns are editable. You can also edit the list of linker regions using the following buttons located next to the linker region table:
AddAdds a linker region in unused space on any existing device. The Add button opens the Add Memory Region dialog box, where you specify the memory device, the new memory region name, the region size, and the regions offset from the device base address. RemoveRemoves a linker region definition. Removing a region frees the regions memory space to be used for other regions. Add Memory DeviceCreates a linker region representing a memory device that is outside the hardware system. The button launches the Add Memory Device dialog box, where you can specify the device name, memory size and base address. After you add the device, it appears in the linker region table, the Memory Device Usage Table dialog box, and the Memory Map dialog box. This functionality is equivalent to the add_memory_device Tcl command. 1 Ensure that you specify the correct base address and memory size. If the base address or size of an external memory changes, you must edit the BSP manually to match. The SBT does not automatically detect changes in external memory devices, even if you update the BSP by creating a new settings file.
f For information about add_memory_device and other SBT Tcl commands, refer to Software Build Tools Tcl Commands in the Nios II Software Build Tools Reference chapter of the Nios II Software Developers Handbook.
Restore Defaultsrestores the memory regions to the default configuration set up at the time of BSP creation.
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
217
Memory UsageOpens the Memory Device Usage Table. The Memory Device Usage Table allows you to view memory device usage by defined memory region. As memory regions are added, removed, and adjusted, each devices free memory, used memory, and percentage of available memory are updated. The rightmost column is a graphical representation of the devices usage, according to the memory regions assigned to it. Memory MapOpens the Memory Map dialog box. The memory map allows you to view a map of system memory in the processor address space. The Device table is a read-only reference showing memories in the hardware system that are mastered by the selected processor. Devices are listed in memory address order. To the right of the Device table is a graphical representation of the processors memory space, showing the locations of devices in the table. Gaps indicate unmapped address space. This representation is not to scale.
f For information about set_ignore_file and other SBT Tcl commands, refer to Software Build Tools Tcl Commands in the Nios II Software Build Tools Reference chapter of the Nios II Software Developers Handbook.
May 2011
Altera Corporation
218
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
Regenerate the BSP from the command line Recreate the BSP as a starting point for a new BSP Recreate the BSP on a different hardware platform Examine the Tcl script to improve your understanding of Tcl command usage
The exported Tcl script captures all BSP settings that you have changed since the previous time the BSP settings file was saved. If you export a Tcl script after creating a new BSP, the script captures all nondefault settings in the BSP. If you export a Tcl script after editing a pre-existing BSP, the script captures your changes from the current editing session. To export a Tcl script, in the Tools menu, click Export Tcl Script, and specify a filename and destination path. The file extension is .tcl. You can later run your exported script as a part of creating a new BSP. f To run a Tcl script during BSP creation, refer to Using a Tcl Script in BSP Creation. For details about default BSP settings, refer to Tcl Scripts for BSP Settings in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook.For information about recreating and regenerating BSPs, refer to Revising Your BSP in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook.
Chapter 2: Getting Started with the Graphical User Interface Using the BSP Editor
219
The .sopcinfo file defining the hardware platform. The CPU name of the targeted processor. The BSP type and version. 1 You can select the operating system only at the time you create the BSP. To change operating systems, you must create a new BSP.
The operating system version. The name of the BSP settings file. It is created with file extension .bsp. Absolute or relative path names in the BSP settings file. By default, relative paths are enabled for filenames in the BSP settings file. An optional Tcl script that you can run to supply additional settings.
Normally, you specify the path to your .sopcinfo file relative to the BSP directory. This enables you to move, copy and archive the hardware and software files together. If you browse to the .sopcinfo file, or specify an absolute path, the Nios II BSP Editor offers to convert your path to the relative form.
Recreate an existing BSP as a starting point for a new BSP Recreate a BSP on a different hardware platform Include custom settings common to a group of BSPs
The Tcl script can be created by hand, or exported from another BSP. f Exporting a Tcl Script describes how to create a Tcl script from an existing BSP. Refer to Tcl Scripts for BSP Settings in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook.
May 2011
Altera Corporation
220
Chapter 2: Getting Started with the Graphical User Interface Run Configurations in the SBT for Eclipse
f For complete information about updating and recreating BSPs, refer to Revising Your BSP in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook. If you recreate your BSP, you might find it helpful to capture your old BSP settings by exporting them to a Tcl script. You can edit the Tcl script to remove any settings that are incompatible with the new hardware design. f For details about exporting and using Tcl scripts, refer to Exporting a Tcl Script and Using a Tcl Script in BSP Creation. For a detailed discussion of updating BSPs for modified hardware systems, refer to Revising Your BSP in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook.
You can right-click an application, point to Run As, and click Run Configurations. You can right-click an application, point to Debug As, and click Debug Configurations.
Depending on which way you opened the run configuration dialog box, the title is either Run Configuration or Debug Configuration. However, both views show the same run configurations. 1 If your project was created with version 10.1 or earlier of the Nios II SBT, you must re-import it to create the Nios II launch configuration correctly. Each run configuration is presented on several tabs. This section describes each tab.
Chapter 2: Getting Started with the Graphical User Interface Optimizing Project Build Time
221
Specify the processor on which to execute the program (if the hardware design provides multiple processors) Specify the device to use for standard I/O Specify the expected location, timestamp and value of the system ID Specify the path to the Quartus II JTAG Debugging Information File (.jdi) Enable or disable profiling
The Nios II SBT for Eclipse sets these parameters to reasonable defaults. Do not modify them unless you have a clear understanding of their effects.
Select the cable, if more than one cable is available Allow software to run despite a system ID value or timestamp that differs from the hardware Reset the processor when the software is downloaded
The System ID Properties button allows you to examine the system ID and timestamp in both the .elf file and the hardware. This can be helpful when you need to analyze the cause of a system ID or timestamp mismatch.
Multi-Core Launches
If you have multiple run configurations, create an Eclipse launch group. Launch groups are an Eclipse feature that allows multiple run configurations to be started at the same time. You choose which run configurations are added to the group. You can use the launch group in any place where you can use a run configuration. f For details about Eclipse launch groups, refer to the Eclipse help system.
May 2011
Altera Corporation
222
Chapter 2: Getting Started with the Graphical User Interface Importing a Command-Line Project
Nios II software build performance is generally better on Linux platforms than on Windows platforms.
Command-line C/C++ application project Command-line BSP project Command-line user library project
You can edit, build, debug, and manage the settings of an imported project exactly the same way you edit, build, debug, and manage the settings of a project created in Nios II SBT for Eclipse. The Nios II SBT for Eclipse imports each type of project through the Import wizard. The Import wizard determines the kind of project you are importing, and configures it appropriately. You can continue to develop project code in your SBT project after importing the project into Eclipse. You can edit source files and rebuild the project, using the SBT either in Eclipse or on the command line. Nios II Integrated Development Environment (IDE) projects cannot be directly imported to the SBT for Eclipse. You must first convert the project for use with the SBT, by following to the procedures in Appendix A. Using the Nios II Integrated Development Environment in the Nios II Software Developers Handbook. f For information about creating projects with the command line, refer to the Getting Started from the Command Line chapter of the Nios II Software Developers Handbook.
Road Map
Importing and debugging a project typically involves several of the following tasks. You do not need to perform these tasks in this order, and you can repeat or omit some tasks, depending on your needs.
Import a command-line C/C++ application Import a supporting project Debug a command-line C/C++ application Edit command-line C/C++ application code
Chapter 2: Getting Started with the Graphical User Interface Importing a Command-Line Project
223
When importing a project, the SBT for Eclipse might make some minor changes to your makefile. If the makefile refers to a source file located outside the project directory tree, the SBT for Eclipse treats that file as a linked resource. However, it does not add or remove any source files to or from your makefile. When you import an application or user library project, the Nios II SBT for Eclipse allows you to choose Eclipse source management or user source management. Unless your project has an unusual directory structure, choose Eclipse source management, to allow the SBT for Eclipse to automatically maintain your list of source files. You debug and edit an imported project exactly the same way you debug and edit a project created in Eclipse.
May 2011
Altera Corporation
224
Chapter 2: Getting Started with the Graphical User Interface Importing a Command-Line Project
Chapter 2: Getting Started with the Graphical User Interface Packaging a Library for Reuse
225
May 2011
Altera Corporation
226
Chapter 2: Getting Started with the Graphical User Interface Creating a Software Package
4. In <example package>/EXAMPLE_SW_PACKAGE/lib, create a new C source file named example_sw_package.c. Insert the code shown in Example 22.
Example 22. Contents of example_sw_package.c
/* Example Software Package */ #include <stdio.h> #include "..\inc\example_sw_package.h" void example_sw_package(void) { printf ("Example Software Package. \n"); }
5. In <example package>, create a new Tcl script file named example_sw_package_sw.tcl. Insert the code shown in Example 23. 6. In the SBT for Eclipse, create a Nios II application and BSP project based on the Hello World template. Set the application project name to hello_example_sw_package.
Chapter 2: Getting Started with the Graphical User Interface Creating a Software Package
227
add_sw_property include_directory EXAMPLE_SW_PACKAGE/inc # This driver supports HAL & UCOSII BSP (OS) types add_sw_property supported_bsp_type HAL add_sw_property supported_bsp_type UCOSII # Add example software package system.h setting to the BSP: add_sw_setting quoted_string system_h_define \ example_sw_package_system_value EXAMPLE_SW_PACKAGE_SYSTEM_VALUE 1 \ "Example software package system value" # End of file
May 2011
Altera Corporation
228
Chapter 2: Getting Started with the Graphical User Interface Creating a Software Package
7. Create a new C file named hello_example_sw_package.c in the new application project. Insert the code shown in Example 24.
Example 24. Contents of hello_example_sw_package.c
/* * "Hello World" example. * * This example prints 'Hello from Nios II' to the STDOUT stream. It also * tests inclusion of a user software package. */ #include <stdio.h> #include "example_sw_package.h" int main() { printf("Hello from Nios II!\n"); example_sw_package(); return 0; }
8. Delete hello_world.c from the hello_example_sw_package application project. 9. In the File menu, point to New and click Nios II Library 10. Set the project name to example_sw_package_library. 11. For Location, browse to <example package>\EXAMPLE_SW_PACKAGE\lib 1 Building the library here is required, because the resulting .a is referenced here by example_sw_package_sw.tcl.
12. Click Finish. 13. Build the example_sw_package_library project to create the libexample_sw_package_library.a library archive file. 14. Right-click the BSP project, point to Nios II, and click BSP Editor to open the BSP Editor. 15. In the Software Packages tab, find example_sw_package in the software package table, and enable it. If there are any errors in a software package's *_sw.tcl file, such as an incorrect path that causes a file to not be found, the software package does not appear in the BSP Editor. 16. Click the Generate button to regenerate the BSP. On the File menu, click Save to save your changes to settings.bsp. 17. In the File menu, click Exit to exit the BSP Editor. 18. Build the hello_example_sw_package_bsp BSP project. 19. Build the hello_example_sw_package application project. hello_example_sw_package.elf is ready to download and execute.
Chapter 2: Getting Started with the Graphical User Interface Programming Flash in Altera Embedded Systems
229
The Nios II SBT for Eclipse provides flash programmer utilities to help you manage and program the contents of flash memory. The flash programmer allows you to program any combination of software, hardware, and binary data into flash memory in one operation.
Browse to a BSP settings file. The flash programmer finds the .sopcinfo file associated with the BSP. Browse directly to a .sopcinfo file.
Once you have identified a hardware configuration, details about the target hardware appear at the top of the Nios II flash programmer screen. Also at the top of the Nios II flash programmer screen is the Hardware Connections button, which opens the Hardware Connections dialog box. This dialog box allows you to select a download cable, and control system ID behavior, as described in The Target Connection Tab on page 221.
May 2011
Altera Corporation
230
Chapter 2: Getting Started with the Graphical User Interface Programming Flash in Altera Embedded Systems
Chapter 2: Getting Started with the Graphical User Interface Creating Memory Initialization Files
231
Staging Directories
Through the Staging Directories dialog box, you control where the flash programmer creates its script and .flash-settings files.
Generate Files
If you disable this option, the flash programmer does not generate programming files, but programs files already present in the directory. You might use this feature to reprogram a set of files that you have previously created.
Program Files
If you disable this option, the flash programmer generates the programming files and the script, but does not program flash. You can use the files later to program flash by turning off the Generate Files option.
May 2011
Altera Corporation
232
Chapter 2: Getting Started with the Graphical User Interface Creating Memory Initialization Files
Creating a Hexadecimal (Intel-Format) File (.hex) is a necessary intermediate step in creating such a .sof file. The Nios II SBT for Eclipse can create .hex files and other memory initialization formats. To generate correct memory initialization files, the Nios II SBT needs details about the physical memory configuration and the types of files required. Typically, this information is specified when the hardware system is generated. 1 If your system contains a user-defined memory, you must specify these details manually. For information, see Memory Initialization Files for User-Defined Memories. To generate memory initialization files, perform the following steps: 1. Right-click the application project. 2. Point to Make targets and click Build to open the Make Targets dialog box. 3. Select mem_init_generate. 4. Click Build. The makefile generates a separate file (or files) for each memory device. It also generates a Quartus II IP File (.qip). The .qip file tells the Quartus II software where to find the initialization files. 5. Add the .qip file to your Quartus II project. 6. Recompile your Quartus II project. If your hardware system was generated with SOPC Builder, you can alternatively use the legacy method to generate memory initialization files. However, this method is not preferred. To generate memory initialization files by the legacy method, perform the following steps: 1. Right-click the application project. 2. Point to Make targets and click Build to open the Make Targets dialog box. 3. Select mem_init_install. 4. Click Build. The makefile generates a separate file (or files) for each memory device. The makefile inserts the memory initialization files directly in the Quartus II project directory for you. 5. Recompile your Quartus II project. f For more information about creating memory initialization files, refer to Common BSP Tasks in the Nios II Software Build Tools chapter of the Nios II Software Developers Handbook.
Chapter 2: Getting Started with the Graphical User Interface Running a Nios II System with ModelSim
233
You specify memory device information when you add the user-defined memory device to your BSP. The device information persists in the BSP settings file, allowing you to regenerate memory initialization files at any time, exactly as if the memory device were part of the hardware system. Specify the memory device information in the Advanced tab of the Add Memory Device dialog box. Settings in this tab control makefile variables in mem_init.mk. On the Advanced tab, you can control the following memory characteristics:
The physical memory width. The devices name in the hardware system. The memory initialization file parameter name. Every memory device can have an HDL parameter specifying the name of the initialization file. The Nios II ModelSim launch configuration overrides the HDL parameter to specify the memory initialization filename. When available, this method is preferred for setting the memory initialization filename. 1 For further information about this parameter, refer to Embedded Software Assignments in the Publishing Component Information to Embedded Software chapter of the Nios II Software Developers Handbook.
The Mem init filename parameter can be used in Nios II systems as an alternative method of specifying the memory initialization filename. The Mem init filename parameter directly overrides any filename specified in the HDL. Connectivity to processor master ports. These parameters are used when creating the linker script. The memory type: volatile, CFI flash or EPCS flash. Byte lanes.
You can also enable and disable generation of the following memory initialization file types:
May 2011
Altera Corporation
234
Chapter 2: Getting Started with the Graphical User Interface Running a Nios II System with ModelSim
Chapter 2: Getting Started with the Graphical User Interface Managing Toolchains in Eclipse
235
4. Open the run configuration you previously created. Click Run. The Nios II SBT for Eclipse performs a make mem_init_generate command to create memory initialization files, and launches ModelSim. 5. At the ModelSim command prompt, type ldr. 1 When you create the launch configuration, you might see the following error message: SEVERE: The Quartus II project location has not been set in the ELF section. You can manually override this setting in the launch configurations ELF file Advanced properties page. To correct this error, perform the following steps: 1. Click the Advanced button. 2. In the Quartus II project directory box, browse to locate the directory containing your Quartus II project .spd file. 3. Click Close. To avoid this error condition, specify the Quartus II project directory when you create your application project, as described in Creating a Simple BSP on page 28.
In the Windows operating system, select MinGW Nios II GCC 4 In the Linux operating system, select Linux Nios II GCC 4
After you select the toolchain, the SBT for Eclipse continues to use that toolchain for your project unless you change it again. If you move the project to a different host platform, you must manually change to the appropriate toolchain for the new host platform. For example, if you move a GCC 4 project from a Windows host to a Linux host, use the Properties dialog box to select Linux Nios II GCC 4.
May 2011
Altera Corporation
236
Chapter 2: Getting Started with the Graphical User Interface Eclipse Usage Notes
You cannot link Nios II GCC 3 projects with Nios II GCC 4 projects. Your application, library and BSP projects must all use the same Nios II GCC toolchain. If you switch between Nios II GCC 3 and Nios II GCC 4, make sure you run make clean on your application, library and BSP projects before rebuilding. When importing a GCC 3 BSP, such as a project created with version 9.1 SP2 or earlier, to version 10.0 SBT for Eclipse using the GCC 4 toolchain, after importing the BSP, regenerate the makefile. If you do not follow these rules, you might see the following error:
make[1]: *** No rule to make target `/cygdrive/c/.../bsp/alt_sys_init.c', needed by 'all'. Stop. make: *** [../bsp/-recurs-make-lib] Error 2
The GCC 3 toolchain is an optional feature. It is available only if you enable Legacy Package: Nios II IDE / GCC3 Toolchain / C2H Compiler when you install the Altera Complete Design Suite.
f For general information about the GCC toolchains, refer to Altera-Provided Development Tools in the Nios II Software Build Tools chapter in the Nios II Software Developers Handbook. For information about selecting the toolchain on the command line, refer to the Getting Started from the Command Line chapter of the Nios II Software Developers Handbook. For detailed information about installing the Altera Complete Design Suite, refer to the Altera Software Installation and Licensing Manual.
The name of the target .elf file (application project only) The library name (library project only) A list of symbols to be defined in the makefile A list of symbols to be undefined in the makefile A list of assembler flags Warning level flags A list of user flags
Chapter 2: Getting Started with the Graphical User Interface Eclipse Usage Notes
237
Generation of debug symbols Compiler optimization level Generation of object dump file (application project only) Source file management Path to associated BSP (required for application, optional for library)
Disable Nios II Console view Ignore mismatched system ID Ignore mismatched system timestamp Download ELF to selected target system Start processor Reset the selected target system
May 2011
Altera Corporation
238
Chapter 2: Getting Started with the Graphical User Interface Eclipse Usage Notes
3. Right-click the project and click Refresh. If you neglect to refresh the project, you might see the following error message when you attempt to build it:
Resource <original_project_name> is out of sync with the system
You must start the SBT for Eclipse from the command line in both the Linux and Windows operating systems, to set up the correct shell environment. 3. From the Eclipse Run menu, point to External Tools, and click External Tools Configurations. 4. Create a new tools configuration, or open an existing tools configuration. 5. On the Main tab, set Location and Argument as shown in Table 23.
Table 23. Location and Argument to Run Shell Script from Eclipse Platform Location Windows ${env_var:QUARTUS_ROOTDIR}\bin\cygwin\bin\sh.exe Linux ${env_var:SOPC_KIT_NIOS2}/bin/<script name> Argument -c "<script name> <script args>" <script args>
For example, to run the command elf2hex --help, set Location and Argument as shown in Table 24.
Table 24. Location and Argument to Run elf2hex --help from Eclipse Platform Location Windows ${env_var:QUARTUS_ROOTDIR}\bin\cygwin\bin\sh.exe Linux ${env_var:SOPC_KIT_NIOS2}/bin/elf2hex Argument -c "elf2hex --help" --help
6. On the Build tab, ensure that Build before launch and its related options are set appropriately. By default, a new tools configuration builds all projects in your workspace before executing the command. This might not be the desired behavior. 7. Click Run. The command executes in the Nios II Command Shell, and the command output appears in the Eclipse Console tab.
Chapter 2: Getting Started with the Graphical User Interface Eclipse Usage Notes
239
CDT Limitations
The features listed in the left column of Table 25 are supported by the Eclipse CDT plugins, but are not supported by Nios II plugins. The right column lists alternative features supported by the Nios II plugins.
Table 25. Eclipse CDT Features Not Supported by the Nios II Plugins (Part 1 of 2) Unsupported CDT Feature New Project Wizard C/C++
Nios II Application Nios II Application and BSP from Template Nios II Board Support Package Nios II Library
Convert to a C/C++ Project Source Folder Build configurations Right-click project and point to Build Configurations Debugger tab
The Nios II plugins only support a single build configuration. This feature is supported only at the top of main().
Stop on startup
Exclude from Build (from version 10.0 onwards) Right-click source files C/C++ Build
Use Remove from Nios II Build and Add to Nios II Build. Project Properties
Builder Settings
By default, the Nios II SBT generates makefiles automatically. The build location is determined with the Nios II Application Properties or Nios II BSP Properties dialog box.
Behavior
May 2011
Altera Corporation
240
Chapter 2: Getting Started with the Graphical User Interface Eclipse Usage Notes
Table 25. Eclipse CDT Features Not Supported by the Nios II Plugins (Part 2 of 2) Unsupported CDT Feature
Current builder Used tools To change the toolchain, use the Current tool chain option Project Properties, continued
C/C++ General
Enable project specific settings Documentation tool comments Documentation File Types Indexer
The Nios II plugins only support a single build configuration. Use Nios II Application Properties and Nios II Application Paths Window Preferences
C/C++
Build scope Build project configurations Build Variables Environment File Types Indexer
Chapter 2: Getting Started with the Graphical User Interface Document Revision History
241
Changes Introduction of Qsys system integration tool impacts ModelSim flow Launch configuration change requires re-importation of existing projects Using variables to link to external resources The GCC 3 toolchain is an optional feature Minor corrections to Table 25 on page 254 Do not mix versions of GCC. How to create and use a library archive file (.a). How to create a software package. Describe Eclipse launch groups. Removed Referenced Documents section. Document how to import and use projects with user-managed source files. Document how to import and use projects with linked resources. Document Remove from Nios II Build command. Update BSP Editor documentation.
May 2011
11.0.0
February 2011
10.1.0
July 2010
10.0.0
Document Add Memory Device command. Document Enable File Generation tab.
November 2009
9.1.0
Initial release.
May 2011
Altera Corporation
242
Chapter 2: Getting Started with the Graphical User Interface Document Revision History