Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

5.2.2.2.2. Application

In the Nios® II SBT window, select either:
  • File > New > Nios® II Application to develop a Nios® II application.

    or

  • File > New > Nios® II Application and BSP from Template to create a template to use for the Nios® II application.

BSP Editor Settings

You must edit the BSP settings according to the selected Nios® II processor boot options.
  1. In the Nios® II SBT tool, right click on your BSP project in the Project Explorer window. Select Nios® II > BSP Editor... to open the Nios® II BSP Editor.
  2. In Nios® II BSP Editor, expand into Advanced.hal.linker under Settings in Main tab.
  3. If the exception vector memory is set to OCRAM or External RAM, then enable the following:
    • allow_code_at_reset
    • enable_alt_load
    • enable_alt_load_copy_rodata
    • enable_alt_load_copy_rwdata
    • enable_alt_load_copy_exceptions
    Figure 60. Advanced.hal.linker SettingsIf exception vector memory is set to OCRAM or External RAM.
  4. If the exception vector memory is set to On-chip Flash, then enable the following:
    • allow_code_at_reset
    • enable_alt_load
    • enable_alt_load_copy_rodata
    • enable_alt_load_copy_rwdata
    Figure 61. Advanced.hal.linker SettingsIf exception vector memory is set to On-Chip Flash.
  5. Click on the Linker Script tab in the Nios® II BSP Editor.
  6. Set the .text region in the Linker Section Name to the On-chip Flash in the Linker Region Name. Set the rest of the regions in the Linker Section Name list to the On-chip Memory (OCRAM) or external RAM.
    Figure 62. Linker Region Settings

HEX File Generation

  1. After creating the Nios® II application, right click on the project in Project Explorer and select Build Project. An *.elf file is created under the project folder.
  2. Again right click on your project and click Make Targets -> Build…, the Make Targets dialog box appears. You can also press shift + F9 to trigger the Make Target dialog box.
  3. Select mem_init_generate.
  4. Click Build to generate the HEX file.
    Figure 63. Selecting mem_init_generate in Make Targets
  5. The “mem_init_generate” macro will create two HEX files; <on_chip_ram.hex> and <on_chip_flash.hex>.
    Note:
    • The mem_init_generate target also generates a Intel® Quartus® Prime IP file (meminit.qip). Intel® Quartus® Prime software will refer to the meminit.qip for the location of the initialization files.
    • All these files can be found under the "<project_folder>/software/<application_name>/mem_init" folder.
  6. Recompile your project in Intel® Quartus® Prime software if you check Initialize memory content option in On-Chip Flash IP. This is to include the software data (.HEX) into the SOF file.