Skip to content

Commit

Permalink
Merge pull request RIOT-OS#20270 from maribu/boards/gd32vf103c-start
Browse files Browse the repository at this point in the history
boards/gd32vf103c-start: new board
  • Loading branch information
maribu committed Jan 20, 2024
2 parents 2cb575a + 66abbd2 commit 504c169
Show file tree
Hide file tree
Showing 25 changed files with 660 additions and 26 deletions.
3 changes: 1 addition & 2 deletions boards/common/gd32v/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))

# configure the flasher
PROGRAMMER ?= openocd
OPENOCD_CONFIG ?= $(RIOTBOARD)/common/gd32v/dist/openocd.cfg
OPENOCD_DEBUG_ADAPTER ?= ftdi
OPENOCD_FTDI_ADAPTER ?= openocd-usb
OPENOCD_TRANSPORT = jtag
OPENOCD_TRANSPORT ?= jtag
OPENOCD_RESET_USE_CONNECT_ASSERT_SRST = 1

# DFU programmer specific variables
Expand Down
2 changes: 1 addition & 1 deletion boards/common/gd32v/include/cfg_usbdev_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ static const dwc2_usb_otg_fshs_config_t dwc2_usb_otg_fshs_config[] = {
.type = DWC2_USB_OTG_FS,
.phy = DWC2_USB_OTG_PHY_BUILTIN,
.rcu_mask = RCU_AHBEN_USBFSEN_Msk,
.bus = AHB,
.irqn = USBFS_IRQn,
.bus = AHB,
}
};

Expand Down
3 changes: 3 additions & 0 deletions boards/gd32vf103c-start/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = board

include $(RIOTBASE)/Makefile.base
5 changes: 5 additions & 0 deletions boards/gd32vf103c-start/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

include $(RIOTBOARD)/common/gd32v/Makefile.dep
24 changes: 24 additions & 0 deletions boards/gd32vf103c-start/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CPU_MODEL = gd32vf103cbt6

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_usbdev
FEATURES_PROVIDED += sdcard_spi

# Other features provided by the board (in alphabetical order)
FEATURES_PROVIDED += arduino_analog
FEATURES_PROVIDED += arduino_i2c
FEATURES_PROVIDED += arduino_pins
FEATURES_PROVIDED += arduino_pwm
FEATURES_PROVIDED += arduino_shield_uno
FEATURES_PROVIDED += arduino_spi
FEATURES_PROVIDED += arduino_uart
FEATURES_PROVIDED += highlevel_stdio
FEATURES_PROVIDED += tinyusb_device

include $(RIOTBOARD)/common/gd32v/Makefile.features
10 changes: 10 additions & 0 deletions boards/gd32vf103c-start/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PORT_LINUX ?= /dev/ttyACM0
PROGRAMMER ?= openocd
OPENOCD_DEBUG_ADAPTER ?= dap
OPENOCD_TRANSPORT := default

# Only consider TTYs matching the following filter when auto-selecting the TTY
# with `MOST_RECENT_PORT=1`.
TTY_BOARD_FILTER := --driver 'ch341' --model 'USB2.0-Serial'

include $(RIOTBOARD)/common/gd32v/Makefile.include
2 changes: 2 additions & 0 deletions boards/gd32vf103c-start/dist/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
adapter speed 10000
source [find target/gd32vf103.cfg]
103 changes: 103 additions & 0 deletions boards/gd32vf103c-start/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
@defgroup boards_gd32vf103c_start GD32VF103C-START
@ingroup boards
@brief Support for the GD32VF103C-START board
@author Marian Buschsieweke

## Overview

The GD32VF103C-START development board is an official starter kit by GigaDevice
for the GD32VF103CBT6 MCU, despite the lack of official documentation. It
featrures:

- GD32VF103CBT6 RISC-V MCU @108MHz
- On-Board GD-Link Programmer/Debugger (middle mini-USB connector)
- USB-OTG (left mini-USB connector)
- Integrated USB to UART bridge (right mini-USB connector)
- 1 user LED
- 1 user Button
- 1 reset button
- Arduino UNO compatible pin headers (except ISP header)

![Image of the GD32VF103C-START board](https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/a0ac2faf9bde45b176f1e8b315ffb1b8a9096166/boards/riscv/gd32vf103c_starter/doc/img/gd32vf103c_starter.jpg)

@warning The analog pins are labeled A1 - A6 rather than A0 - A5, as would
be the correct Arduino naming. The Arduino pin mapping uses the
correct Arduino naming, so that apps written for other boards
expecting Arduino UNO compatible shields remain compatible.

## Hardware

