Longan Nano, le kit RISC-V à moins de 5$

Je viens de recevoir mon kit, voici donc une petite description du déballage du kit basé sur un microcontrôleur RISC-V GD32VF nommé Longan Nano.

Le kit est tout petit mais comporte quand même une LED tricolore, un écran LCD, des boutons, …

Pour accéder à l’usb (mode DFU) il faut laisser le bouton boot0 appuyé tout en branchant le kit. On obtient le message suivant :

$ dmesg
[896404.667425] usb 3-2: new full-speed USB device number 59 using xhci_hcd
[896404.808892] usb 3-2: New USB device found, idVendor=28e9, idProduct=0189
[896404.808895] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[896404.808896] usb 3-2: Product: GD32 0x418 DFU Bootloade
[896404.808897] usb 3-2: Manufacturer: GDMicroelectronics
[896404.808898] usb 3-2: SerialNumber: 䌳䩂

Surtout retenez bien le numéro de série 😉

Outils et développement

SiPeed indique comment développer sur son kit avec Visual Studio (Hé oui le truc tourne sous Linux !) et la plate-forme platform.io.

Il faut donc commencer par installer les outils Microsoft qui, à ma grande surprise, fonctionnent très bien sur debian (64bits) ! Ça me vexe un peu d’ailleurs, mais passons.

$ sudo dpkg -i /home/fabien/Téléchargements/code_1.39.2-1571154070_amd64.deb

  • Visual Studio se lance simplement avec la commande code (pas du tout prétentieux):

$ code

  • Pour installer le greffon platformio (pio pour les intimes) il faut faire une recherche dans les extensions et installer PlatformIO IDE. Et patienter un peu (1 à 2 minutes chez moi).
  • Pour configurer le bouzin pour la Longan Nano il suffit d’ouvrir une console dans l’outils (symbole platformio fourmi -> quick access -> New Terminal) puis de lancer la commande :

