Skip to content

Sipeed Longan Nano

Support for the Sipeed Longan Nano board @author Gunar Schorcht gunar@schorcht.net

\section sipeed_longan_nano Sipeed Longan Nano

Overview

The Sipeed Longan Nano is a development board for the GigaDevice GD32VF103CBT6 MCU with the following on-board components:

  • GD32VF103CBT6 RISC-V MCU @108MHz
  • USB Type C
  • TF card slot
  • 3 user LEDs
  • 0.96” TFT display 160 x 80 pixel (optional)

Sipeed Longan Nano

Hardware

MCUGD32VF103CBT6Supported
FamilyRISC-V with ECLIC
VendorGigaDevice
RAM32 kByte
Flash128 KByte
Frequency108 MHz
Power Modes3 (Sleep, Deep Sleep, Standby)yes
GPIOs37yes
Timers5 x 16-bit timeryes
RTC1 x 32-bit counter, 20-bit prescaleryes
WDT2 x 12-bit counter, 3-bit prescaleryes
ADC2 x 12-bit units, 16 channels @ 1 Mspsyes
DAC2 x 12-bit channelyes
UART-yes
USART3yes
SPI3yes
I2C2 x Fast Mode 400 kHzyes
I2S2no
CAN2 x CAN 2.0B with up to 1 Mbpsno
PWM6 Channelsyes
USB1 x USB FS OTGyes
Vcc3.0V - 3.6V
DatasheetDatasheet
Reference ManualReference Manual
Board ManualBoard Manual
Board SchematicBoard Schematic

Pin Layout / Configuration

The general pin layout is shown below.

Sipeed Longan Nano Pinout

The following tables show the connection of the on-board components with the MCU pins and their configuration in RIOT sorted by RIOT peripherals and by pins.

RIOT PeripheralMCU PinMCU PeripheralBoard FunctionRemark
ADC_LINE(0)PA0ADC01_IN0
ADC_LINE(1)PA3ADC01_IN3
ADC_LINE(2)-ADC01_IN16internal Temperature channel
ADC_LINE(3)-ADC01_IN17internal VFEF channel
ADC_LINE(4)*PA4ADC01_IN4N/A if DAC is used
ADC_LINE(5)*PB0ADC01_IN8TFT RSN/A if TFT is used
ADC_LINE(6)*PB1ADC01_IN9TFT RSTN/A if TFT is used
ADC_LINE(7)*PA6ADC01_IN6N/A if TFT/SPI_DEV(1) is used
ADC_LINE(8)*PA7ADC01_IN7N/A if TFT/SPI_DEV(1) is used
ADC_LINE(9)*PA5ADC01_IN5N/A if TFT/SPI_DEV(1)/DAC used
BTN0PA8BOOT0BOOT
DAC_LINE(0)PA4DAC0
DAC_LINE(1)*PA5DAC1N/A if TFT is used
GPIO_PIN(1, 2)PB2TFT CS
I2C_DEV(0) SCLPB6I2C0 SCL
I2C_DEV(0) SDAPB7I2C0 SDA
I2C_DEV(1) SCLPB10I2C1 SCL
I2C_DEV(1) SDAPB11I2C1 SDA
LED0PC13LED red
LED1PA1LED green
LED2PA2LED blue
PWM_DEV(0) CH0PA1LED green
PWM_DEV(0) CH1PA2LED blue
PWM_DEV(1) CH0*PB8N/A if CAN is used
PWM_DEV(1) CH1*PB9N/A if CAN is used
SPI_DEV(0) CSPB12SPI1 CSSD CS
SPI_DEV(0) SCLKPB13SPI1 SCLKSD SCK
SPI_DEV(0) MISOPB14SPI1 MISOSD MISO
SPI_DEV(0) MOSIPB15SPI1 MOSISD MOSI
SPI_DEV(1) CSPB5SPI0 CS
SPI_DEV(1) SCLKPA5SPI0 SCLKTFT SCL
SPI_DEV(1) MISOPA6SPI0 MISO
SPI_DEV(1) MOSIPA7SPI0 MOSITFT SDA
UART_DEV(0) TXPA9USART0 TXUART TX
UART_DEV(0) RXPA10USART0 RXUART RX

(*) The availability of these peripherals depend on the use of other peripherals.

\n Note: For the Sipeed Longan Nano board version with TFT display, the sipeed-longan-nano-tft board definition has to be used.

