Sipeed Longan Nano on Linux Mint 20.1

Hi, I am having problems trying to program the Sipeed Longan Nano.

My operating system is Linux Mint 20.1 Cinnamon.

Steps I have done so far: -

  1. Install Visual Studio Code
    Download “code_1.54.3-1615806378_amd64.deb”
    sudo apt install ./code_1.54.3-1615806378_amd64.deb
  2. Install Python 3 virtual environment
    sudo apt-get install python3-venv
  3. Install PlatformIO
    Use extensions in Visual Studio Code
  4. Create a new project
    Board Sipeed Longan Nano
    Framework Arduino
  5. Code in “main.cpp”
#include <Arduino.h>

void setup() {
  pinMode(PC13, OUTPUT);
  pinMode(PA1,  OUTPUT);
  pinMode(PA2,  OUTPUT);
}

void loop() {
  digitalWrite(PC13, HIGH);
  digitalWrite(PA1,  HIGH);
  digitalWrite(PA2,  HIGH);
  delay(1000);
  digitalWrite(PC13, LOW);
  digitalWrite(PA1,  LOW);
  digitalWrite(PA2,  LOW);
  delay(1000);
}
  1. Contents of “platform.ini”
[env:sipeed-longan-nano]
platform = gd32v
board = sipeed-longan-nano
framework = arduino
upload_protocol = dfu
  1. Connect Sipeed Longan Nano via USB & program
    Boot → Reset → Boot
    Program (Click program arrow)
    Message → Tool Manager: Installing tool-openocd-gd32v @ ~0.1.1
  2. Terminal output
> Executing task in folder Longan1: platformio run --target upload <

Processing sipeed-longan-nano (platform: gd32v; board: sipeed-longan-nano; framework: arduino)
----------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/pa1ge/boards/gd32v/sipeed-longan-nano.html
PLATFORM: GigaDevice GD32V (1.2.0) > Sipeed Longan Nano
HARDWARE: GD32VF103CBT6 108MHz, 32KB RAM, 128KB Flash
DEBUG: Current (altera-usb-blaster) External (altera-usb-blaster, gd-link, jlink, rv-link, sipeed-rv-debugger, um232h)
PACKAGES:
- framework-arduino-gd32v 0.1.1
- tool-dfuutil 1.9.200310
- tool-gd32vflash 0.1.0
- tool-openocd-gd32v 0.1.1
- toolchain-gd32v 9.2.0
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 7.2% (used 2358 bytes from 32768 bytes)
Flash: [= ] 6.3% (used 8250 bytes from 131072 bytes)
Configuring upload protocol...
AVAILABLE: altera-usb-blaster, dfu, gd-link, jlink, rv-link, serial, sipeed-rv-debugger, um232h
CURRENT: upload_protocol = dfu
Uploading .pio/build/sipeed-longan-nano/firmware.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2020 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/[/code]

dfu-util: Cannot open DFU device 28e9:0189
dfu-util: No DFU capable USB device available
*** [upload] Error 74
======================== [FAILED] Took 0.58 seconds ========================
The terminal process "platformio 'run', '--target', 'upload'" terminated with exit code: 1.
  1. Update “udev rules”
    curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
  2. Restart udev server
    sudo service udev restart
  3. Program Sipeed Longan Nano via USB
    Boot → Reset → Boot
    Program (Click program arrow)
  4. Terminal output
> Executing task in folder Longan1: platformio run --target upload <

Processing sipeed-longan-nano (platform: gd32v; board: sipeed-longan-nano; framework: arduino)
----------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/gd32v/sipeed-longan-nano.html
PLATFORM: GigaDevice GD32V (1.2.0) > Sipeed Longan Nano
HARDWARE: GD32VF103CBT6 108MHz, 32KB RAM, 128KB Flash
DEBUG: Current (altera-usb-blaster) External (altera-usb-blaster, gd-link, jlink, rv-link, sipeed-rv-debugger, um232h)
PACKAGES:
 - framework-arduino-gd32v 0.1.1
 - tool-dfuutil 1.9.200310
 - tool-gd32vflash 0.1.0
 - tool-openocd-gd32v 0.1.1
 - toolchain-gd32v 9.2.0
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.2% (used 2358 bytes from 32768 bytes)
Flash: [=         ]   6.3% (used 8250 bytes from 131072 bytes)
Configuring upload protocol...
AVAILABLE: altera-usb-blaster, dfu, gd-link, jlink, rv-link, serial, sipeed-rv-debugger, um232h
CURRENT: upload_protocol = dfu
Uploading .pio/build/sipeed-longan-nano/firmware.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2020 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
ID 28e9:0189
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
Found GD32VF103, which reports a bad page size and count for its internal memory.
Fixed layout based on part number: page size 1024, count 64.
Downloading to address = 0x08000000, size = 8268