| MCU | GD32VF103CBT6 | Supported |
|:----------------- |:----------------------------------------- | --------- |
| Family | RISC-V with ECLIC | |
| Vendor | GigaDevice | |
| RAM | 32 KiB | |
| Flash | 128 KiB | |
| Frequency | 108 MHz | |
| Power Modes | 3 (Sleep, Deep Sleep, Standby) | yes |
| GPIOs | 37 | yes |
| Timers | 5 x 16-bit timer | yes |
| RTC | 1 x 32-bit counter, 20-bit prescaler | yes |
| WDT | 2 x 12-bit counter, 3-bit prescaler | yes |
| ADC | 2 x 12-bit units, 16 channels @ 1 Msps | yes |
| DAC | 2 x 12-bit channel | yes |
| UART | - | yes |
| USART | 3 | yes |
| SPI | 3 | yes |
| I2C | 2 x Fast Mode 400 kHz | yes |
| I2S | 2 | no |
| CAN | 2 x CAN 2.0B with up to 1 Mbps | no |
| PWM | 6 Channels | yes |
| USB | 1 x USB FS OTG (+ GD-Link + UART bridge) | yes |
| Vcc | 3.0V - 3.6V | |
| Datasheet | [Datasheet][gd32vf103c-datasheet] | |
| User Manual | [User Manual][gd32vf103c-manual] | |
| Board Manual | [Board Manual][gd32vf103c-board-manual] | |

[gd32vf103c-datasheet]: https://web.archive.org/web/20240117072854/https://gd32mcu.com/data/documents/datasheet/GD32VF103_Datasheet_Rev1.6.pdf
[gd32vf103c-manual]: https://web.archive.org/web/20240117073025/https://gd32mcu.com/data/documents/userManual/GD32VF103_User_Manual_Rev1.5.pdf
[gd32vf103c-board-manual]: https://web.archive.org/web/20240117072723/https://en.maritex.com.pl/product/attachment/154626/6f28fdabafb9dff852537ced7bc0aa71

## Flashing

@warning Flashing seems to fail with some Arduino UNO compatible boards
attached. Remove them and try again.

By default, flashing is done via OpenOCD using the GD-Link programmer/debugger
using:

```
make BOARD=gd32vf103c-start -C path/to/app flash
```

It is also possible to flash via DFU-Util:

