You've got a badge, you want to write and run C to run on the RiscV. This is a guide for you.
The toolchain requires a bash shell - it won't work with CMD. We'll use the bash shell that comes with Git for Windows. Other options include installing Windows Subsystem for Linux or using a Mac. However, the git bash shell is straight forward and Just Works.
-
Download git for Windows from git-scm.com. Choose the "64-bit Git for Windows Setup" option.
-
Run the installer. There are a lot of screens for options. You can accept the defaults for everything.
-
Run the Git bash shell. (I generally press the Win key once to bring up the menu, then type 'bash', which brings up the Git Bash option, and the press enter.)
-
You'll be at a command prompt like this:
Yourname@SOMENAME MINGW64 ~
$
- Run:
$ mkdir hadbadge
-
Download the precompiled toolchain from xobs/ecp5-toolchain. You want the file named something like
ecp5-toolchain-windows-v1.6.2.zip
. -
Unzip the toolchain to
C:\Users\Yourname\hadbadge
. You should now have a directory namedC:\Users\Yourname\hadbadge\ecp5-toolchain-windows-v1.6.2
.
-
From the bash shell, cd to
~/hadbadge
. -
Clone the repo
$ git clone https://github.com/Spritetm/hadbadge2019_fpgasoc.git
- If you plan on writing verilog or recompiling the SoC, you must also get the submodules:
$ cd hadbadge2019_fpgasoc
$ git submodule update --init --recursive
Make a .bashrc
file in your home directory (i.e. ~/.bashrc
). The file will
set these environment variables and your path. If the .bashrc file already
exists, just add this to the end.
(If the toolchain version changes, don't forget to update the version number in the path here too!)
export APPSSDK_DIR=~/hadbadge/hadbadge2019_fpgasoc/apps-sdk
export RISCV_TOOLCHAIN_PATH=~/hadbadge/ecp5-toolchain-windows-v1.6.2/bin
export PATH=$RISCV_TOOLCHAIN_PATH:$PATH
Now restart your Git Bash shell to pick up the changes. Test that you have the paths set correctly by attempting to run nextpnr:
$ nextpnr-ecp5.exe
This should output a list of command-line options. If it doesn't find the nextpnr-ecp5 command, carefully check directory names in the path.
Nearly there!
- Copy the app-helloworld to use as a template for your own code.
$ cd ~/hadbadge
$ cp -r hadbadge2019_fpgasoc/app-helloworld myapp
- Edit the Makefile at
~/hadbadge/myapp/Makefile
. The most important thing to change is to changeAPPNAME
:
APPNAME = myapp
- Edit
main.c
. Find the line that says:
fprintf(f, "Hello World!"); // Print a nice greeting.
Change it to say "Hello Yourname!", or "Yourname Roolz!".
- Run
make
:
$ cd ~/hadbadge/myapp
$ make
All going well, you'll see this output:
$ make
CC crt0.S
CC app_start.c
AR libgloss.a
CC main.c
CC bla.c
OBJCOPY bgnd.png
OBJCOPY tilemap.tmx
LD myapp.elf
SYM myapp.elf
STRIP myapp.elf
And you'll have myapp.elf sitting in the myapp directory, ready to move onto your badge and run.