Introduction
When I teach microprocessors to students I find it important to have access to good tools like simulators and IDEs. Up until now that hasn’t been the case with RISC-V. Now that RISC-V tools are at a state that puts them on par with equivalent tools for AVR, ARM, x86, MIPS and PIC, I’m now getting on board with using RISC-V in my classroom.
If you’re getting started with RISC-V, don’t fall into the trap of building your own tools. Use off-the-shelf tools instead. I’ll explain that next.
Don’t do this: Build Your Own Tool
Any student getting started with RISC-V will likely encounter dozens of posts about building your own toolchain.
My advice: don’t do it.
Instead, skip past this section to see my recommendations on pre-built tools.
I’ll point out that RISC-V tool setup is still a challenge and is not nearly as straight-forward as the other architectures. The biggest stumbling block, in my mind, is that the compiler tools often need explicit rebuilding — that you have to compile your compiler. I’m looking specifically at how difficult it is to install the “RISC-V GNU Compiler Toolchain“, whether it’s the Linux or weirdly-named “unknown” target branches.
There are installer options like apt and Homebrew to get your RISC-V toolchain installed on your machine. However, they don’t always work. I’ve tried them a few times on Linux and macOS machines and it has not worked. You can see from the Homebrew installer page that the RISC-V toolchain is tagged as “failing”. This is indicative of a bad state of affairs for RISC-V tooling.
I’m clearly not the only one who thinks this. The Five-Embedded group is one of many that have turned to Docker containers with pre-built tools to avoid, at least in part, having their customers give up on setting up their own tools. I’ve found it particularly interesting that the Docker container for the RISC-V Rust compiler is far simpler to execute that the one for C/C++.
So, build your own tools if you must. But, really, the RISC-V community should consider more releases that can be used off-the-shelf.
Do This: Use Off-The-Shelf Tools
Save yourself a lot of grief. Use off-the-shelf tools that get the job done. It’s difficult enough to learn about microprocessors. Don’t start your journey by getting frustrated with trying to “build your own” tools.
There are three off-the-shelf tools that I like to use for exploring RISC-V:
The Compiler Explorer is the gold standard tool for seeing how high-level code written in languages like C, C++ or Rust get converted into Assembler for a variety of hardware platforms like RISC-V, AVR, x86 and ARM. It’s free, it’s easy and it’s high quality. Check it out.
The Web Simulator is a niche product but is handy for courses on computer architecture, like YorkU’s EECS 2021. It’s easier to set up than Spike and it’s based on the Kite simulator tool — which I’ve had a lot of success building on my own computer but is also available as a Docker container from Five Embedded. It was designed to help guide students through the standard textbook and is widely used by students and teachers. That said, it’s an assembler-only simulator, so it is limited and doesn’t reflect a modern development workflow. Consider it an entry-level tool that excels at its one job.
The Segger Embedded Studio application is the easiest, most straightforward way to get the complier and assembler tools for “bare-metal” RISC-V on to your computer. Period. It has a modern-looking front end and has all the compiler tools hidden away in its back end. There are no messy Makefiles to modify. Just start writing code. Then press the green triangle. If you have a physical RISC-V board connected with a J-Link debugger, it’ll connect. If not, it will drop into the simulator. And, at its heart, it appears to be using the open-source compiler tools that everyone else is using combined with the Rowley Crossworks front end, but it’s just been packaged a whole lot better than anything else that I’ve seen.
Again, if you’re a student and need a compiler for programming RISC-V processors: use the Segger IDE. And spend the money on a J-Link EDU debugger if you need to use hardware. Otherwise, just use the simulator.
Update (July 25, 2024): There are some options for pre-built cross-compilers that I’ve been able to find:
- Multi-OS: https://www.embecosm.com/resources/tool-chain-downloads/
- Linux only: https://github.com/stnolting/riscv-gcc-prebuilt
- macOS only: https://formulae.brew.sh/formula/riscv64-elf-gcc
- Debian package: https://packages.debian.org/bullseye/gcc-riscv64-unknown-elf
- And, of course, there’s the Segger IDE that has already been mentioned.
Conclusion
If you’re going to learn about and use RISC-V processors it’s important to have good tools at your disposal. The build-your-own route will cause headaches for a lot of students and really isn’t worth it for most people, in my mind. Two notable exceptions have been the Spike and Kit simulators, which I’ve found to be okay to build. But, for most other RISC-V tools, get yourself up-and-running much faster with tools like Compiler Explorer, the Kite-based assembler simulator on the web, and the Segger Embedded Studio product.
The RISC-V developer tools are still not as mature as those for ARM, x86, PIC and AVR. Things are getting better, but the state of RISC-V tools today is a lot like the state of ARM tools back in 2008 when my colleagues at TMU tried to get me on board with using ARM then. I eventually did around 2012 and I’m glad that I stuck with other processors until the time was right to switch.
We’re now in similar territory with RISC-V. My recommendation on using and learning with RISC-V has some caveats. And if you’re careful you’ll be fine. Stick to off-the-shelf to start. Get some success with those first. Then dip your toes into the build-your-own when you know what you’re doing.
James Andrew Smith is a Professional Engineer and Associate Professor in the Electrical Engineering and Computer Science Department of York University’s Lassonde School, with degrees in Electrical and Mechanical Engineering from the University of Alberta and McGill University. Previously a program director in biomedical engineering, his research background spans robotics, locomotion, human birth and engineering education. While on sabbatical in 2018-19 with his wife and kids he lived in Strasbourg, France and he taught at the INSA Strasbourg and Hochschule Karlsruhe and wrote about his personal and professional perspectives. James is a proponent of using social media to advocate for justice, equity, diversity and inclusion as well as evidence-based applications of research in the public sphere. You can find him on Twitter. Originally from Québec City, he now lives in Toronto, Canada.
Update: July 24, 2024 rewording and adding links.
Update: July 25: added two pre-built options.