diff --git a/boards/common/gd32v/Kconfig b/boards/common/gd32v/Kconfig new file mode 100644 index 0000000000..dfd5106d70 --- /dev/null +++ b/boards/common/gd32v/Kconfig @@ -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 diff --git a/boards/common/gd32v/Makefile.dep b/boards/common/gd32v/Makefile.dep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/boards/common/gd32v/Makefile.features b/boards/common/gd32v/Makefile.features new file mode 100644 index 0000000000..3a51e118f3 --- /dev/null +++ b/boards/common/gd32v/Makefile.features @@ -0,0 +1 @@ +CPU = gd32v diff --git a/boards/common/gd32v/Makefile.include b/boards/common/gd32v/Makefile.include new file mode 100644 index 0000000000..9a0807abd5 --- /dev/null +++ b/boards/common/gd32v/Makefile.include @@ -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 diff --git a/boards/seeedstudio-gd32/dist/openocd.cfg b/boards/common/gd32v/dist/openocd.cfg similarity index 100% rename from boards/seeedstudio-gd32/dist/openocd.cfg rename to boards/common/gd32v/dist/openocd.cfg diff --git a/boards/common/gd32v/doc.txt b/boards/common/gd32v/doc.txt new file mode 100644 index 0000000000..6ff30b528e --- /dev/null +++ b/boards/common/gd32v/doc.txt @@ -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. + */ diff --git a/boards/common/gd32v/include/cfg_timer_default.h b/boards/common/gd32v/include/cfg_timer_default.h new file mode 100644 index 0000000000..180f2cf563 --- /dev/null +++ b/boards/common/gd32v/include/cfg_timer_default.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2020 Koen Zandberg + * 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. + */ + +/** + * @ingroup boards_common_gd32v + * @{ + * + * @file + * @brief Default timer configuration for GD32VF103 boards + * + * @author Koen Zandberg + * @author Gunar Schorcht + */ + +#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 */ +/** @} */ diff --git a/boards/common/gd32v/include/cfg_uart_default.h b/boards/common/gd32v/include/cfg_uart_default.h new file mode 100644 index 0000000000..70ba87c68b --- /dev/null +++ b/boards/common/gd32v/include/cfg_uart_default.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 Koen Zandberg + * 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. + */ + +/** + * @ingroup boards_common_gd32v + * @{ + * + * @file + * @brief Default UART configuration for GD32VF103 boards + * + * @author Koen Zandberg + * @author Gunar Schorcht + */ + +#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 */ +/** @} */ diff --git a/boards/common/gd32v/include/periph_common_conf.h b/boards/common/gd32v/include/periph_common_conf.h new file mode 100644 index 0000000000..c455aa60dd --- /dev/null +++ b/boards/common/gd32v/include/periph_common_conf.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2020 Koen Zandberg + * 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. + */ + +/** + * @ingroup boards_common_gd32v + * @{ + * + * @file + * @brief Common peripheral configuration for GD32VF103 boards + * + * @author Koen Zandberg + * @author Gunar Schorcht + */ + +#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 */ +/** @} */ diff --git a/cpu/gd32v/Makefile.include b/cpu/gd32v/Makefile.include index 3b1ec4d9a3..a2f2252e24 100644 --- a/cpu/gd32v/Makefile.include +++ b/cpu/gd32v/Makefile.include @@ -6,4 +6,6 @@ ROM_LEN ?= 128K LINKER_SCRIPT ?= riscv.ld +CFLAGS += -DCPU_MODEL_$(call uppercase_and_underscore,$(CPU_MODEL)) + include $(RIOTCPU)/riscv_common/Makefile.include diff --git a/cpu/gd32v/clock.c b/cpu/gd32v/clock.c index 6624ddf377..c640138760 100644 --- a/cpu/gd32v/clock.c +++ b/cpu/gd32v/clock.c @@ -21,10 +21,6 @@ #include "cpu.h" #include "periph_conf.h" -#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 */ - #define CLOCK_AHB_DIV 0 /* Max speed at 108 MHz */ #define CLOCK_APB1_DIV (0x04 | 0) /* Max speed at 54 MHz */ #define CLOCK_APB2_DIV (0x0 | 0) /* Max speed at 108 MHz */ diff --git a/dist/tools/doccheck/generic_exclude_patterns b/dist/tools/doccheck/generic_exclude_patterns index 1b74b8f441..d23b4fef22 100644 --- a/dist/tools/doccheck/generic_exclude_patterns +++ b/dist/tools/doccheck/generic_exclude_patterns @@ -41,9 +41,15 @@ warning: Member PULSE_COUNTER_SAUL_INFO \(macro definition\) of warning: Member SHT1X_PARAMS \(macro definition\) of warning: Member SHT1X_PARAM_[A-Z0-9_]* \(macro definition\) of warning: Member SHT1X_SAULINFO \(macro definition\) of +warning: Member TIMER_[0-9]_IRQN \(macro definition\) of +warning: Member TIMER_NUMOF \(macro definition\) of +warning: Member timer_config\[\] \(variable\) of warning: Member TMP00X_PARAM_ADDR \(macro definition\) of warning: Member TMP00X_PARAM_I2C \(macro definition\) of warning: Member TMP00X_PARAM_RATE \(macro definition\) of +warning: Member UART_[0-9]_IRQN \(macro definition\) of +warning: Member UART_NUMOF \(macro definition\) of +warning: Member uart_config\[\] \(variable\) of warning: Member XTIMER_BACKOFF \(macro definition\) of warning: Member XTIMER_CHAN \(macro definition\) of warning: Member XTIMER_DEV \(macro definition\) of