Page 1 of 1

Playing around with a Risc-V demo processor board

Posted: Fri Jan 03, 2020 1:06 pm
by parkview
The RISC-V processor is one of the first open source intellectual property rights free CPU. This means anyone (or company), can use the files and information to create their own RSIC-V core CPU. More info can be found here:

I have been following it's journy for a number of years, but late 2019 seems to have been when CPU chips are now affordable to be used. Lots of companies will now be using them inside their products. Eventually this might impact on ARM's busin4ess modle of selling cheap CCPU Cores to companies for re-use.

Last December while in Shenzhen a couple of use purchased some cheap Sipeed Nano-Lite RISK-V based dev boards:
Sipeed Longan Nano-Lite.jpg
Sipeed Longan Nano-Lite.jpg (46.35 KiB) Viewed 1711 times
For me these have been fun to play with, as I have learned how to program then via a Windows 7 USB-C based dfu-util program. You can also program it via OSX and Linux. Initially there where some driver issues, in that 1) special Windows 7 drivers needed to be installed and 2) a special updated version of the dfu-util needed to be found.

The error in my Device Manager:
missing a DFU Windows USB driver.jpg
missing a DFU Windows USB driver.jpg (21.58 KiB) Viewed 1711 times
1) If needed, you can find the Windows 7 dfu-util driver here: Now the Device has been found:
DFU USB driver now installed.jpg
DFU USB driver now installed.jpg (3.52 KiB) Viewed 1711 times
2) As I am currently using Microsoft Visual Code IDE and PlatformIO to program the board, I found a working dfu-util inside the PlatformIO packages area: C:\Users\<loginname>\.platformio\packages\tool-gd32vflash>dfu-util.exe

Use dfu-util -h to see a full list of available commands.

There are two areas of code storage on the RISC-V flash ROM. The area starting at: 0x80000000 is the user program storage site. To backup the default program that comes with it:
dfu-util.exe -a 0 --dfuse-address 0x08000000:leave -Z 32768 -U GD32_clean-firmware_20200101.a0.2.bin

The Z command should have only uploaded 32KB, but instead it uploaded 1MB. I manually had to hack that back to a smaller file as I received an error message when I tried flashing the backup image to another board. To do this, I used a hex editor called: Frhed (you can most probably use any one). It was easy to spot where the program ended, as most of the 1MB backup file contained: FF bytes. I deleted them all, in my case from 0x49c8 to 0xffff and then saved the 18,888B file. I then uploaded this and it worked:
EOF.jpg (87.92 KiB) Viewed 1711 times
dfu-util.exe -a 0 --dfuse-address 0x08000000 -D GD32_clean-firmware_20200101.a0.2a.bin

I can now write any program I like, knowing I can restore the board back to an original condition. Thanks to Olivier for his help with the dfu-util commands.

Re: Playing around with a Risc-V demo processor board

Posted: Fri Jan 03, 2020 1:14 pm
by parkview
So lets have a play with writing a simple program using the Arduino framework on PlatformIO. After installing the Sipeed Longan Nano-Lite board form the home page, I created a new project with this code:

platformio.ini config:

Code: Select all

platform = gd32v
board = sipeed-longan-nano-lite
framework = arduino
upload_protocol = df

main.cpp code:

Code: Select all

#include <Arduino.h>

// Green LED = P1
// Blue LED = P2
// HIGH = led OFF
// LOW = led ON
#define LED_DELAY 900   // mSec

void setup() {
  // put your setup code here, to run once:
  pinMode (2,OUTPUT);  // Blue LED
  pinMode (1,OUTPUT);  // Green LED
  // make sure all LEDs are off
  digitalWrite (LED_BUILTIN, HIGH);
  digitalWrite (1, HIGH);
  digitalWrite (2, HIGH);

void loop() {
  // put your main code here, to run repeatedly:
  // Turn the LEDs on - one by one
  digitalWrite (LED_BUILTIN, LOW);
  digitalWrite (2, LOW);
  digitalWrite (1, LOW);
  // Turn the LEDs off- one by one
  digitalWrite (LED_BUILTIN, HIGH);
  digitalWrite (2, HIGH);
  digitalWrite (1, HIGH);

Which cycles the three built in RGD LEDs. As my notes above say, the LEDs are turned off with the HIGH, as it's a common Anode RGB LED.

Re: Playing around with a Risc-V demo processor board

Posted: Mon Mar 09, 2020 9:42 pm
by DJCoopes
A fully open-source CPU! Now this is an interesting concept. Can't wait to see how people work with /on it. Thanks for the post!