-
Notifications
You must be signed in to change notification settings - Fork 8
OpenRISC SoC on FPGA
This page will outline how to compile the designs in mor1kx-dev-env for FPGA, program the board and debug the system.
Note: this guide will focus on using the build for the DE0 Nano FPGA board.
If you haven't already, make sure all the tools and required source are installed. See the installation guide for details.
It's advisable to familiarise yourself with the mor1kx-dev-env / ORPSoC system by running some basic examples. See this guide to using the system for the basics.
The boards/
directory in this build environment contain system builds (the top-level description of the SoC, pulling in each component and configuring other parts of the system, as well as containing scripts to simulate and synthesise the system for FPGA). They are sorted, first by technology, and secondly by the targeted FPGA board.
In this guide we will build for the Altera FPGA-based DE0 Nano board.
The next section will focus on building and running the system on the DE0 Nano.
The DE0 Nano source is under the mor1kx-dev-env/boards/altera/de0_nano
To synthesise the design using the Quartus tools we want to go into mor1kx-dev-env/boards/altera/de0_nano/syn/quartus/run
First it's best to clean everything:
make clean clean-sw
Here we simply run:
make asm
This will work as long as the $ALTERA_PATH
is configured correctly.
This will generate an orpsoc.sof
file which cna be programmed onto the board
In the synthesis directory, there is also a makefile recipe for programming the board:
make pgm
One of several things could go wrong here.
- One is that the JTAG daemon running needs to be killed and the Altera one run instead, to do this run:
killall jtagd
sudo /opt/altera/12.1sp1/quartus/bin/jtagd
-
Another problem might be that the OpenOCD debugger is still using the JTAG/USB port - exiting OpenOCD will fix this
-
Another could be basic permissions on the USB device, and running
sudo make pgm
may fix things
From within the OpenOCD directory (presumably $HOME/or1k/openOCD
) run:
sudo ./src/openocd -f ./tcl/interface/altera-usb-blaster.cfg -f altera-dev.tcl
You should then see something like:
Info : JTAG tap: or1k.cpu tap/device found: 0x020f30dd (mfg: 0x06e, part: 0x20f3, ver: 0x0)
(ignore any warnings or errors about the JTAG tap...)
target state: halted
Chip is or1k.cpu, Endian: big, type: or1k
Once the proxy is connected we can then connect to it with GDB.
Note that when the proxy connects it will stall the processor.
In a new terminal run the OR1K port of the GNU debugger (GDB).
or1k-elf-gdb
Now connect to the port the proxy is running on:
(gdb) target remote :50001
You should see something like the following:
Remote debugging using :50001
0x00000700 in ?? ()
You can now access the system memory and registers.
Read memory with x <addr>
eg:
(gdb) x 0x0
0x0: 0x00000000
See this table of GDB commands for further information.
We can compile software and load software from within GDB.
Some software we can run on the board to flash the LEDs is in the board's sw/tests/gpio/board directory:
(gdb) cd ~/or1k/mor1kx-dev-env/boards/altera/de0_nano/sw/tests/gpio/board/
(gdb) make gpio-blink.elf
Now tell GDB to use this compiled binary:
(gdb) file gpio-blink.elf
Download the file to the system's memory
(gdb) load
This will also set the CPU's program counter (PC) to point to the start address
Finally - run the program!
(gdb) c
....
Press ctrl+c to stall the processor and regain control of the GDB console.
Now build and load the gpio-int
test to demonstrate a pushbutton triggering an interrupt:
(gdb) make gpio-int.elf
(gdb) file gpio-int.elf
(gdb) load
(gdb) c
Now press pushbutton 1 (marked KEY1) on the board to toggle an LED. Actually we are doing edge detection in the GPIO peripheral core. On the button being pressed we then install an interrupt handler for when it is released.
(gdb) cd ~/or1k/mor1kx-dev-env/boards/altera/de0_nano/sw/tests/simple_spi/board/
(gdb) make simple_spi-adxl345.elf
(gdb) file simple_spi-adxl345.elf
(gdb) load
(gdb) c
This software is communicating with the ADXL345 accelerometer and reading the X, Y and Z axis acceleration readings, determining which is greatest (and therefore, when at rest, perpendicular to earth's gravity).
LEDs 0 = X (positive)
LEDs 1 = Y (positive)
LEDs 2 = Z (positive)
LEDs 3 = X (negative)
LEDs 4 = Y (negative)
LEDs 5 = Z (negative)
(gdb) make simple_spi-adxl345fancy.elf
(gdb) file simple_spi-adxl345fancy.elf
(gdb) load
(gdb) c
Now double-tap the top of the board with a pen to see the LED pattern switch.