Erase           [                         ]   0%            0 bytes
Erase           [======                   ]  24%         2048 bytes
Erase           [============             ]  49%         4096 bytes
Erase           [==================       ]  74%         6144 bytes
Erase           [======================== ]  99%         8192 bytes
Download        [                         ]   0%            0 bytes
Download        [======                   ]  24%         2048 bytes
Download        [============             ]  49%         4096 bytes
Download        [==================       ]  74%         6144 bytes
Download        [======================== ]  99%         8192 bytes
Download        [=========================] 100%         8268 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state
======================= [SUCCESS] Took 2.68 seconds =======================
  1. LEDs do not blink, also “bad page size…”
  2. In a terminal install DFU utility
    sudo apt install dfu-util
  3. Program via new DFU utility in a terminal
    Boot → Reset → Boot
    sudo dfu-util -a 0 -s 0x08000000:leave -D firmware.bin
  4. Terminal output
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Match vendor ID from file: 28e9
Match product ID from file: 0189
Opening DFU capable USB device...
ID 28e9:0189
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash "
Downloading to address = 0x08000000, size = 8268
Download [=========================] 100% 8268 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state
  1. LEDs do not blink, but no message about “bad page size…”
  2. List USB devices
    Boot → Reset → Boot
    lsusb
Bus 001 Device 013: ID 28e9:0189 GDMicroelectronics GD32 0x418 DFU Bootloade
  1. DFU utility list
    Boot → Reset → Boot
    sudo dfu-util --list
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [28e9:0189] ver=1000, devnum=14, cfg=1, intf=0, path="1-3", alt=1, name="@Option Bytes /0x1FFFF800/01*016 g", serial="??"
Found DFU: [28e9:0189] ver=1000, devnum=14, cfg=1, intf=0, path="1-3", alt=0, name="@Internal Flash /0x08000000/512*002Kg", serial="??"

What do I need to change / do to get the Sipeed Longan Nano to program and get a blinking LED working? Thanks…

:sleepy:

There’s a mentiond of that in GitHub - riscv-rust/longan-nano: Board support package for the Longan Nano board.

First of all, are you sure you have that version with the chip that reads GD32VF103CBT6 on it or the “Lite” version with a GD32VF103C8T6?

Does pressing the reset button on the board after an upload make a difference?

Does the official longan-nano-blink example that is based on a different framework behave the same?

Addendum: There also seems to be an issue open about it at Example programs don't run when using dfu download · Issue #17 · sipeed/platform-gd32v · GitHub.

1 Like

Hi, thanks for the response.

You are correct, although the listing on AliExpress stated it was a GD32VF103CBT6, it was in fact a GD32VF103C8T6… and to my eyes the small ‘8’ looks too much like a ‘B’.

So, changing the board from “sipeed-longan-nano” to “sipeed-longan-nano-lite” allowed me to upload the code, and it works, the LEDs blink (this is programming within PlatformIO).

However, I still get the “bad page size…” error, although it still seems to program.

When I repeat steps 14-17 from the original post, it programs without error, and again the LEDs blink (This is programming from the standard terminal within Linux Mint).

Is there a way I can configure PlatformIO to use the working & error free DFU utility and command line?

Thanks…

A bug report for that has already been opened in fact at dfu-util Error: 74 -- please update dfu-util · Issue #30 · sipeed/platform-gd32v · GitHub. I’ll bump the issue.

Yes, there are two ways:

  • find the folder ~/.platformio/packages/tool-dfuutil and replace the files with the good version (but retain the `package.json). This fixes it globally.
  • create a new tool-dfuutil package (a copy of the beforementioned folder but with updated files) at some place on the harddrive and link to it using platform_packages = file://<path to fixed dfu folder> in the platformio.ini. This is a per-project fix.

Thanks, that worked perfectly…

So, to complete this thread… and maybe assist others with the same issue…

On Linux Mint 20.1

I renamed the 4 files in this folder (to prevent losing them when copying): -
/home/USER/.platformio/packages/tool-dfuutil/bin

Then copied…
dfu-prefix
dfu-suffix
dfu-tool
dfu-util
From: /usr/bin
To: /home/USER/.platformio/packages/tool-dfuutil/bin

Thank you maxgerhardt for your help… my next step is setting up the Sipeed USB-JTAG…

:smiley: