Skip to content

Commit

Permalink
Merge #19170
Browse files Browse the repository at this point in the history
19170: boards/sipeed-longan-nano: add definition for the Sipeed Longan Nano GD32VF103 board r=benpicco a=gschorcht

### Contribution description

This PR add the support for the [Sipeed Longan Nano](https://longan.sipeed.com/en) board, a GD32VF103 development board with the GigaDevice GD32VF103CBT8 RISC-V MCU. This includes moving the common board definitions for GDV32F103 boards from `boards/seeedstudio-gd32` to `boards/common/gd32v`.

**[Update]** At first glance, the existing peripheral definition for `seeedstudio-gd32` seems to fit exactly for `sipeed-longan-nano`. But at second glance it becomes clear that `seeedstudio-gd32` which is using the GD32VF103VBT6 instead of the GD32VF103CBT6 has more peripherals and much more peripheral pins are broken out. This allows a more extensive and flexible peripheral definition (more timers, more ADC pins, more UART interfaces, ...). So it doesn't seem to be a good idea to share the peripheral definitions between these boards.

This PR depends on PR #19166 and includes this PR for the moment.

### Testing procedure

t.b.d.

### Issues/PRs references

Depends on PR #19166

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
  • Loading branch information
bors[bot] and gschorcht authored Jan 23, 2023
2 parents 7157ff3 + 13e4ea4 commit 7218da9
Show file tree
Hide file tree
Showing 28 changed files with 576 additions and 92 deletions.
20 changes: 20 additions & 0 deletions boards/common/gd32v/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2023 Gunar Schorcht
#
# 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.
#

config BOARD_HAS_HXTAL
bool
help
Indicates that the board is providing an HXTAL oscillator

config BOARD_HAS_LXTAL
bool
help
Indicates that the board is providing an LXTAL oscillator

config CLOCK_HXTAL
int
default 8000000
Empty file.
1 change: 1 addition & 0 deletions boards/common/gd32v/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CPU = gd32v
14 changes: 14 additions & 0 deletions boards/common/gd32v/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# include this module into the build
INCLUDES += -I$(RIOTBOARD)/common/gd32v/include

# configure the serial interface
PORT_LINUX ?= /dev/ttyUSB0
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_RESET_USE_CONNECT_ASSERT_SRST = 1
File renamed without changes.
17 changes: 17 additions & 0 deletions boards/common/gd32v/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2023 Gunar Schorcht
*
* 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.
*/

/**
* @defgroup boards_common_gd32v GD32V Common Configuration
* @ingroup boards_common
* @brief Definitions and configurations that are common for
* all GD32VF103 boards.
*
* All boards using a MCU from the GD32VF103 family share some parts of their
* configuration.
*/
88 changes: 88 additions & 0 deletions boards/common/gd32v/include/cfg_timer_default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2020 Koen Zandberg <koen@bergzand.net>
* 2023 Gunar Schorcht <gunar@schorcht.net>
*
* 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_common_gd32v
* @{
*
* @file
* @brief Default timer configuration for GD32VF103 boards
*
* @author Koen Zandberg <koen@bergzand.net>
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#ifndef CFG_TIMER_DEFAULT_H
#define CFG_TIMER_DEFAULT_H

#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Timer configuration
*
* All GD32VF103xx variants have at least one advanced timer TIMER0 and two
* general timers TIMER1 and TIMER2. GD32VF10x8 and GD32VF10xB have two
* additional general timers TIMER3 and TIMER4.
*
* @{
*/
static const timer_conf_t timer_config[] = {
{
.dev = TIMER1,
.max = 0x0000ffff,
.rcu_mask = RCU_APB1EN_TIMER1EN_Msk,
.bus = APB1,
.irqn = TIMER1_IRQn
},
{
.dev = TIMER2,
.max = 0x0000ffff,
.rcu_mask = RCU_APB1EN_TIMER2EN_Msk,
.bus = APB1,
.irqn = TIMER2_IRQn
},
#if defined(CPU_MODEL_GD32VF103C8T6) || defined(CPU_MODEL_GD32VF103CBT6) || \
defined(CPU_MODEL_GD32VF103R8T6) || defined(CPU_MODEL_GD32VF103RBT6) || \
defined(CPU_MODEL_GD32VF103T8U6) || defined(CPU_MODEL_GD32VF103TBU6) || \
defined(CPU_MODEL_GD32VF103V8T6) || defined(CPU_MODEL_GD32VF103VBT6)
{
.dev = TIMER3,
.max = 0x0000ffff,
.rcu_mask = RCU_APB1EN_TIMER3EN_Msk,
.bus = APB1,
.irqn = TIMER3_IRQn
},
{
.dev = TIMER4,
.max = 0x0000ffff,
.rcu_mask = RCU_APB1EN_TIMER4EN_Msk,
.bus = APB1,
.irqn = TIMER4_IRQn
}
#endif
};

#define TIMER_0_IRQN TIMER1_IRQn
#define TIMER_1_IRQN TIMER2_IRQn
#define TIMER_2_IRQN TIMER3_IRQn
#define TIMER_3_IRQN TIMER4_IRQn

#define TIMER_NUMOF ARRAY_SIZE(timer_config)
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* CFG_TIMER_DEFAULT_H */
/** @} */
55 changes: 55 additions & 0 deletions boards/common/gd32v/include/cfg_uart_default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2020 Koen Zandberg <koen@bergzand.net>
* 2023 Gunar Schorcht <gunar@schorcht.net>
*
* 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_common_gd32v
* @{
*
* @file
* @brief Default UART configuration for GD32VF103 boards
*
* @author Koen Zandberg <koen@bergzand.net>
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#ifndef CFG_UART_DEFAULT_H
#define CFG_UART_DEFAULT_H

#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name UART configuration
* @{
*/
static const uart_conf_t uart_config[] = {
{
.dev = USART0,
.rcu_mask = RCU_APB2EN_USART0EN_Msk,
.rx_pin = GPIO_PIN(PORT_A, 10),
.tx_pin = GPIO_PIN(PORT_A, 9),
.bus = APB2,
.irqn = USART0_IRQn,
},
};

#define UART_0_IRQN USART0_IRQn

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* CFG_UART_DEFAULT_H */
/** @} */
42 changes: 42 additions & 0 deletions boards/common/gd32v/include/periph_common_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2020 Koen Zandberg <koen@bergzand.net>
* 2023 Gunar Schorcht <gunar@schorcht.net>
*
* 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_common_gd32v
* @{
*
* @file
* @brief Common peripheral configuration for GD32VF103 boards
*
* @author Koen Zandberg <koen@bergzand.net>
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#ifndef PERIPH_COMMON_CONF_H
#define PERIPH_COMMON_CONF_H

#include "macros/units.h"
#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

#define CLOCK_CORECLOCK MHZ(108) /**< CPU clock frequency in Hz */

#define CLOCK_AHB CLOCK_CORECLOCK /**< Equal to the CPU clock */
#define CLOCK_APB1 CLOCK_AHB/2 /**< Half AHB clock */
#define CLOCK_APB2 CLOCK_AHB /**< Equal to the AHB clock */

#ifdef __cplusplus
}
#endif

#endif /* PERIPH_COMMON_CONF_H */
/** @} */
17 changes: 3 additions & 14 deletions boards/seeedstudio-gd32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ config BOARD_SEEEDSTUDIO_GD32
bool
default y
select CPU_MODEL_GD32VF103VBT6
select HAS_PERIPH_UART
select BOARD_HAS_HXTAL
select BOARD_HAS_LXTAL
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAVE_SAUL_GPIO

config BOARD_HAS_HXTAL
bool
help
Indicates that the board is providing an HXTAL oscillator

config BOARD_HAS_LXTAL
bool
help
Indicates that the board is providing an LXTAL oscillator

config CLOCK_HXTAL
int
default 8000000
source "$(RIOTBOARD)/common/gd32v/Kconfig"
2 changes: 2 additions & 0 deletions boards/seeedstudio-gd32/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

include $(RIOTBOARD)/common/gd32v/Makefile.dep
3 changes: 2 additions & 1 deletion boards/seeedstudio-gd32/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CPU = gd32v
CPU_MODEL = gd32vf103vbt6

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart

include $(RIOTBOARD)/common/gd32v/Makefile.features
11 changes: 1 addition & 10 deletions boards/seeedstudio-gd32/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
# configure the serial interface
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))

# configure the flasher
PROGRAMMER ?= openocd
OPENOCD_DEBUG_ADAPTER ?= ftdi
OPENOCD_FTDI_ADAPTER ?= openocd-usb
OPENOCD_TRANSPORT = jtag
OPENOCD_RESET_USE_CONNECT_ASSERT_SRST = 1
include $(RIOTBOARD)/common/gd32v/Makefile.include
10 changes: 0 additions & 10 deletions boards/seeedstudio-gd32/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
extern "C" {
#endif

#include "macros/units.h"

/**
* @name Button pin definitions
* @{
Expand Down Expand Up @@ -67,14 +65,6 @@ extern "C" {
#define LED_BLUE_PIN LED2_PIN /**< LED2 is blue */
/** @} */

/**
* @name Xtimer configuration
* @{
*/
#define XTIMER_HZ MHZ(1)
#define XTIMER_WIDTH (16)
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
60 changes: 7 additions & 53 deletions boards/seeedstudio-gd32/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
#ifndef PERIPH_CONF_H
#define PERIPH_CONF_H

#include "macros/units.h"
#include "periph_cpu.h"
#include "periph_common_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#include "cfg_timer_default.h"
#include "cfg_uart_default.h"

#ifndef CONFIG_BOARD_HAS_HXTAL
#define CONFIG_BOARD_HAS_HXTAL 1 /**< This board provides an high frequency oscillator */
#define CONFIG_BOARD_HAS_HXTAL 1 /**< The board provides a high frequency oscillator. */
#endif

#ifndef CONFIG_BOARD_HAS_LXTAL
Expand All @@ -38,54 +37,9 @@ extern "C" {
#define CONFIG_CLOCK_HXTAL MHZ(8) /**< HXTAL frequency */
#endif

#define CLOCK_CORECLOCK MHZ(108) /**< CPU clock frequency in Hz */

/**
* @name Timer configuration
* @{
*/
static const timer_conf_t timer_config[] = {
{
.dev = TIMER2,
.max = 0x0000ffff,
.rcu_mask = RCU_APB1EN_TIMER2EN_Msk,
.bus = APB1,
.irqn = TIMER2_IRQn
},
{
.dev = TIMER3,
.max = 0x0000ffff,
.rcu_mask = RCU_APB1EN_TIMER3EN_Msk,
.bus = APB1,
.irqn = TIMER3_IRQn
}
};

#define TIMER_0_IRQN TIMER2_IRQn
#define TIMER_1_IRQN TIMER3_IRQn

#define TIMER_NUMOF ARRAY_SIZE(timer_config)
/** @} */

/**
* @name UART configuration
* @{
*/
static const uart_conf_t uart_config[] = {
{
.dev = USART0,
.rcu_mask = RCU_APB2EN_USART0EN_Msk,
.rx_pin = GPIO_PIN(PORT_A, 10),
.tx_pin = GPIO_PIN(PORT_A, 9),
.bus = APB2,
.irqn = USART0_IRQn,
},
};

#define UART_0_IRQN USART0_IRQn

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */
#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 7218da9

Please sign in to comment.