$ platformio platform install gd32v
PlatformManager: Installing gd32v
gd32v @ 1.1.0 has been successfully installed!
PackageManager: Installing toolchain-gd32v @ ~9.2.0
Downloading [####################################] 100%
Unpacking [####################################] 100%
toolchain-gd32v @ 9.2.0 has been successfully installed!
The platform ‘gd32v’ has been successfully installed!
The rest of packages will be installed automatically depending on your build environment.

  • Perso j’ai plutôt pris la version «à jour» github :
$ platformio platform install https://github.com/sipeed/platform-gd32v
  • Un guide est donné également pour faire clignoter la LED en rouge. Il faut néanmoins faire quelques modifications pour le téléchargement du programme dans le micro comme nous allons le voir.
  • Lancer l’exemple longan-nano-blink
  • Modifier le fichier platform.ini comme suivant :
[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
  • Ajouter les règles udev pour l’usb :

$ sudo vim /etc/udev/rules.d/90-longan-nano.rules

  • Avec la règle suivante (en supposant que votre utilisateur fait parti du groupe dialout depuis longtemps déjà).

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

  • Installer les outils DFU :

$ sudo apt-get install dfu-util

  • (Re-)Démarrer le kit en mode «bootstrap» en le branchant à l’USB du pc tout en restant appuyé sur le bouton «boot0». Une fois branché vous avez l’autorisation de lâcher le bouton 😉 Constater que le kit est bien présent sur l’usb :

$ sudo dfu-util -l
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=62, cfg=1, intf=0, path="3-1", alt=1, name="@Option Bytes /0x1FFFF800/01016 g", serial="??" Found DFU: [28e9:0189] ver=1000, devnum=62, cfg=1, intf=0, path="3-1", alt=0, name="@Internal Flash /0x08000000/512002Kg", serial="??"

$  sudo dfu-util -l
 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=62, cfg=1, intf=0, path="3-1", alt=1, name="@Option Bytes  /0x1FFFF800/01016 g", serial="??" Found DFU: [28e9:0189] ver=1000, devnum=62, cfg=1, intf=0, path="3-1", alt=0, name="@Internal Flash  /0x08000000/512002Kg", serial="??"
  • Compiler (le minuscule symbole de check en V en bas à gauche)
  • Télécharger (le minuscule symbole flèche juste à coté du minuscule symbole de compile)
> Executing task: platformio run --target upload <

Processing sipeed-longan-nano (platform: gd32v; framework: gd32vf103-sdk; board: sipeed-longan-nano)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PackageManager: Installing tool-openocd-gd32v @ ~0.1.1
Downloading  [####################################]  100%          
tool-openocd-gd32v @ 0.1.1 has been successfully installed!
PackageManager: Installing tool-gd32vflash @ ~0.1.0
tool-gd32vflash @ 0.1.0 has been successfully installed!
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: tool-openocd-gd32v 0.1.1, framework-gd32vf103-sdk 1.0.0, 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
Compiling .pio/build/sipeed-longan-nano/src/main.o
Compiling .pio/build/sipeed-longan-nano/src/systick.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_adc.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_bkp.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_can.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_crc.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_dac.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_dbg.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_dma.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_eclic.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_exmc.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_exti.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_fmc.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_fwdgt.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_gpio.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_i2c.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_pmu.o
/home/fabien/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Source/gd32vf103_i2c.c: In function 'i2c_flag_clear':
/home/fabien/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Source/gd32vf103_i2c.c:610:14: warning: variable 'temp' set but not used [-Wunused-but-set-variable]
  610 |     uint32_t temp;
      |              ^~~~
/home/fabien/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Source/gd32vf103_i2c.c: In function 'i2c_interrupt_flag_clear':
/home/fabien/.platformio/packages/framework-gd32vf103-sdk/GD32VF103_standard_peripheral/Source/gd32vf103_i2c.c:718:14: warning: variable 'temp' set but not used [-Wunused-but-set-variable]
  718 |     uint32_t temp;
      |              ^~~~
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_rcu.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_rtc.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_spi.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_timer.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_usart.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/Source/gd32vf103_wwdgt.o
Compiling .pio/build/sipeed-longan-nano/standard_peripheral/system_gd32vf103.o
Compiling .pio/build/sipeed-longan-nano/RISCV/drivers/n200_func.o
Compiling .pio/build/sipeed-longan-nano/RISCV/env_Eclipse/entry.o
Compiling .pio/build/sipeed-longan-nano/RISCV/env_Eclipse/handlers.o
Compiling .pio/build/sipeed-longan-nano/RISCV/env_Eclipse/init.o
Compiling .pio/build/sipeed-longan-nano/RISCV/env_Eclipse/start.o
Compiling .pio/build/sipeed-longan-nano/RISCV/env_Eclipse/your_printf.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/_exit.o
/home/fabien/.platformio/packages/framework-gd32vf103-sdk/RISCV/env_Eclipse/your_printf.c: In function '__wrap_printf':
/home/fabien/.platformio/packages/framework-gd32vf103-sdk/RISCV/env_Eclipse/your_printf.c:4:1: warning: control reaches end of non-void function [-Wreturn-type]
    4 | }
      | ^
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/close.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/fstat.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/isatty.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/lseek.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/read.o
Archiving .pio/build/sipeed-longan-nano/libstandard_peripheral.a
Indexing .pio/build/sipeed-longan-nano/libstandard_peripheral.a
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/sbrk.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/write.o
Compiling .pio/build/sipeed-longan-nano/RISCV/stubs/write_hex.o
Archiving .pio/build/sipeed-longan-nano/libRISCV.a
Indexing .pio/build/sipeed-longan-nano/libRISCV.a
Linking .pio/build/sipeed-longan-nano/firmware.elf
Checking size .pio/build/sipeed-longan-nano/firmware.elf
Building .pio/build/sipeed-longan-nano/firmware.bin
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
  • Et voilà ! La led clignote en rouge. Pour la passer en vert (par exemple) il faut changer le code de main.c:
/* BUILTIN LED OF LONGAN BOARDS IS PIN PC13
#define LED_PIN GPIO_PIN_13
#define LED_GPIO_PORT GPIOC
#define LED_GPIO_CLK RCU_GPIOC
*/

/* BUILTIN LED GREEN*/
#define LED_PIN BIT(1)
#define LED_GPIO_PORT GPIOA
#define LED_GPIO_CLK RCU_GPIOA

Le pinout de la LED RGB n’apparaît pas sur ce schéma

Ce contenu a été publié dans électronique, Non classé, avec comme mot(s)-clé(s) , , . Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *