Interfacing with the Pins

I am using Freedom Studio with a HiFive1 rev b. I would like to build a simple program that blinks an LED on a solderless breadboard. Is there any way for me to interface with pins 1-19 like an Arduino?

Arduino provides simple commands like
digitalWrite(0, HIGH);

Of course, given the fact that as of the latest release of the HiFive board, there is no way to run Arduino code directly on the board directly, I don’t expect this to be simple, especially since this product is new. I am wondering, however, if it can be done. How simple is it in C vs Rust? Any help would be appreciated.

Hi Jonas,

I don’t know about the Freedom Studio but you want to accomplish is surely possible there. Another possibility would be to use the Snowfox framework where accessing GPIO pins can be done quite simple in a high-level way quite similar to Arduino.

A minimal example might look like this:

#include <snowfox/hal/riscv64/FE310/Io.h>
#include <snowfox/hal/riscv64/FE310/Clock.h>
#include <snowfox/hal/riscv64/FE310/Delay.h>
#include <snowfox/hal/riscv64/FE310/DigitalOutPin.h>
/* ... */
using namespace snowfox::hal;
/* ... */
static uint32_t const HFXOSCIN_FREQ_Hz      =  16000000UL;
static uint32_t const CORECLK_FREQ_Hz       = 200000000UL;
/* ... */
static uint8_t  const LED_BLUE_GPIO_NUMBER  = 21;
/* ... */
FE310::Delay         delay;
/* ... */
int snowfox_main()
  clock.setClockFreq(static_cast<uint8_t>(FE310::ClockId::coreclk), CORECLK_FREQ_Hz);


  return 0;

For a full working example take a look here.

If you want to compile it for your HiFive 1 Rev. B you’ve got to follow the following steps:

  • Download/Install RISCV64 Compiler (you probably already did that)
sudo wget
sudo tar -xzvf riscv64-unknown-elf-gcc-8.2.0-2019.02.0-x86_64-linux-ubuntu14.tar.gz
export PATH=$PATH:/opt/riscv64-unknown-elf-gcc-8.2.0-2019.02.0-x86_64-linux-ubuntu14/bin
  • Clone the Snowfox Repository with all examples
git clone --recurse-submodules
cd snowfox
  • Build the SiFive FE310-G002 GPIO example (the compiled binary is located in `build/bin/hal-fe310-digital-out-pin )
.ci/script/ examples/hal/FE310/hal-fe310-digital-out-pin

As for getting the number of a specific pin exposed on the HiFive 1 Rev. B header - you can look up the exact GPIO number by taking a look at the schematic / page 3. It would be an easy thing to create a header file containing constants for each GPIO pin exposed on a header, e.g.

/* ... */
enum class HiFive1RevBGpioPin : uint32_t
  D2 = 18, /* GPIO_18 */
  D3 = 19, /* GPIO_19 */
  /* etc. */
/* ... */

Pull requests are always welcome :wink:

1 Like

It’s interesting. I actually imported these as source files in scifive to see if the libraries would work in the IDE. The only problem seems to be that the code above is written in c++ rather than C. Does snowfox support C? I think that’s all I would need. Granted, I haven’t tried it the way you suggested. I’m not complainin, I’m just curious.

Hi Jonas :wave: You’ll be definitely able to integrate Snowfox code within the Freedom SDK / Studio (and compile them) but I doubt it’s the wisest course of action. Both Freedom SDK and Snowfox provide HAL (Hardware Abstraction Layer) functionality but each of those projects is self-contained and follows its own design philosophy. Wildly mixing together without knowing what you are doing is a guarantee for a headache :wink:

1 Like

Noted. Naturally, I like working within a GUI workspace because of all the tools and convenience, but I will give your advice a try in the terminal.

Hi Jonas :wave:

I can understand your reluctance to deviate from GUI tools because I myself like to work with a good GUI when its available. Fortunately the HiFive 1 Rev. B is supported by Segger Ozone which is one of the best debugging IDEs that’s around. In order to get started you have to:

  • Download & Install Ozone

  • Start it up and select the FE310 MCU


  • Connect the HiFive 1 Rev. B and check if the JLink on the HiFive is detected


  • Select the binary file for upload/debugging ( snowfox/build/bin/hal-fe310-digital-out-pin )


  • Download binary via Download & Reset Programm and perform a reset and halt in order to start debugging from the very beginning via Reset & Halt

Have fun :wink:

1 Like