I wanted to test my coding chops and enable the RIOT RTOS on the SiFive RISC-V HiFive1 board. Now I’d like to share my project and get some feedback from others that may be working on RISC-V implementations. I’m a Windows guy, so all the instructions below are geared towards developing on a Windows PC, but I’m pretty sure the port will comile under a Ubuntu system. I’m curious as to what you all think. By the way, kudos to SiFive for making the Freedom Studio tools. They definitely made it very easy to get up a running with the HiFive1 board.
RISC-V port fork:
Tools Used on Windows 10:
Freedom Studio v20170616 (beta2) - https://www.sifive.com/products/tools/
GNU MCU Eclipse - https://gnu-mcu-eclipse.github.io/
RISC-V Embedded GCC v7.1.1-2-20170912
MinGW & MSYS - http://www.mingw.org/
Putty - http://www.putty.org/
Setup Steps on Windows 10:
- Install Freedom Studio per instructions for Windows. Import the example projects for HiFive1
- Install HiFive1_Driver.exe under \FreedomStudio\SiFive\Misc
- Follow steps for compiling RIOT under Windows https://github.com/RIOT-OS/RIOT/wiki/Build-RIOT-on-Windows-OS
- In addition to the Mintty mingw-get install steps, add the following: mingw-get install msys-mktemp
- Copy RISC-V Embedded GCC to \riscvgcc folder somewhere on PC
- Add to Windows system environment Path env var full dir to riscvgcc\bin folder
- Clone RIOT RISC-V fork respository to \RIOT folder
- Open mintty window, cd to /RIOT/examples/default
- Build application: make BOARD=hifive1
- Setup Putty with implicit CR after LF and configure with the USB COM port per Freedom Studio instructions
Flashing and Debugging RIOT:
I liked using the Freedom Studio IDE for flashing and debugging RIOT. Also, I used the GCC and OpenOCD tool versions that come with Freedom Studio as they seemed to have been built with an XML lib that the GNU MCU versions did not, which causes download issues (seems to be related to the “cannot parse XML memory map” issue that has been discussed in the SiFive forums). I do compile RIOT with the newer compiler because it has support for the newlib_nano libraries which are smaller. So, compile with the newer GCC but flash and debug with the Freedom Studio GCC and OpenOCD tool versions.
- Add RIOT source tree to Freedom Studio via File->New->Makefile Project with Existing Code
- Make project name RIOT and give path to \RIOT folder; select the RISC-V Cross GCC toolchain for the indexer
- Under Run->Debug Configurations, duplicate one of the HiFive1 debugging configurations like led_fade Debug, name the config RIOT Debug
- Edit the RIOT Debug configuration:
Main tab: set the project to RIOT and the C/C++ app to be the full path to the RIOT app .elf file (C:\RIOT\examples\default\bin\hifive1\default.elf) Select “Disable auto build” because builds of RIOT can only be done from the Mintty shell
Debugger tab: tge OpenOCD Config option will need a full path to the HiFive1 cfg file (eg. -f C:\FreedomStudio\SiFive\Misc\sifive-freedom-e300-hifive1.cfg)
Startup tab: For Load Symbols and Load Executable, set the Use file option and give the full path to the application .elf file. Set breakpoint at: _start (the entry point to the .elf file in start.S)
-
Apply the configuration, then press Debug. The .elf file will be flashed to the HiFive1 board and Freedom Studio will kick into the GDB debugger just like any of the other example projects that ship with Freedom Studio
-
To debug other RIOT applications, update the full paths to the app’s .elf file in the RIOT Debug configuration
Features Supported:
Base RIOT core OS
FE310 CPU package
Newlib_nano
Interrupt routing via PLIC driver
Bypass clock setting via PRCI driver
Peripherals: Timer, UART, GPIO, RTT/RTC, CPUID
HiFive1 board package
Stdin/Stdout routed to UART1
Tested with RIOT Examples Default, Hello-World, IPC_pingpong, Timer_periodic_wakeup and various RIOT tests apps
Feature WIP:
PMW, SPI peripheral support
Configuration of other CPU clock speeds
Determine why the newer GNU MCU OpenOCD won’t work
Finish RIOT support of commandline flash and debug scripts
Pull request into the main RIOT repository to have offical support of RISC-V