Using USB to host computer <-> longan nano communication

Hi,

I just received my Longan Nano kit and plugged the usb wire on my Linux (debian) computer.

The kit is been powered and the RGB led is blinking. But I see nothing in Linux dmesg.

Does somebody know how to use USB protocol with the Longan Nano to establish communication between the board and a Linux computer ?

you need press boot button before insert usb, then it will come into DFU mode

1 Like

Thank Zepan, it works.
Have you a link on documentation about this DFU mode ?

Most of the operations are the same under Linux and Win using the PlatformIO IDE. You can refer to the Longan Wiki.

If you are not using the root user, you may need to add udev rules, refer to the PIO documentation.

Hi @Zepan,

I held the Boot button and “lsusb” showed a new device with no description:

Bus 001 Device 092: ID 28e9:0189

However, PlatformIO still can’t see it.

When I attach the SiSpeed RISC-V debugger PlatformIO sees the device, however, I can’t upload and I get the following error:

Processing sipeed-longan-nano (platform: gd32v; board: sipeed-longan-nano; framework: gd32vf103-sdk)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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.0.0 > Sipeed Longan Nano
HARDWARE: GD32VF103CBT6 108MHz, 32KB RAM, 128KB Flash
DEBUG: Current (altera-usb-blaster) External (altera-usb-blaster, gd-link, jlink, sipeed-rv-debugger, um232h)
PACKAGES: framework-gd32vf103-sdk 1.0.0, tool-openocd-gd32v 0.1.1, tool-gd32vflash 0.1.0, 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
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   7.0% (used 2310 bytes from 32768 bytes)
PROGRAM: [=         ]   5.0% (used 6572 bytes from 131072 bytes)
Configuring upload protocol...
AVAILABLE: altera-usb-blaster, gd-link, jlink, serial, sipeed-rv-debugger, um232h
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

Using Parser : Raw BINARY
Interface serial_posix: 115200 8E1

*** [upload] Error 1
======================================================================================== [FAILED] Took 1.31 seconds ========================================================================================
The terminal process terminated with exit code: 1

It keeps trying to use the STM flash:

Failed to init device.
stm32flash Arduino_STM32_0.9

I am confused because I have configured the .ini file:

[env:sipeed-longan-nano]

platform = gd32v

board = sipeed-longan-nano

framework = gd32vf103-sdk

; change microcontroller

board_build.mcu = GD32VF103CBT6

; change MCU frequency

board_build.f_cpu = 108000000L

; upload_protocol = sipeed-rv-debugger

Am I missing something?

Thanks.

Hi,
The usb interface on the board is directly connected to the GD32V chip, not the serial port transfer USB, so if you want to download the program, please choose DFU download.

You need add:
upload_protocol = dfu

1 Like

Thanks.

Where would I learn about these things? Is there a manual or site?

1 Like

@BigBits, @Zepan,

I switched my protocol to dfu but now I get a dfu util error:

Processing sipeed-longan-nano (platform: gd32v; board: sipeed-longan-nano; framework: gd32vf103-sdk)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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.0.0 > Sipeed Longan Nano
HARDWARE: GD32VF103CBT6 108MHz, 32KB RAM, 128KB Flash
DEBUG: Current (altera-usb-blaster) External (altera-usb-blaster, gd-link, jlink, sipeed-rv-debugger, um232h)
PACKAGES: framework-gd32vf103-sdk 1.0.0, tool-openocd-gd32v 0.1.1, tool-gd32vflash 0.1.0, 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
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   7.0% (used 2310 bytes from 32768 bytes)
PROGRAM: [=         ]   5.0% (used 6572 bytes from 131072 bytes)
Configuring upload protocol...
AVAILABLE: altera-usb-blaster, dfu, gd-link, jlink, 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-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
dfu-util: Invalid DFU suffix signature
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!

dfu-util: Cannot open DFU device 28e9:0189
dfu-util: No DFU capable USB device available
*** [upload] Error 74
======================================================================================== [FAILED] Took 0.28 seconds ========================================================================================
The terminal process terminated with exit code: 1

