This guide will show you how to use the Nios II CLI, and create/run Nios II C projects on Windows without WSL or Eclipse.
- Windows (duh)
- Quartus Prime Lite (if you have a version other than
20.1
you will need to modify one of the utility scripts, see "Gotchas" below) - A
bash
terminal
- Clone this repository (TO A PATH THAT CONTAINS NO SPACES - See "Gotchas" below)
- Add the
Utilities
directory to%PATH
- When you want to start a Nios II CLI session, open a Bash terminal and run
nios2-cli
-
You may have to modify the
Utilities/nios2-cli
script if your Nios II installation directory is notC:\intelFPGA_lite\20.1\nios2eds\
. See lines 3-4 of thenios2-cli
script. -
A lot of the Nios II tools can't handle whitespace in paths because whoever made them wants to watch the world burn. This means you must install the utility scripts and keep all your projects in a directory that contains no spaces in its full path.
-
Whenever specifying a directory path in a command, it is best to always use relative paths to avoid compatibility issues between Linux and Windows path formats.
You will need a .sopcinfo
file that describes your Nios II system. This is produced by Platform Designer (Qsys).
-
In a Nios II CLI session, run
nios2-bsp {bspType} {bspDir} {sopcFile}
wherebspType
ishal
orucosii
depending on if you are running on bare metal or if you want to use μC/OS-II (respectively),bspDir
is the directory to create the BSP in, andsopcFile
is the path to your.sopcinfo
file. -
Then run
nios2-fixbsp {bspDir}
, wherebspDir
is the directory in which you created the BSP in the previous step. This fixes a bug in the default makefile, I'm not sure why the bug happens.
I recommend writing a bash script that will perform these two steps for you, as you do not want to check the BSP into VCS.
The key step to either of these tasks is to generate the Makefile
. The Makefile
is very big, however, so I recommend not checking it into VCS and instead writing a script that will generate it
Create a bash script that runs nios2-app-generate-makefile --bsp-dir {bspDir} --src-dir .
where bspDir
is your BSP directory. This will add all files in the current directory to the Makefile
. To specify additional source directories, add --src-dir {dir}
or --src-files {file1} {file2}
command line flags.
Run it in a Nios II CLI session in the project directory.
You will need a BSP. See above for how to create a BSP.
-
Create a project directory
-
The examples are located in
{nios2dir}/examples/software/
wherenios2dir
is your Nios II installation directory. Usually this isC:\intelFPGA_lite\{version}\nios2eds
, but yours might be different. -
Each example has a directory. Choose an example, copy its contents to your project directory and delete
template.xml
. -
Now follow the instructions for creating a new project.
In a Nios II CLI session in your project directory, run make
. This will generate an .elf
file in the project directory.
In a Nios II CLI session, run nios2-download -g {elfFile}
where elfFile
is the ELF file generated by compiling the project.
In a Nios II CLI session, run nios2-terminal
.
Normally, Eclipse IDE is required to use the Nios II tools. However, I hate loathe detest DESPISE Eclipse. Therefore I have developed the following CLI methods to avoid using it.
You're supposed to install WSL. However, I don't want to. So I won't. This guide shows you how to get the tools working without WSL.
The normal start menu shortcut to start a Nios II CLI session won't work - it will complain that WSL isn't installed.
There is a script in the Utilities
directory that initializes a Nios II CLI session in the current Bash window. You must add the Utilities
directory to PATH so that you can just run nios2-cli
in any Bash window to start a Nios II CLI session. This also makes the other included utilities available.
You can also run any Nios II command directly using the script. For example, to start a Nios II terminal, run nios2-cli nios2-terminal
outside of a Nios II CLI session, and it will start a session and run the command nios2-terminal
. When the terminal session ends, the script will terminate, instead of leaving you in a Nios II CLI session.