So far, I’ve unboxed a couple of low-cost development kits featuring a relatively new Instruction Set Architecture (ISA) called the RISC-V. The RISC-V systems are surprisingly powerful microcontrollers capable of operating around 150 MHz. The ISA itself is maintained by the RISC-V Foundation, and the devices are produced by many enterprises and research institutes worldwide.
Mostly, the RISC-V projects done here in 2019 had Microsoft Windows 10 users in mind. But not so much for the avid Linux user. But no more! Today, I will cover one way to get started with the RISC-V ISA using Ubuntu 19.10 and 18.04. Users of similar Linux distributions can expect a similar experience.
Before I get started, I should acknowledge Sparkfun and Digi-Key. Both of them have published highly useful guides that helped get my project underway.
Notice of Non-Affiliation and Disclaimer: We are not affiliated, associated, authorized, endorsed by, compensated by, or in any way officially connected with Sparkfun Electronics, SiFive, Segger Microcontroller Systems, RISC-V Foundation, Arduino, Digi-Key, ARM, NXP or their subsidiaries or affiliates.
Comparing RISC-V Development Boards
If you’re looking to start a new electronic project using a RISC-V system, the easiest way to get started is to use a low-cost development board. Fortunately, there are many more RISC-V development board options today than in previous years. The two featured here are both available from Sparkfun.
In Figure 2 above, the larger board on the left is the Sparkfun RED-V RedBoard. This system has an Arduino-like form factor. The smaller one near the center of the photo is the Sparkfun RED-V Thing Plus. This system has a lower price tag, but you will need to solder on your own through-hole connectors if you want real connectors for inputs and outputs.
These systems feature SiFive Inc.’s Reduced Instruction Set Computer Five (RISC-V) processor: the FE310-G002. This device is based on SiFive’s Freedom E310 core, which is used in a few other devices not featured here. The USB interface is the interface for programming and debugging. The debugging features are handled by a Kinetis K22F processor and its SEGGER and J-Link firmware.
You can use either the RedBoard or the ThingPlus in this guide since they both include the Kinetis K22F chip and the Freedom E310.
Hardware Materials Used
Basically, the hardware you need is the RISC-V development board itself and a USB Type C cable…
Hardware used:
- RED-V RedBoard or RED-V Thing Plus board
- USB-C Cable: Type A (USB 3.1) to Type C
- Desktop PC running Ubuntu (tested here: version 18.04 and version 19.10)
- (Optional) Separate 2.54 mm (0.1-inch) pin headers for the RED-V Thing Plus
- (Optional) Soldering iron and solder
Software Materials Used
I tested this build using a desktop computer and some recent distributions of Ubuntu Linux.
Software used:
- Freedom Studio 2019.08.2
- Ubuntu 19.10 (Eoan Ermine) and Ubuntu 18.04 Long Term Support (Bionic Beaver).
- (Recommended) Anti-malware software
This guide will assume you have basic-level experience with Linux: such as how to open the terminal and what the home directory is. You will also need super-user (sudo) privileges on your computer. If you are using a computer you don’t own, you should ask your system administrator for this level of access.
Installing Freedom Studio
It’s time to get started!
The easiest way to get Freedom Studio is to go directly to SiFive’s official website at: https://www.sifive.com/boards.
From there, scroll down to the section labeled “Freedom Studio.”
Select the Linux download option, and then choose to save the FreedomStudio-2019-08-2-lin64.tar.gz file.
While you wait for the file to download, you should go ahead and plug your RED-V board and its USB cable into your computer if you haven’t already.
In Ubuntu, open a terminal window. Make sure you are at the home directory…
After scanning the .tar.gz file for malware (always scan anything you get from the outside world), create a new directory for Freedom Studio…
mkdir -p Projects/FreedomStudio
Now extract the .tar.gz file from the Downloads directory to the new FreedomStudio directory. Assuming your download went to the Downloads directory, enter this in the terminal…
tar -zxvf Downloads/FreedomStudio-2019-08-2-lin64.tar.gz -C Projects/FreedomStudio/
If the file extraction succeeds, navigate to the new FreedomStudio directory by entering…
cd Projects/FreedomStudio
View the directory contents by entering…
ls
You should see several files and directories here, including the FreedomStudio application itself.
Now it’s time to execute the application. By default, Linux might block FreedomStudio’s access to your USB port. This could cause the “J-Link GDB Server failed” error in later steps, which is something I saw in both Ubuntu 18.04 and 19.10. To avoid this, you can run Freedom Studio with super user privileges as shown…
sudo ./FreedomStudio
If you don’t like needing to type sudo every time, SiFive has offered a different approach in their official Freedom Studio User Manual. But you will need to use sudo privileges at least once to configure everything.
Anyway, if things are working, you will see the workspace selection form below. For today, I will accept the default by clicking “Launch” without changing anything.
Next, you should see the Freedom Studio splash screen…
Create a New Freedom E SDK Project
If it’s your first time running the application, you will probably see the welcome screen below. Select the option labelled “I want to create a new Freedom E SDK Project.” If you don’t see the welcome menu, navigate to:
File –> New –> Freedom E SDK Software Project
Next, it’s time to tell Freedom Studio what type of SiFive device we will reprogram, and the name of the example program we want to load.
According to Sparkfun, the SiFive HiFive1 Revision B board is similar to the system we will use here. So choose “sifive-hifive1-revb” in the drop-down box, as shown in Figure 11 above.
Select the “hello” example program by choosing it in the “Select Example Program” area, as shown in Figure 11 above.
Click “Finish.”
Freedom Studio will automatically build the example application for you.
Edit Configuration
The edit configuration form should appear automatically after a short delay while the hello project builds. There is no need to change anything here, so just click “Close.”
With edit configurations closed, we can see the entire Freedom Studio Integrated Development Environment (IDE), and the example source code.
This includes the printf() method, which will cause the FE310-G002 chip to send the message “hello world” through the USB cable to us later…
Above, you can see the hello.c example program. I modified this code by adding a while(1) loop. Doing this will transmit the string endlessly. Without the while loop, you will need to reset the RED-V system before the message will appear, which could become a tad bothersome.
Upload the Application (Begin Debugging)
To upload this application to the RED-V boards, we need to access the Run Configuration form.
Look near the top of the Freedom Studio IDE. Locate the green “play” button, and click the drop-down arrow next to it, as shown in Figure 14 below. Then click “Run Configurations…”
In the “Run Configurations” form, click the option labelled “SiFive GDB SEGGER J-Link Debugging.” This will expand to include the line “sifive-hifive1-revb-hello.” Select “sifive-hifive1-revb-hello,” and then click “Run.” If you made any changes, you will be asked to save first, which is okay.
When you click the Run button, the GNU Debugger (GDB) server should start automatically. This will automatically upload your application to the development board.
Tips for Debugging Run Configurations
If you have a connection problem (such as not having USB permissions), you will see “Error. Exception occurred during launch.” This is the error I encountered the most when trying this for the first time. Try a using different cable or a different USB port first if you see this error. Some USB-C cables are very unreliable. If you still have problems, open up a new terminal window, and type:
lsusb
Lsusb will list your USB devices. You should see at least 1 SEGGER device on the list. If not, you should try a different USB cable, or try a different USB plug.
Configure the Terminal
The code will automatically start running on the FE310-G002. But you will not see the “hello world” message until you configure the terminal.
On the right side of the Freedom Studio IDE is an area for configuring the terminal. Click the terminal tab first. Then click the small terminal icon to select a serial interface.
This will produce the “Launch Terminal” form. Click “Serial Port.”
The RISC-V is connected to 1 of 2 or more serial interfaces labeled “/dev/ttyACM.” In my case, /dev/ttyACM0 was the correct one. Yours may be slightly different.
All other settings should match these…
- Choose terminal: Serial Terminal
- Baud rate: 115200
- Data size: 8
- Parity: None
- Stop bits: 1
- Encoding: Default (ISO-8859-1)
Click “OK” to finish.
If you used the while(1) loop, as shown above, you should see a lot of activity at the terminal…
Once your code is running, you can pause or stop the application using the icons below…
Conclusions
Hopefully, this guide gets Linux users up and running with this low-cost RISC-V platform. Having sampled Freedom Studio both in Windows and Ubuntu, I’ll say both have very similar layouts. Expect to see more projects as we explore more applications for this new ISA!
References
[1] | B. R. Mayes, “Unboxing the Sparkfun RED-V Thing Plus Board,” Voxidyne Media, LLC, 4 Feb. 2020. [Online]. Available: https://unboxing-tomorrow.com/unboxing-the-sparkfun-red-v-thing-plus-board/. [Accessed 17 Feb. 2020]. |
[2] | B. R. Mayes, “Unboxing the Sparkfun RISC-V RedBoard,” Voxidyne Media, LLC, 15 Dec. 2019. [Online]. Available: https://unboxing-tomorrow.com/unboxing-the-sparkfun-risc-v-redboard/. [Accessed 18 Feb. 2020]. |
[3] | Digi-Key Corp., “Getting Started with SparkFun Red-V RISC-V Boards – Maker.io Tutorial | Digi-Key Electronics,” Digi-Key Corp., [Online]. Available: https://www.digikey.com/en/videos/s/sparkfun/getting-started-with-sparkfun-red-v-risc-v-boards-digi-key-electronics. [Accessed 18 Feb. 2020]. |
[4] | Sparkfun Electronics, “RED-V RedBoard Hookup Guide,” Sparkfun Electronics, [Online]. Available: https://learn.sparkfun.com/tutorials/red-v-redboard-hookup-guide. [Accessed 18 Feb. 2020]. |
[5] | Sparkfun Electronics, “RED-V Development Guide,” Sparkfun Electronics, [Online]. Available: https://learn.sparkfun.com/tutorials/red-v-development-guide. [Accessed 18 Feb. 2020]. |
[6] | SiFive, Inc., “Freedom Studio User Manual,” 2 Aug. 2019. [Online]. Available: https://cdn.sparkfun.com/assets/learn_tutorials/1/1/0/1/freedom-studio-manual-4.7.2-2019-08-2.pdf. [Accessed 18 Feb. 2020]. |