Embedded Design Handbook

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

6.2.3.3. Building Software Design

  1. Open the Nios® II Software Build Tools for Eclipse from Tools menu.
  2. Create a workspace for your software project.
  3. Click on File>New> Nios® II Application and BSP from Template to create the application and BSP project. You can also choose to use the existing available template in your design.
  4. Entering the SOPC Information File Name automatically detects the processor which is available in your design.
  5. Enter a name for your project and click Finish. This step creates your application project with the linked BSP.
  6. Select the Hello World template from the project template.
  7. Modify the hello_world.c to instruct the Nios® II processor to print sentences via JtagUart and write data to PIO for blinking the LED.
    For example:
    #include <stdio.h>
    #include "system.h"
    #include <io.h>
    #include <unistd.h>
    #include "altera_avalon_pio_regs.h"
    
    int main()
    {
      printf("Hello from Debug Test!\n");
    
      //blink the LED for two times
      for(int i=0;i<2;i++)
      {
    	  IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x1);
    	  usleep(1000000);
    	  IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x2);
    	  usleep(1000000);
    	  IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x4);
    	  usleep(1000000);
    	  IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x8);
    	  usleep(1000000);
      }
      
      printf("Does all the breakpoint is detected by debugger?\n");
      printf("Program ended!\n");
    
      return 0;
    }
    
  8. Right click on the application project, then click Nios II>BSP editor.
    1. Under the Main tab of the editor, click on linker and match the settings as shown below:
      Figure 248. Linker Settings in Main Tab
    2. Under the Linker Script tab, change the .text section to onchip_flash_data as shown below:
      Figure 249. Linker Section Mappings
  9. Right click on the application project, then click Build Project. After a successful built, the .elf file is created in the application folder.
  10. Right click on the application project, then click Make Target>Build>mem_init_generate to create the .hex file.