DE0-Nano | NiosII untethered

Introduction

Here is a quick step-by-step tutorial for creating a NiosII soft processor on the 
Altera DE0-Nano board and uploading it to the configuration device so it will run independently without a PC.

I am writing this because I am new to the whole FPGA world and got stuck several times doing this myself. All the necessary information needed to do this is out there on the web, mostly on the Altera homepage / forums but it is widespread and can be confusing at times.


I am heavily borrowing from the tutorials provided in the DE0-Nano user manual. Specifically chapter 7, Creating a Nios II Project.
So if you find my steps a bit too rushed and need more detail and screen shots have a look there. (There is a link at the bottom of this page)


Prerequisites for this tutorial (Other software versions will work just as well but the steps might be slightly different):
  • Altera Quartus II 11.0sp1
  • Altera Nios II EDS 11.0sp1

This is what we are going to build:


Hardware setup

Building the processor

  • start quartus11.0sp1
  • file>new project wizard
    1/5: create new folder NiosTut, select as project dir
    name of project: mynios2
    skip 2/5
    3/5: select Family: CycloneIV E
    select device EP4CE22F17C6
    click Finish
  • select Tools>SOPC Builder
  • Name system: DE0_NANO_SOPC
    select verilog
  • rename clk_0 to clk_50
  • add NiosII processor (Procesors>Nios II Processor)
    select NiosII/E variant and click Finish
  • rename cpu_0  to cpu
  • add a JTAG-UART (Interface Protocols>Serial>JTAG UART)
    all defaults, click Finish
  • rename jtag_uart_0 to jtag_uart
  • add on-chip ram  (Memories and Memory Controllers>On-Chip>On-Chip Memory RAM or ROM)
    set total memory size to 26000
    click Finish
  • rename onchip_memory2_0 to onchip_memory2
  • add EPCS Serial Flash Controller (Memories and Memory Controllers>External Memory Interfaces>Flash>EPCS Serial Flash Controller)
    click Finish (defaults)
  • rename epcs_flash_controller_0 to epcs_flash_controller
  • right-click cpu and select edit...
    set reset vector to epcs_flash_controller, offset 0x0
    set exception vector to  onchip_memory2, offset 0x20
    click Finish
  • add an output port (Peripherals>Microcontroller Peripherals>PIO (Parallel IO) )
    click Finish (Defaults)
  • rename pio_0 to pio_led
  • Select System > Assign Base Addresses 
  • Select File>Refresh System
  • click Generate
    and save the file as DE0_NANO_SOPC.sopc
        >> Info: System generation was successful.
    click Exit

Instanciating the hardware

  • File > New...
    create a new Block Diagram/Schematic file (.bdf)
  • in the schematic view right click > Insert > Insert Symbol
  • under Project select the DE0_NANO_SOPC component
  • click Ok and place the Nios symbol on the schematic
  • right click the newly created DE0_NANO_SOPC symbol and select > Generate Pins For Symbol Ports
  • save the file as mynios2.bdf
  • it will show up in the project navigator under Files
  • select Processing > Start Compilation
    wait........
    >> Full compilation was successful (78 warnings)
  • select Assignments > Pin Planner
    and connect the following signals to these pins

clk_50 R8 
data0_to_the_epcs_flash_controllerH2
dclk_from_the_epcs_flash_controllerH1
sce_from_the_epcs_flash_controllerD2
sdo_from_the_epcs_flash_controller C1
out_port_from_the_pio_led[7] L3
out_port_from_the_pio_led[6] B1
out_port_from_the_pio_led[5] F3
out_port_from_the_pio_led[4] D1
out_port_from_the_pio_led[3] A11
out_port_from_the_pio_led[2] B13
out_port_from_the_pio_led[1] A13
out_port_from_the_pio_led[0] A15
reset_nleave unconnected



  • recompile (Processing > Start Compilation)
    >>Successful (77 wanrings)
  • If after this compilation you get errors like this:
    Error: Can't place multiple pins assigned to pin location Pin_C1 (IOPAD_X0_Y27_N7)
    ....

    go to the menu Assignments->Device...
    click on "Device and Pin Options..."
    and under Dual Purpose Pins switch the pins DCLK, Data[0], Data[1] and FLASH_nCE to "Use as regular IOs"
  • While you are in the Assignments->Device dialog you can use the opportunity to switch the pin voltage standard to 3,3LVTTL
    This can be found under Device and Pin options > Voltage > Default I/O standard
  • recompile
  • This creates a new file called mynios2.sof in the project folder.