lsusb reports:

Bus 001 Device 097: ID 28e9:0189  
Bus 001 Device 098: ID 0403:6010 Future Technology Devices International, Ltd FT2232C/D/H Dual UART/FIFO IC

It seems like I must have the debugger plugged in otherwise nothing is recognized. I thought I could program it using just the USB connector and the RISC-V debug tool was for debugging.

I must be doing something wrong or missing something.

Argh! What am I missing???

Hi @Martoni, I see yours worked when you used DFU mode. What OS are you using and are you using the RISC-V debugger attachment as well?

I still can’t get mine to upload.

Thanks.

Hi @iPostHuman I managed to detect the board in kernel dmesg yes. But nothing more. I didn’t have time to do more.

Okay, thanks. I can detect too:

[50891.093247] usb 1-2.4.3: new full-speed USB device number 13 using xhci_hcd
[50891.195103] usb 1-2.4.3: New USB device found, idVendor=28e9, idProduct=0189, bcdDevice=10.00
[50891.195108] usb 1-2.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[50891.195112] usb 1-2.4.3: Product: GD32 0x418 DFU Bootloade
[50891.195115] usb 1-2.4.3: Manufacturer: GDMicroelectronics
[50891.195117] usb 1-2.4.3: SerialNumber: 䌳䩂

But that is all I can do. :disappointed:

I had similar issues on Ubuntu 18.10. I installed dfu-util:
sudo apt-get install dfu-util
and was able to use this to see the device as root (making sure to hold down boot when plugging into usb):
sudo dfu-util -l
To see what usb device dfu-util was using I used:
sudo strace -e trace=openat dfu-util -l
which shows something like:


