Playing around with a Risc-V demo processor board

Tell us about your projects. Update us regularly.
Post Reply
parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Playing around with a Risc-V demo processor board

Post by parkview » Fri Jan 03, 2020 1:06 pm

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: https://riscv.org/

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 1044 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 1044 times
1) If needed, you can find the Windows 7 dfu-util driver here: https://zadig.akeo.ie/ Now the Device has been found:
DFU USB driver now installed.jpg
DFU USB driver now installed.jpg (3.52 KiB) Viewed 1044 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
EOF.jpg (87.92 KiB) Viewed 1044 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.

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

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

Post by parkview » Fri Jan 03, 2020 1:14 pm

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

[env:sipeed-longan-nano-lite]
platform = gd32v
board = sipeed-longan-nano-lite
framework = arduino
upload_protocol = df

main.cpp code:

Code: Select all

#include <Arduino.h>

// NOTE:  LED_BUILTIN = RED = P13
// 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 (LED_BUILTIN,OUTPUT);  //RED LED.
  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);
  delay(LED_DELAY);
  digitalWrite (2, LOW);
  delay(LED_DELAY);
  digitalWrite (1, LOW);
  delay(LED_DELAY);
  // Turn the LEDs off- one by one
  digitalWrite (LED_BUILTIN, HIGH);
  delay(LED_DELAY);
  digitalWrite (2, HIGH);
  delay(LED_DELAY);
  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.

DJCoopes
Mini-Maker
Posts: 40
Joined: Sat May 26, 2018 11:38 am
Location: Busselton
Contact:

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

Post by DJCoopes » Mon Mar 09, 2020 9:42 pm

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!
10 poke 53281,0
20 poke 646,5
30 poke 53280,0
40 poke 647,0
50 print " **** commodore 64 basic v3 ****"
60 print " "
70 print " 64k ram system 38911 basic bytes free"
80 print " "
90 print "ready."

Post Reply