RISC-V

 
 
RISC-V is an open standard instruction set architecture (ISA) based on established reduced instruction set computer (RISC) principles. The RISC-V ISA is provided under open source licenses that do not require fees to use.

More information about RISC-V can be found at:
https://riscv.org/








Sipeed Longan Nano using Visual Studio Code and PlatformIO and upload to development board.



Information
none

Operating system used
Windows 10 Pro

Procedure
  • Sipeed Longan GD32VF103CBT6 MCU Nano RISC-V Development Board (LCD screen is optional)

    Sipeed Longan GD32VF103CBT6 MCU Nano RISC-V Development Board

  • USB A - USB C cable

    USB A - USB C cable

  • Install Visual Studio Code.
    https://code.visualstudio.com/
    Download and install VSCodeUserSetup-x64-1.59.1.exe

  • Change Color Theme (Optional)
    Select in left menu: Manage (Cog wheel)
    Color Theme: Monokai

  • Select in left menu: Extensions

    Visual Studio Code: Select Extensions

  • Install several extensions:
    Note: Search the extensions by entering its name in the Search box.

    • C/C++ (C/C++ IntelliSense, debugging, and code browsing.)
    • vscode-icons (Icons for Visual Studio Code)
    • vscode-pdf (Display pdf file in VSCode.)
    • PlatformIO IDE (Professional development environment for Embedded, IoT, Arduino, CMSIS, ESP-)

    Installed extensions

  • Restart Visual Studio Code.

  • Start PIO Home:
    • Select in left menu PlatformIO (Ant/Alien icon)
    • Select: New Terminal

    PlatformIO New Terminal

  • In the terminal window type: pio platform install gd32v
    The release version (stable version) will be installed.
    If you want to install the development version (latest version), type: pio platform install https://github.com/sipeed/platform-gd32v

    Install platform

  • Select menu: PIO Home | Open
    Select: Project Examples

    Project Examples

  • Import project example:Arduino blink

    Arduino Blink

  • Modify platformio.ini

    [env:sipeed-longan-nano]
    ;Platform, choose gd32v
    platform = gd32v

    ;Optional gd32vf103-sdk or arduino
    framework = arduino

    ;Development board
    board = sipeed-longan-nano

    ;Serial monitor baudrate
    monitor_speed = 115200

    ;Download tool Default serial port, optional jlink, gd-link, dfu, etc.
    upload_protocol = serial


    Platformio.ini

  • Build code.

    Build

    Terminal output: build_serial_sipeed_longan_arduino_blink.txt

  • There are several methods to upload the compiled Blink program to the Sipeed Longan Nano Development Board. I will demonstrate 3 methods A, B and C.
    Method D is not working. Do not use this option.

    • Method A: Using a USB-A - Mini USB-B cable (upload_protocol = serial), a FTDI FT232RL adapter and PlatformIO to upload the firmware.
    • Method B: Using a USB-A - USB-C cable (upload_protocol not used), and "GD32 Dfu Tool" to upload the firmware.
    • Method C: Using a USB-A - USB-C cable (upload_protocol = sipeed-rv-debugger), the Sipeed RV Debugger Plus and PlatformIO to upload the firmware.
    • Method D: Using a USB-A - USB-C cable (upload_protocol = dfu) and PlatformIO to upload the firmware.

      ***********************
      WARNING! Method D was not working for me and I was not able to upload the firmware.
      ***********************


  • Method A: Using a USB-A - Mini USB-B cable (upload_protocol = serial), a FTDI FT232RL adapter and PlatformIO to upload the firmware.
    FTDI FT232RL

    Top view

    FTDI FT232RL top view

    The VCC pin can output 3.3V or 5.0V depending on how you set the jumper.
    Set the jumper to 3.3V.
    The FTDI adapter itself is powered (5V) by the USB-A -> mini USB-B cable.

    Bottom view

    FTDI FT232RL bottom view

  • Jumper wires 15 cm long (4x female-female), the photo shows 6 wires!
    I only need 4 jumper wires to connect the FTDI adapter to the Sipeed Longan Nano Development Board.

    FTDI cable

    Connect the FTDI FT232RL (on the left) to the Sipeed Longan Nano Development Board (on the right) using jumper wires.

    Connect the FTDI adapter to the Sipeed Longan Nano Development Board

    FTDI FT232RL adapter (Only pins RX, TX, VCC and GND are used)

    FTDI adapter

    Sipeed Longan Nano Development Board (Only pins TO, RO, 3V3 and GND are used)

    Sipeed Longan Development Board

    FTDI adapter (set jumper 3.3V) Sipeed Longan Nano Development Board
    DTR (Not connected) -
    RX TO
    TX RO
    VCC 3V3
    CTS (Not connected) -
    GND GND

  • Connect the FTDI FT232RL adapter to the computer using an USB 2.0 cable, USB-A > Mini USB-B (length: 80 cm)

    USB 2.0 cable type A/B

    Connect FTDI FT232RL adapter to computer

  • When the FTDI FT232RL adapter is plugged into the computer, Windows 10 pro does not detects the FTDI FT232RL adapter.
    You need to install a Virtual COM port (VCP) driver.
    Virtual COM port (VCP) drivers cause the USB device to appear as an additional COM port available to the PC. Application software can access the USB device in the same way as it would access a standard COM port.

    The VCP Drivers, can be found at: https://ftdichip.com/drivers/vcp-drivers/

    I downloaded the setup_executable file (CDM212364_Setup.zip) and executed CDM212364_Setup.exe to install the Virtual COM port (VCP) driver.

    VCP drivers

  • Install FTDI CDM drivers.

    Install FTDI driver 1

    Install FTDI driver 2

    Install FTDI driver 3

    Install FTDI driver 4

  • The Windows Device Manager (devmgmt.msc) automatically detects which COM port is being used when the FTDI FT232RL adapter is plugged in.

    COM port detected

  • When using the FTDI FT232RL adapter, modify the platformio.ini file and add the following line:
    upload_protocol = serial

    Note 1: The USB-C connector on the Sipeed Longan Nano Development Board is not connected to anything. The FTDI FT232RL adapter provides power (3.3V) to the Sipeed Longan Nano Development Board.

    Note 2: There is no need to specify the port by adding the following line in platformio.ini:
    upload_port = COM4 (Depends which COM port the FTDI FT232RL adapter is connected to).
    The COM port is auto detected.

  • Set the Sipeed Longan Nano Development Board into download mode:
    • Press BOOT key and keep it pressed.
    • Shortly press and immediately release the RESET button.
    • Then release the BOOT button.

    Reset and boot button on the Sipeed Longan Nano Development Board

    The Sipeed Longan Nano Development Board is now set into download mode.
    The preloaded Red-Green-Blue Led stopped blinking and only the power LED is on.

    Sipeed Longan Nano Development Board in download mode

  • Upload the Blink program to the development board.

    Upload program

    Terminal output: upload_serial_sipeed_longan_arduino_blink.txt

  • The Blink program is now running on the development board.


  • Method B: Using a USB-A - USB-C cable (upload_protocol not used), and "GD32 Dfu Tool" to upload the firmware.
    First connect the Sipeed Longan Nano Development Board to computer using the USB cable.

    Connect Sipeed Longan Development Board to computer

    When the Sipeed Longan Nano Development Board is plugged into the computer using the USB-A - USB-C cable, Windows 10 pro does not detects the development board.
    You need to install an driver.

  • It is important to follow this procedure in the correct order:

    • Goto http://www.gd32mcu.com/en/download/ (GigaDevice download section), and select GD32VF1 MCU.
      Select Tab "Tool & Software".

      Download "GD32 Dfu Drivers". I have downloaded GD32_Dfu_Tool_V3.8.2.9056.rar
      Download "GD32 MCU Dfu Tool". I have downloaded GD32DfuDrivers_V3.6.6.6167.rar

    • Unpack both rar files.

  • Install the GD32DfuDriver (Please note: My computer has a 64-bit processor x64):
    • Goto folder GD32DfuDrivers_V3.6.6.6167\x64
    • Execute file GD32DfuDrivers.exe as Administrator.

    Install GD32DfuDriver

  • Start Windows Device Manager (devmgmt.msc) and check if the device is detected.
    If the device is not detected:

    • Press BOOT key and keep it pressed.
    • Shortly press and immediately release the RESET button.
    • Then release the BOOT button.

    Device Manager GD32DfuDriver

    Device Manager GD32DfuDriver details

    Device Manager GD32DfuDriver events

  • The GD32DfuDriver is now installed and the Sipeed Longan Nano Development Board can now be detected.

    There is NO need to add the following line:
    upload_protocol = dfu

    in platformio.ini, because PlatformIO will not be used to upload the firmware.

  • Start the GD32 MCU Dfu Tool.exe, the other rar was which unpacked.
    If the pull down menu "DFU Device" is empty, set the Sipeed Longan Nano Development Board into download mode:

    • Press BOOT key and keep it pressed.
    • Shortly press and immediately release the RESET button.
    • Then release the BOOT button.

    ... and restart GD32 MCU Dfu Tool.exe

    GD32 Dfu Tool

  • Build the Blink.cpp program.

    The firmware file (firmware.hex) which will be uploaded to the development board is located at: C:\Users\robertlie\Documents\PlatformIO\Projects\xxxxx-arduino-blink\.pio\build-sipeed-longan-nano

    firmware.hex file

  • In the GD32 MCU Dfu Tool, select the firmware.hex file and press the OK button to upload the firmware to the development board.

    Select firmware.hex file in GD32 MCU Dfu Tool

    firmware.hex file is uploaded

  • Press the Reset button on the development board if the LED does not blink.


  • Method C: Using a USB-A - USB-C cable (upload_protocol = sipeed-rv-debugger), the Sipeed RV Debugger Plus and PlatformIO to upload the firmware.
    I have written a separate tutorial, see:
    Using Sipeed RV Debugger Plus to upload firmware and to debug code


  • Method D: Using a USB-A - USB-C cable (upload_protocol = dfu) and PlatformIO to upload the firmware.
    ***********************
    WARNING! Method D was not working for me and I was not able to upload the firmware.
    ***********************


    First connect the Sipeed Longan Nano Development Board to computer using the USB cable.

    Connect Sipeed Longan Development Board to computer

    When the Sipeed Longan Nano Development Board is plugged into the computer using the USB-A - USB-C cable, Windows 10 pro does not detects the development board.
    You need to install a driver.

    There are two ways to install the driver:
    1. The easiest way: Install the GD32DfuDriver as described in method B.

    2. An elaborate way: Install a WinUSB driver as described herebelow.

    Please note: I have tried both methods (1 and 2) and in both cases I was not able to upload the firmware using PlatformIO.

  • It is important to follow this procedure in the correct order:

    • Goto https://zadig.akeo.ie, download and install Zadig.
      Zadig is a Windows application that installs generic USB drivers, such as WinUSB, libusb-win32/libus0_sys or libusbK.

      I downloaded Zadig 2.5 (zadig-2.5.exe) but not started it yet!

    • The Sipeed Longan Nano Development Board is connected to computer using the USB-A - USB-C cable. Set the Sipeed Longan Nano Development Board into download mode.

      • Press BOOT key and keep it pressed.
      • Shortly press and immediately release the RESET button.
      • Then release the BOOT button.

    • Start Windows Device Manager (devmgmt.msc).
      This is not required but it is useful to see what is happening.
      You will see "Unknown device".
      You may close or leave the Device Manager open.

      Windows Device Manager: Unknown device

    • Start the Zadig executable. Select in the Zadig toolbar: Options | List All Devices

      Zadig list devices

      In the bottom left corner you will see how many USB devices it has found.
      In this example there are 4 devices found.

      4 devices found

    • Select the EMPTY line. This represents the "Unknown Device".
      Make sure USB ID = 28E9 0189 otherwise it is not the correct USB device.
      Hardware ID USB\VID_28E9&PID_0189 is recognized as GD32 DFU Bootloader (Longan Nano).
      Vendor Id = 28e9 (GDMicroelectronics)
      Product Id = 0189 (GD32 DFU Bootloader, Longan Nano)
      USB Vendor/Device IDs Database: http://www.linux-usb.org/usb.ids

      Select Unknown device

    • Make the following changes:
      • Select WinUSB (vx.x.xxxx.xxxxx)
      • Enable Edit and enter an arbritrary name, for example: Sipeed Longan Nano
      • Press Install Driver button.

      Changes to unknown device

    • After the driver is installed, close the Zadig application. This application is not needed anymore.
      Lets verify if the WinUSB driver is installed.
      Start Windows Device Manager (devmgmt.msc)
      You will see it has detected an USB device but it is an "Unknown device".

      Windows Device Manager: Unknown device

    • Double click "Unknown device" and select tab Driver.
      You will see Driver Provider: libwdi

      Unknown device properties

    • Press button Driver details. WinUSB is installed.

      Show driver details

    • Select tab Details, you will see the name you have entered: Sipeed Longan Nano.

      Show driver details

  • The WinUSB driver is now installed and the Sipeed Longan Nano Development Board can now be detected.

    Modify the platformio.ini file and add the following line:
    upload_protocol = dfu

    Set the Sipeed Longan Nano Development Board into download mode:

    • Press BOOT key and keep it pressed.
    • Shortly press and immediately release the RESET button.
    • Then release the BOOT button.

  • Build and upload the Blink program to the development board.
    Terminal output (build): build_dfu_sipeed_longan_arduino_blink.txt
    Terminal output (upload): upload_dfu_sipeed_longan_arduino_blink.txt

  • Unfortunately I got several error messages during the upload:

    Found GD32VF103, which reports a bad page size and count for its internal memory.

    .. and ..

    Error during upload get_status
    *** [upload] Error 74

    I was not able to fixed this error. I abandon the use of the USB-A - USB-C cable to upload the firmware to the development board via PlatformIO. More information see: Issue raised at forum.seeedstudio.com