Build and debug with toolchain

Hello,

I am starting over with the HiFive 1 Rev B. I want to learn Assembly, C and Rust with this board and I want to have it down seriously. But I am a complete noob even when it comes to building a simple “Hello world!” I have already tried Freedom Studio and SEGGER Embedded Studio. Both are fine, but I want to use the toolchain only,

I am using Debian bookworm and these are the steps I have performed.
I have installed SEGGER - The Embedded Experts - Downloads
extracted the toolchain to $HOME/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/ and added this bin path to $PATH
I could get GitHub - riscv-rust/riscv-rust-quickstart: A template for building Rust applications for HiFive1 boards to run, but i don’t know, how to build and run a simple “Hello world” in C on the device. Any help would be appreciated!

When I execute “riscv64-unknown-elf-gcc -march=rv32imac -mabi=ilp32 main.c” on

#include <stdio.h>
#include <stdlib.h>

int main(void) {
printf(“Hello, world!\n”);
return 0;
}

i get the a.out file. Executing it exec: Failed to execute process: ‘./a.out’ the file could not be run by the operating system.

The debugger is running in another terminal with
JLinkGDBServer -device FE310 -if JTAG -speed 4000 -port 3333 -nogui
and another one has cat < /dev/ttyACM0, which shows the SiFive logo.

How can I get my program to run on the device? Please help.

Hello @jahro_me

The easiest way to run C and Assembly programs is by using SiFive Freedom Studio IDE. This is the recommended way to start with the board development.
Alternatively, you can use Freedom-E-SDK with the command line toolchain.
Please refer to section “7.3 Software Development Using Freedom E SDK Command
Line Tools” in SiFive HiFive1 Rev B Getting Started Guide for more details:
https://www.sifive.com/document-file/hifive1b-getting-started-guide

1 Like

Perhaps the smallest (and simplest) toolchain in the world, @jahro_me, is riscv.mk shown by way of example in my Demonstrating AMO repo.

Revise a few lines at the top of the .mk file and you can compile, assemble, link, load, and even debug with one command:

make -f riscv.mk ramload

Of course, use ramrun to start the target running; or the rom… equivalents to load and run from Flash. Memory map physical layout is in the .lds linker definition script files.

You’ll also need to customize (and copy/paste) the few lines to define your source files, whether asm’s, c’s, etc.

For details on building your toolchain applications (I use openocd for the loader) from source, you can see my notes at RISC-V Easy As PI.

An overview and refresher of RISC-V concepts is in the JCSSE Hands-on Workshop – it’s on my www.riscvthai.org site.
User name: paul
Password: paul

Let me know how goes :slight_smile: