Tutorial on bare-metal programming with the VisionFive 2

Hi everyone,

I’ve been playing around with writing bare-metal code for the VisionFive 2. If this is interesting to you, I’ve written up a small article about how to get some basic bare-metal programs working (blink an LED and print over the UART): https://zyedidia.github.io/blog/posts/2-baremetal-visionfive/. The associated code can be found here. The code is written in D, but should be easy understand if you know C. If you are new to bare-metal programming, you can also check out the first post in the series, which describes how to write a bare-metal RISC-V program that is simulated in QEMU.

Thanks!

6 Likes

Awesome and nice job, learning right now.

1 Like

Awesome! Let me know if you have any questions or issues.

Terrific work!

I have done bare metal programming with riscv chips from SiFive and WCh using assembly language. This write up is a great summary of how to start working with this sbc.

Thanks for your hard work!

1 Like

According to this patch: [v4,19/19] riscv: dts: starfive: Add StarFive JH7110 VisionFive 2 board device tree - Patchwork
mtime frequency should be 4Mhz if you use same clock config as upstream device tree.

Very interesting. I measured the 4.8 MHz number assuming the CPU clock speed was 1.5 GHz. If the timer is actually 4 MHz then this would indicate that the CPU clock speed is 1.25 GHz by default. I wonder if you need to do some device I/O to increase the clock speed to the maximum 1.5 GHz. I’ll try looking into it tonight.

1 Like

Yes I can confirm that the timer frequency is actually 4 MHz, and the board seems to run at 1.25 GHz by default. Thanks!

1 Like

I just received a Star64 board which features the JH7110 cores and a chipset similar to the Visionfive 2. I am using a mac for development.

I flashed the boards SPL to the latest startech version.

I also was able to use zachs post to flash a simple assembly program to the board.

The Star64 board came with a usb “PINE64 usb jtag adapter” but I couldn’t find out how to use it with openocd or the jlink software.

I was able to use a “JLink Edu” usb device to connect to the boards jtag connector.

Using jlink i was able to load elf files into the boards memory. This allows you to rapidly test code on the device. This does NOT load the code to the boards flash. You have to use the method zach describes to do that.

Unfortunately I was only to load code that runs on the hart with mhartid of zero. This corresponds to the S7 monitor core on the JH7110.

Has anyone figured out how to get code loaded into memory and get the other cores to run it?

I think that perhaps the S7 core could load code into memory and then maybe communicate with one of the other cores and tell it to run that code.