The Longan Nano is a new contestor in the area of affordable RISC-V development boards. The Longan Nano’s form factor and price puts it up against the Arduino Nano and all other varieties of STM32-based “nano boards”, which can be found abundantly on Ebay and AliExpress.
The Longan Nano features a GigaDevices GD32VF103CBT6 core running at 108 MHz with 32KB SRAM and 128KB flash.
The Longan Nano comes with a small 160×80 pixel LCD glued on top of the board and a practical plastic case. Really no reason to complain for just 5 $. More details in the datasheet.
Longan Nano top Longan Nano bottom
The first requirement is to install PlatformIO. The command line tools of platformio are sufficient. I will assume the OS as Ubuntu 18.04 in the following.
$> pip3 install platformio
To get a feeling for the versatility of PlatformIO let’s list the supported boards:
$> python3 -m platformio boards ... (lots of boards)
Now let’s only look at the boards of interest, to see if the Longan Nano is supported at all:
$> python3 -m platformio boards | grep GD32 gd32vf103v-eval GD32VF103VBT6 108MHz 128KB 32KB GD32VF103V-EVAL sipeed-longan-nano GD32VF103CBT6 108MHz 128KB 32KB Sipeed Longan Nano wio_lite_risc-v GD32VF103CBT6 108MHz 128KB 32KB Wio Lite RISC-V
Next create a project directory for the Longan Nano and initialize a platformio project:
$> mkdir longan_nano $> cd longan_nano $> python3 -m platformio init $> ls include lib platformio.ini src test
Have a look at some information about our platform:
$> python3 -m platformio platform search gd32v
gd32v ~ GigaDevice GD32V
The GigaDevice GD32V device is a 32-bit general-purpose microcontroller based on the RISC-V core with an impressive balance of processing power, reduced power consumption and peripheral set.
Home: http://platformio.org/platforms/gd32v
Frameworks: arduino, gd32vf103-sdk
Packages: framework-gd32vf103-sdk, framework-arduino-gd32v, tool-openocd-gd32v, tool-gd32vflash, toolchain-gd32v
Before a build can be run some minimum viable source code is required. It is sufficient to put an empty main function into the src folder like so:
$> echo 'int main(int argc, char* argv[]) { return 0; }' > ./src/main.c
Now the project can be run for the first time to make platformio install requires packages and other dependency stuff:
$> python3 -m platformio run Processing sipeed-longan-nano (platform: gd32v; framework: gd32v103f-sdk; board: sipeed-longan-nano) PlatformManager: Installing gd32v ... Error: This board doesn't support gd32v103f-sdk framework!
Oops! What’s going on here? The content of platformio.ini is copied from Sipeed’s example page, so why isn’t it working?
Well, as so often human error is the cause of this catastrophe. Fix the framework defined in platformio.ini like so:
framework = gd32vf103-sdk
Repeat the failing step from before:
$> python3 -m platformio run Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano) ... Building .pio/build/sipeed-longan-nano/firmware.bin ================================ [SUCCESS] Took 2.50 seconds ==========================
Success! An empty project has been built, oh the accomplishment! Well at least the toolchain seems to work.
Just for fun the empty program can be uploaded to the Longan Nano board to see that the LED stops blinking (i.e. overwrite the preloaded example design).
To load a program to the Longan Nano it must be properly recognized as a USB device by Ubuntu. This is achieved by pressing and holding down the BOOT button and then pressing the RESET button (while still holding the BOOT button). After the RESET button has been pressed and released the BOOT button can also be released. This is the official way to do it, but may only yield the expected result after several attempts. I could be wrong, but for me it seemed to work quite nicely to unplug the Longan Nano, then hold down the BOOT button and plug the board back in (while still holding the BOOT button).
An unnamed USB device should appear in Linux:
$> lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 004: ID 28e9:0189 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Next a USB-serial adapter (3.3V) is required. Check that platformio does recognize the adapter:
$> sudo python3 -m platformio device list
/dev/ttyUSB0
Hardware ID: USB VID:PID=0403:6001 SER=00000000 LOCATION=1-3
Description: FT232R USB UART
OK, one step back, it turns out the upload_protocol = serial
part is not what I thought it was and only works with the Arduino framework.
$> sudo python3 -m platformio run --target upload Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano) ... CURRENT: upload_protocol = serial Looking for upload port… Auto-detected: /dev/ttyUSB0 Uploading .pio/build/sipeed-longan-nano/firmware.bin Failed to init device. stm32flash Arduino_STM32_0.9 http://github.com/rogerclarkmelbourne/arduino_stm32 *** [upload] Error 1 Using Parser : Raw BINARY Interface serial_posix: 115200 8E1 ================================= [FAILED] Took 1.88 seconds ==========================
So that didn’t work.
The next alternative is to use dfu-util
which is easily available via apt:
$> sudo apt install dfu-util
Subsequently change the upload_protocol in platformio.ini:
upload_protocol = dfu
Repeat the upload step from before:
$> sudo python3 -m platformio run --target upload Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano) ... Download [=========================] 100% 6584 bytes Download done. File downloaded successfully dfu-util: dfuse_download: libusb_control_transfer returned -9 *** [upload] Error 74 ================================= [FAILED] Took 2.71 seconds =========================
There is still an error showing at the end, but this one can be ignored (not sure why, but it does work despite of the error). After uploading a new program the Longan Nano has to be reset manually by pressing the RESET button. The Longan Nano should no longer blink it’s RGB LED, but instead remain dark and silent. Yippie?
Since this result is somewhat unsatisfying let’s load the official blinky example to bring the Longan Nano back to light. Get the sources from github (just clone the whole project) and descend into the example directory of interest, then build and upload the longan-nano-blink example.
$> git clone https://github.com/sipeed/platform-gd32v $> cd ./platform-gd32v/examples/longan-nano-blink $> sudo python3 -m platformio run --target upload Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano) ... Download [=========================] 100% 6584 bytes Download done. File downloaded successfully dfu-util: dfuse_download: libusb_control_transfer returned -9 *** [upload] Error 74 ================================= [FAILED] Took 2.91 seconds ==========================
After pressing the RESET button the Longan Nano does start blinking it’s RGB LED again, using only the red color. Success!

In case at any point the messagedfu-util: No DFU capable USB device available
appears this means your host machine dropped the USB device corresponding to the Longan Nano for some reason. Try to connect it again with the BOOT and RESET button combo described above.
And that concludes the first steps with the Longan Nano. See you next time.
References:
- https://longan.sipeed.com/en/get_started/blink.html
- https://docs.platformio.org/en/latest/core.html
- https://docs.platformio.org/en/latest/boards/gd32v/sipeed-longan-nano.html
- https://bbs.sipeed.com/t/topic/1338/4
- https://github.com/sipeed/platform-gd32v/issues/10
- http://dl.sipeed.com/LONGAN/Nano/DOC
1 Pingback