BOARD=sipeed-longan-nano-tft make ...
PinBoard FunctionRIOT Function 1RIOT Function 2RIOT Function 3
PA0ADC_LINE(0)
PA1LED greenPWM_DEV(0) CH0LED0
PA2LED bluePWM_DEV(0) CH1LED1
PA3ADC_LINE(1)
PA4ADC_LINE(4)*DAC_LINE(0)
PA5TFT SCLSPI_DEV(1) SCLKADC_LINE(9)*DAC_LINE(1)*
PA6SPI_DEV(1) MISOADC_LINE(7)*
PA7TFT SDASPI_DEV(1) MOSIADC_LINE(8)*
PA8BOOTBTN0
PA9UART_DEV(0) TX
PA10UART_DEV(0) RX
PA11USB D-
PA12USB D+
PA13JTAG TMS
PA14JTAG TCK
PA15JTAG TDI
PB0TFT RSADC_LINE(5)*
PB1TFT RSTADC_LINE(6)*
PB2TFT CS
PB3JTAG TDO
PB4JTAG NRST
PB5SPI_DEV(1) CS
PB6I2C_DEV(0) SCL
PB7I2C_DEV(0) SDA
PB8PWM_DEV(1) CH0
PB9PWM_DEV(1) CH1
PB10I2C_DEV(1) SCL
PB11I2C_DEV(1) SDA
PB12SD CSSPI_DEV(0) CS
PB13SD SCKSPI_DEV(0) SCLK
PB14SD MISOSPI_DEV(0) MISO
PB15SD MOSISPI_DEV(0) MOSI
PC13LED redLED2
PC14OSC32IN
PC15OSC32OUT
-TemperatureADC_LINE(2)
-VREFADC_LINE(3)

(*) The availability of these peripherals depend on the use of other peripherals.

Note: Since the availability of ADC_LINE(4) to ADC_LINE(9) depends on other peripheral configurations, their index may vary.

Flashing the Device

Using the DFU bootloader

The board is flashed via the in-ROM DFU bootloader by default. To enter bootloader mode, hold the BOOT0 button while pressing the RESET button.

BOARD=sipeed-longan-nano make -C examples/basic/hello-world flash

After flashing you need to leave bootloader mode again by pressing the RESET button.

Note: For the Sipeed Longan Nano board version with TFT display, the sipeed-longan-nano-tft board definition has to be used.

BOARD=sipeed-longan-nano-tft make -C examples/basic/hello-world flash

Using an external debug adapter

The board can also be flashed via a JTAG interface with OpenOCD (at least release version 0.12.0). By default, an FTDI adapter according to the configuration defined in interface/openocd-usb.cfg is assumed.

PROGRAMMER=openocd BOARD=sipeed-longan-nano make -C examples/basic/hello-world flash

To use an FTDI adapter with a different configuration, the configuration can be defined using the variable OPENOCD_FTDI_ADAPTER, for example:

PROGRAMMER=openocd OPENOCD_FTDI_ADAPTER=tigard BOARD=sipeed-longan-nano make -C examples/basic/hello-world flash

If another adapter is used, it can be specified using variable OPENOCD_DEBUG_ADAPTER, for example for a Segger J-Link adapter:

PROGRAMMER=openocd OPENOCD_DEBUG_ADAPTER=jlink BOARD=sipeed-longan-nano make -C examples/basic/hello-world flash

Using the TFT Display

To use the display of the Sipeed Longan Nano board version with TFT display, the sipeed_longan_nano_tft board definition has to be used, for example:

BOARD=sipeed-longan-nano-tft make -C tests/drivers/st7735 flash

Accessing STDIO

By default, the stdio is provided by the USBUS CDC ACM module stdio_cdc_acm. This interface is mapped to /dev/ttyACM<n> on a Linux host, where <n> is the index of the CDC ACM interface, which is 0 by default.

To use the first UART interface for stdio instead, the stdio_uart module has to be enabled:

USEMODULE=stdio_uart BOARD=sipeed-longan-nano make -C examples/basic/hello-world flash

The stdio is then directly accessible through the first UART interface. If an external USB-to-UART interface is used, this interface is mapped to /dev/ttyUSB<n> on a Linux host, where <n> is the index of the UART interface, which is 0 by default.

Use the term target to connect to the board using /dev/ttyUSB0:

BOARD=sipeed-longan-nano make -C examples/basic/hello-world term PORT=/dev/ttyUSB0

If the UART interface index of the USB-to-UART interface is not 0, use the following command to connect:

BOARD=sipeed-longan-nano make -C examples/basic/hello-world term PORT=/dev/ttyUSB<n>