Setting up the PIO IDE for Sipeed Longan Nano in Windows 10

Last month I joined this awesome project, aimed at developing the future European RISC-V processors with hardware accelerators, with applications in mind such as genomic analysis, cryptography or supercomputing. I thought that it would be cool to have a physical platform at home to get introduced to RISC-V and to run benchmarks on future optimizations of crypto primitives. So I came across Sipeed’s Longan Nano, an inexpensive (5€) dev board with a RISC-V 32-bit core, which also comes with an integrated 0.96inch 160×80 IPS RGB LCD.


Sipeed have put up a detailed set of instructions to be able to flash the device over USB (using the DFU mode), but I’ve been unsuccessful with those in all sorts of ways:

  • Zadig/libusb wizard wouldn’t show the device, or wouldn’t install the drivers
  • The device wasn’t detected by PIO with drivers other than libusb/WinUSB
  • dfu-util.exe didn’t flash the device properly, resulting in a black screen
  • *** [upload] Error 309
  • error during download get_status
  • “[upload] Error 123”
  • #error “Can’t get no sleep! Please report”
  • Cannot open DFU device 28e9:0189
  • Error 0xc000007b when calling dfu-util.exe

One can easily use the GD34 MCU Tool and Drivers to flash the device with the firmware.bin file in {project_folder}\.pio\build\sipeed-longan-nano, but then you can forget about the one-click upload and debugging capabilities of the VSC/PlatformIO IDE, and prepare to waste long hours flashing this little gem again and again with the GD34 MCU tool. What a nightmare.

As of April 2020 (in a Windows 10 64-bit v10.0.18362 machine), I’ve succeeded with the setup process following the next steps:

  1. Install VSC and PlatformIO
  2. Manually install the WinUSB driver (libusb) without a certificate
  3. Compile the latest version of dfu-util.exe using msys2/mingw (with libusb statically linked) and replace the version in the PIO directory

1. Install VSC and PlatformIO

Follow the instructions here to install the VSC IDE and the PIO plugin.

2. Install the WinUSB driver

Time to plug in your Longan Nano over USB and enter DFU mode (keep BOOT pressed, press RESET and release).

The official instructions point to Zadig to install the libusb drivers. You could also try installing libusb by other means, but I was unsuccessful with them. Instead, manually installing WinUSB worked like a charm. You can download WinUSB in:

Then you’ll have to modify the libusb_device.inf file before installing the driver. Here is the configuration I used:

  • DeviceName = “Longan Nano”
  • VendorID = “Sipeed”
  • ProductID = “PID_gd32vf103”
  • DeviceGUID = “{66bfb811-3c88-48f4-a124-e19b61f42586}”
  • DeviceClassGUID = “{78a1c341-4539-11d3-b88d-00c04fad5171}”
  • Date = “04/07/2020”

For the DeviceGUID parameter, you should generate your own GUID (.GUID is a great app for this IMO). Also, I don’t know if this step is really necessary, but you may have to edit the registry. Look for HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_28E9&PID_0189\{your_device}\Device Parameters (if there are many devices under VID_28E9&PID_0189, pick the last one or check which one is yours by uninstalling it in the Device Manager, looking at regedit, and then reconnecting it). Add a string REG_SZ register with name DeviceInterfaceGUID and a REG_MULTI_SZ register with name DeviceInterfaceGUIDs, and your GUID as the value. And you’re done with the registry tinkering.

Then, go to Device Manager (hit Ctrl+X -> Device Manager), right click your device, select Update Driver, and go through the usual drill to manually select your libusb_device.inf file to install the driver. Your Longan Nano should then appear under “libusb (WinUSB) devices”.

3. Install the current version of dfu-util

As noted in, the latest released version (v0.9) of dfu-utils has a bug (fixed by Thomas Hebb) that prevents dfu-util to fully upload the firmware.bin file in your project folder. Hence, you will need to locally compile the latest version of dfu-util from git.

You can follow the instructions in, but with a few caveats:

  1. Download and compile the current version of libusb (as of now, 1.0.23), instead of version 1.0.20.
  2. Run the “pacman -Syu”, the “-pacman -Su”, and the make commands as many times as it takes until all packages have been installed and all objects created (that is, more than once, even after closing msys2).
  3. Replace all relative paths (“$PWD/…”) in the PKG_CONFIG_PATH assignments with absolute paths (“/c/Users/…”).
  4. When compiling dfu-util, link libusb statically into dfu-util.exe using “make LDFLAGS=-static”, not “make”.

When you’re done following these instructions, rename dfu-util-static.exe to dfu-util.exe, and paste it to C:\Users\{your_username}\.platformio\packages\tool-gd32vflash (possibly along with dfu-prefix.exe and dfu-suffix.exe). Now you should be able to build and upload a sample project in VSC/PIO.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s