Initial upload

  • Now, the next steps depend on tools that talk to a Nios core over the JTAG cable. For this reason we need to upload our core to the board at least once (even though it won't do much without a program).
  • If for some reason you already got a Nios running on it you can skip right to Software setup.
  • select from the menu Tools>Programmer
  • If there are already files loaded from a previous session, remove them by selecting File>New
  • Add the mynios2.sof file you just built.
  • Press Start to upload it. (If the Start button is greyed out you might have to select the USB-Blaster cable in the Hardware Setup Dialog)


Software setup

Hello World (Blinking Led)

  • Open NiosII EDS 11.0sp1 Software Build Tools For Eclipse
    choose your project folder as the workspace
    when Eclipse opens up the workspace should be empty
  • File > New > Nios II Application and Bsp From Template
    SOPC Information File ... browse to your project folder and select the file DE0_NANO_SOPC.sopcinfo
    the cpu name should be auto selected for you
    Select the Hello World template
    call the Project "hello_world"
    click Finish
  • 2 new projects are created, the hello_world project containing your code and the hello_world_BSP, a support library for your custom hardware
  • before hitting compile, right click the hello_world_BSP project and select NiosII > BSP Editor
    on the Main tab under hal check enable_small_c_library (otherwise our little program won't fit into our even smaller ram)
    hit Generate and then Exit
  • Right click the hello_world project and select Build Project
  • Right click the hello_world project and select Run as Hardware
    It will upload the program and print "Hello From Nios II!"
  • Note, if at this point the Run Configurations window pops up, you either don't have a nios core currently running on the board or something is wrong with it. Go back to the Hardware setup section above that describes how to initially upload the nios core using the Quartus II programmer.
  • Now this following part is optional but we are going to blink an LED on the board. To truely prove that our board runs standalone (not connected to a computer) it would be great to just connect a battery to it. Without a JTag debug console, the easiest way to see if the program is running is to successfully blink an LED. If you don't care skip to Making it stick.
  • add the following lines to the generated file hello_world.c.

#include <stdio.h>
#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 < 200000)
            delay++;
        count++;
    }

  return 0;
}

  • save the file and rebuild the project. Then run it again as hardware. LED0 on the board should now blink.

Making it stick!

  • If this all works it's time to push the whole thing into the flash to make it independent from the PC.
  • From the Eclipse menu select NiosII > Flash Programmer
  • Select File > New
    Use the default: Get flash programmer system details from BSP Settings file
    Browse to the settings.bsp file (it's in the hello_world_bsp folder)
    everything else will be auto-detected for you.
    click OK
  • You'll get an error message in the Problems tab
  • click on Connections
    tick Ignore mismatched system ID
    tick Ignore mismatched system timestamp
    (if you have some patience left later you should add a SystemID ip core to the nios!)
    click Close
  • click add File, browse to your NiosTut hardware folder and select the file myfirst_niosii.sof
  • click add again and select the file hello_world.elf in your hello_world folder
  • click Start
    If everything is okay the Nios system and your program will be uploaded to the EPCS flash.
    Once this is done, unplug and re-plug the board. The LED should start to blink.
    The program will be uploaded and started on power up.

Please let me know if something in this tutorial is horribly wrong or I am missing something important.
Some of the steps above can be taken care of by the DE0-Nano project builder which comes with the board but I found it helpful to click around inside Quartus and navigate through the various dialogs to get a quicker understanding of it's inner workings.


Useful links regarding this tutorial

DE0-Nano User Manual:
www.terasic.com:

CycloneIV E Pinout file:
www.altera.com:
Embedded Peripherals IP User Guide:
www.altera.com:
Č
ą
ď
Florian Hu,
May 15, 2012, 5:13 AM
Comments