openat(AT_FDCWD, “/dev/bus/usb/001/008”, O_RDWR|O_CLOEXEC) = 9`
Found DFU: [28e9:0189] ver=1000, devnum=8, cfg=1, intf=0, path=“1-8”, alt=1, name="@Option Bytes /0x1FFFF800/01016 g", serial="??"
Found DFU: [28e9:0189] ver=1000, devnum=8, cfg=1, intf=0, path=“1-8”, alt=0, name="@Internal Flash /0x08000000/512
002Kg", serial="??"
+++ exited with 0 +++

I then ran (with the platformio.ini change of upload_protocol = dfu):

sudo chown $USER /dev/bus/usb/001/008
platformio run --target upload

which yielded:

Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: …
PLATFORM: GigaDevice GD32V 1.1.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-gd32vf103-sdk 1.0.0, tool-openocd-gd32v 0.1.1, tool-gd32vflash 0.1.0, toolchain-
gd32v 9.2.0
LDF: Library Dependency Finder -> …
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies…
No dependencies
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA: [= ] 7.0% (used 2310 bytes from 32768 bytes)
PROGRAM: [= ] 5.0% (used 6572 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.
dfu-util: Invalid DFU suffix signature
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to …

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
GD32 flash memory access detected
Device model: GD32VF103CB
Memory segment (0x08000000 - 0801ffff)(rew)
Erase size 1024, page count 128
Downloading to address = 0x08000000, size = 6584

Download [ ] 0% 0 bytes
Download [======= ] 31% 2048 bytes
Download [=============== ] 62% 4096 bytes
Download [======================= ] 93% 6144 bytes
Download [=========================] 100% 6584 bytes
Download done.
File downloaded successfully
dfu-util: dfuse_download: libusb_control_transfer returned -4
*** [upload] Error 74
==================================== [FAILED] Took 2.37 seconds ====================================

Despite failing the device is running the example LED flash program, which I confirmed by tweaking the blink frequency.

@irogers I tryied to follow your step by step procedure, but I got dfu suffix signature error:

 Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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.1.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-gd32vf103-sdk 1.0.0, tool-openocd-gd32v 0.1.1, tool-gd32vflash 0.1.0, 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
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   7.0% (used 2310 bytes from 32768 bytes)
PROGRAM: [=         ]   5.0% (used 6572 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-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/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
dfu-util: Cannot open DFU device 28e9:0189
dfu-util: No DFU capable USB device available

With this platformio ini file :

[env:sipeed-longan-nano]
platform = gd32v
framework = gd32vf103-sdk
board = sipeed-longan-nano
monitor_speed = 115200

; change microcontroller
board_build.mcu = GD32VF103CBT6

; change MCU frequency
board_build.f_cpu = 108000000L

; upload_protocol = sipeed-rv-debugger

upload_protocol = dfu

And udev config file installed.

Ok I fixed my problem.

It was a udev problem, the udev file given by platform.io does not include the longan nano number. Then I added the following line to my udev file : /etc/udev/rules.d/99-platformio-udev.rules

# Longan Nano
ATTRS{idVendor}=="28e9", ATTRS{idProduct}=="0189", MODE="0666"    

And that works now :

> Executing task in folder 191018-160134-longan-nano-blink: platformio run --target upload <

Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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.1.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-gd32vf103-sdk 1.0.0, tool-openocd-gd32v 0.1.1, tool-gd32vflash 0.1.0, 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
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   7.0% (used 2310 bytes from 32768 bytes)
PROGRAM: [=         ]   5.0% (used 6572 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: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
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/

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
GD32 flash memory access detected
Device model: GD32VF103CB
Memory segment (0x08000000 - 0801ffff)(rew)
Erase size 1024, page count 128
Downloading to address = 0x08000000, size = 6584

Download        [                         ]   0%            0 bytes
Download        [=======                  ]  31%         2048 bytes
Download        [===============          ]  62%         4096 bytes
Download        [=======================  ]  93%         6144 bytes
Download        [=========================] 100%         6584 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state

Yeah that fixed mine as well, but I also had to do a full-hard-reboot to get the new rules. Re-triggering didn’t seem to work on my linux machine.

Finally I was able to upload the blink example. :partying_face:

Hi iPostHuman
Can you post the file “firmware.bin” for upload in my longan Nano, please?
Thanks

Having bought a Sipeed Longan Nano RISC-V GD32VF103CBT6 MCU Development Board, I have installed Visual Studio Code with platformio add-on. Drivers GD32 MCU Dfu Drivers_v1.0.1.2316 for Windows 10.
Mention here the platformio.ini lines:
[env:sipeed-longan-nano]
platform = gd32v
framework = arduino
board = sipeed-longan-nano
monitor_speed = 115200
upload_protocol = dfu

The board was set in burning mode: the Device Manager shows in USB devices: GD32 Device in DFU mode. Download, with messages:
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
GD32 flash memory access detected
Device model: GD32VF103C8
Memory segment (0x08000000 - 0800ffff)(rew)
Erase size 1024, page count 64
Downloading to address = 0x08000000, size = 8268
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

Now comes the question: After Reset, NO sign of blink (the factory 4 colors blink went off). Moreover the display went dark.
Being the first time I try to use this board, I would appreciate a suggestion to make work the first code!

What firmware are you trying to upload? Is this the Arduino Blink example? My guess is that everything is correct in your environment. The display goes dark because this example does not address it. Look careful at the LED. In my case it was blinking but at a much lower frequency than expected. Try to reduce the parameter in delay() function to a lower value like 100. Look at this thread here: https://bbs.sipeed.com/t/topic/1551. There is reported that the delay() function has a bug, so it may be that the frequency is so low that it appears to be off all the time. Could this be the cause?

1 Like

Thank you mouseclicker! I was very frustrated to see the nice Longan not working. I looked in all available information sources, and now it works! The problem was my Longan, bought from a company found on Ali Express: my model is C8T6 and has 64KB Flash, 20KB SRAM. The solution is to change in platformio.ini : board = sipeed-longan-nano-lite. I hope this helps others too!

Thanks, changing “board” to “sipeed-longan-nano-lite” and shortening delay makes my Longan blinking.

According to AliExpress order my board should be CBT6 (item 4000349399843) with 128KB Flash/32KB RAM, but chip under the glued display says C8T6…