1. Connect a mini USB cable to the USB connector labeled OTG.
2. Power the board (e.g. by connecting a second mini USB cable to the GD-Link
programmer/debugger, even though we won't use it)
3. Enter the DFU bootloader by placing the jumper on JP4 (below BOOT) in
position H. Press the reset button afterwards.
4. Run `make BOARD=gd32vf103c-start PROGRAMMER=dfu-util -C path/to/app flash`
5. Restore the JP4 jumper to position L. Afterwards press the reset button
again

## Connecting to the Serial Output

By default RIOT's uses UART for `stdio`. To access that, connect a mini USB
cable to the connector labeled "USART". In addition a jumper needs to be
placed on JP2 in the "Usart" position; otherwise RIOT's TXD is not connected
to the RXD of the integrated USB UART bridge. Afterwards just run:

```
make BOARD=gd32vf103c-start -C path/to/app term
```

Alternatively, `stdio_cdc_acm` can be used. In this case the mini USB cable
needs to be connected to the USB connector labeled OTG.

@note It is safe to keep the jumper at JP2 in "Usart" position or even
remove the jumper with RIOT. PA9 is still used as UART/TXD and VBUS
sensing is disabled anyway.

*/
150 changes: 150 additions & 0 deletions boards/gd32vf103c-start/include/arduino_iomap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (C) 2024 Marian Buschsieweke
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_gd32vf103c_start
* @{
*
* @file
* @brief Mapping from MCU pins to Arduino pins
*
* You can use the defines in this file for simplified interaction with the
* Arduino specific pin numbers.
*
* @author Marian Buschsieweke <[email protected]>
*/

#ifndef ARDUINO_IOMAP_H
#define ARDUINO_IOMAP_H

#include "macros/units.h"
#include "periph/adc.h"
#include "periph/gpio.h"
#include "periph/pwm.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Arduino's UART devices
* @{
*/
#define ARDUINO_UART_D0D1 UART_DEV(0)
/** @} */

/**
* @name Arduino's SPI buses
* @{
*/
/**
* @brief SPI_DEV(0) is connected to D11/D12/D13
*/
#define ARDUINO_SPI_D11D12D13 SPI_DEV(0)
/** @} */

/**
* @name Arduino's I2C buses
* @{
*/
/**
* @brief The first I2C bus is where shields for the Arduino UNO expect it
*/
#define ARDUINO_I2C_UNO I2C_DEV(0)
/** @} */

/**
* @brief Mapping of MCU pins to Arduino pins
* @{
*/
#define ARDUINO_PIN_0 GPIO_PIN(PORT_A, 10)
#define ARDUINO_PIN_1 GPIO_PIN(PORT_A, 9)
#define ARDUINO_PIN_2 GPIO_PIN(PORT_B, 4)
#define ARDUINO_PIN_3 GPIO_PIN(PORT_B, 5)
#define ARDUINO_PIN_4 GPIO_PIN(PORT_B, 6)
#define ARDUINO_PIN_5 GPIO_PIN(PORT_B, 7)
#define ARDUINO_PIN_6 GPIO_PIN(PORT_B, 8)
#define ARDUINO_PIN_7 GPIO_PIN(PORT_B, 9)

#define ARDUINO_PIN_8 GPIO_PIN(PORT_B, 1)
#define ARDUINO_PIN_9 GPIO_PIN(PORT_B, 0)
#define ARDUINO_PIN_10 GPIO_PIN(PORT_B, 12)
#define ARDUINO_PIN_11 GPIO_PIN(PORT_B, 15)
#define ARDUINO_PIN_12 GPIO_PIN(PORT_B, 14)
#define ARDUINO_PIN_13 GPIO_PIN(PORT_B, 13)
#define ARDUINO_PIN_14 GPIO_PIN(PORT_B, 11)
#define ARDUINO_PIN_15 GPIO_PIN(PORT_B, 10)

#define ARDUINO_PIN_16 GPIO_PIN(PORT_A, 1)
#define ARDUINO_PIN_17 GPIO_PIN(PORT_A, 2)
#define ARDUINO_PIN_18 GPIO_PIN(PORT_A, 3)
#define ARDUINO_PIN_19 GPIO_PIN(PORT_B, 4)
#define ARDUINO_PIN_20 GPIO_PIN(PORT_C, 5)
#define ARDUINO_PIN_21 GPIO_PIN(PORT_C, 6)

#define ARDUINO_PIN_LAST 21
/** @} */

/**
* @name Aliases for analog pins
* @warning Silkscreen label is A1 - A6 instead of A0 - A5. We stick with
* Arduino UNO labeling here so that e.g. board independent drivers
* for shields can be provided.
* @{
*/
#define ARDUINO_PIN_A0 ARDUINO_PIN_16
#define ARDUINO_PIN_A1 ARDUINO_PIN_17
#define ARDUINO_PIN_A2 ARDUINO_PIN_18
#define ARDUINO_PIN_A3 ARDUINO_PIN_19
#define ARDUINO_PIN_A4 ARDUINO_PIN_20
#define ARDUINO_PIN_A5 ARDUINO_PIN_21
/** @} */

/**
* @name Mapping of Arduino analog pins to RIOT ADC lines
* @{
*/
#define ARDUINO_A0 ADC_LINE(0)
#define ARDUINO_A1 ADC_LINE(1)
#define ARDUINO_A2 ADC_LINE(2)
#define ARDUINO_A3 ADC_LINE(3)
#define ARDUINO_A4 ADC_LINE(4)
#define ARDUINO_A5 ADC_LINE(5)

#define ARDUINO_ANALOG_PIN_LAST 5
/** @} */

/**
* @name Mapping of Arduino pins to RIOT PWM dev and channel pairs
* @{
*/
/**
* @brief PWM frequency
*/
#define ARDUINO_PWM_FREQU KHZ(100)

#define ARDUINO_PIN_3_PWM_DEV PWM_DEV(0)
#define ARDUINO_PIN_3_PWM_CHAN 0

#define ARDUINO_PIN_5_PWM_DEV PWM_DEV(1)
#define ARDUINO_PIN_5_PWM_CHAN 0

#define ARDUINO_PIN_6_PWM_DEV PWM_DEV(1)
#define ARDUINO_PIN_6_PWM_CHAN 1

#define ARDUINO_PIN_9_PWM_DEV PWM_DEV(0)
#define ARDUINO_PIN_9_PWM_CHAN 1
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* ARDUINO_IOMAP_H */
/** @} */
53 changes: 53 additions & 0 deletions boards/gd32vf103c-start/include/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2024 Marian Buschsieweke
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_gd32vf103c_start
* @{
*
* @file
* @brief Board specific definitions for the GD32VF103C-START board
*
* @author Marian Buschsieweke <[email protected]>
*/

#ifndef BOARD_H
#define BOARD_H

#include "board_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Button pin definitions
* @{
*/
#define BTN0_PIN GPIO_PIN(PORT_A, 0)
#define BTN0_MODE GPIO_IN_PU
#define BTN0_INT_FLANK GPIO_FALLING
/** @} */

/**
* @name LED (on-board) configuration
* @{
*/
#define LED0_PIN GPIO_PIN(PORT_A, 7)
#define LED0_MASK (1 << 7)
#define LED0_ON (GPIOA->BC = LED0_MASK)
#define LED0_OFF (GPIOA->BOP = LED0_MASK)
#define LED0_TOGGLE (GPIOA->OCTL ^= LED0_MASK)
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* BOARD_H */
/** @} */
Loading

0 comments on commit 504c169

Please sign in to comment.