Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards/sipeed_longan_nano: separate board definition for Sipeed Longan Nano TFT #19824

Merged
merged 7 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions boards/common/gd32v/include/cfg_i2c_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ extern "C" {
*/

/**
* @brief Enable the second I2C device `I2C_DEV(1)` by default
* @brief Disable the second I2C device `I2C_DEV(1)` by default
*
* The second I2C device `I2C_DEV(1)` is only defined if `I2C_DEV_1_USED`
* is set to 1 by the board.
* This allows to use the default configuration with one or two I2C devices
* depending on whether other peripherals are enabled that would collide with
* the I2C devices.
*/
#ifndef I2C_DEV_1_USED
#define I2C_DEV_1_USED
#define I2C_DEV_1_USED 0
#endif

/**
Expand All @@ -46,7 +51,7 @@ extern "C" {
* The default I2C device configuration allows to define up to two I2C devices
* `I2C_DEV(0)` and `I2C_DEV(1)`. `I2C_DEV(0)` is always defined if the I2C
* peripheral is enabled by the module `periph_spi`. The second I2C device
* `I2C_DEV(1)` is only defined if `I2C_DEV_1_USED` is defined by the board.
* `I2C_DEV(1)` is only defined if `I2C_DEV_1_USED` is set to 1 by the board.
* This allows to use the default configuration with one or two I2C devices
* depending on whether other peripherals are enabled that would collide with
* the I2C devices.
Expand All @@ -60,6 +65,7 @@ static const i2c_conf_t i2c_config[] = {
.rcu_mask = RCU_APB1EN_I2C0EN_Msk,
.irqn = I2C0_EV_IRQn,
},
#if I2C_DEV_1_USED
{
.dev = I2C1,
.speed = I2C_SPEED_NORMAL,
Expand All @@ -68,6 +74,7 @@ static const i2c_conf_t i2c_config[] = {
.rcu_mask = RCU_APB1EN_I2C1EN_Msk,
.irqn = I2C1_EV_IRQn,
}
#endif
};

#define I2C_NUMOF ARRAY_SIZE(i2c_config)
Expand Down
15 changes: 10 additions & 5 deletions boards/common/gd32v/include/cfg_spi_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ extern "C" {
*/

/**
* @brief Enable the second SPI device `SPI_DEV(1)` by default
* @brief Disable the second SPI device `SPI_DEV(1)` by default
*
* The second SPI device `SPI_DEV(1)` is only defined if `SPI_DEV_1_USED`
* is set to 1 by the board.
* This allows to use the default configuration with one or two SPI devices
* depending on whether other peripherals are enabled that would collide with
* the SPI devices.
*/
#ifndef SPI_DEV_1_USED
#define SPI_DEV_1_USED
#define SPI_DEV_1_USED 0
#endif

/**
Expand All @@ -57,7 +62,7 @@ extern "C" {
* the default CS signal is connected to an unused hardware.
*/
#ifndef SPI_DEV_1_CS
#define SPI_DEV_1_CS GPIO_PIN(PORT_A, 4)
#define SPI_DEV_1_CS GPIO_PIN(PORT_B, 5)
#endif

/**
Expand All @@ -66,7 +71,7 @@ extern "C" {
* The default SPI device configuration allows to define up to two SPI devices
* `SPI_DEV(0)` and `SPI_DEV(1)`. `SPI_DEV(0)` is always defined if the SPI
* peripheral is enabled by the module `periph_spi`. The second SPI device
* `SPI_DEV(1)` is only defined if `SPI_DEV_1_USED` is defined by the board.
* `SPI_DEV(1)` is only defined if `SPI_DEV_1_USED` is set to 1 by the board.
* This allows to use the default configuration with one or two SPI devices
* depending on whether other peripherals are enabled that would collide with
* the SPI devices.
Expand All @@ -81,7 +86,7 @@ static const spi_conf_t spi_config[] = {
.rcumask = RCU_APB1EN_SPI1EN_Msk,
.apbbus = APB1,
},
#ifdef SPI_DEV_1_USED
#if SPI_DEV_1_USED
{
.dev = SPI0,
.mosi_pin = GPIO_PIN(PORT_A, 7),
Expand Down
8 changes: 7 additions & 1 deletion boards/seeedstudio-gd32/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
#define CONFIG_CLOCK_HXTAL MHZ(8) /**< HXTAL frequency */
#endif

#define SPI_DEV_1_USED /**< Enable SPI_DEV(1) for the connected flash */
#ifndef SPI_DEV_1_USED
#define SPI_DEV_1_USED 1 /**< Enable SPI_DEV(1) by default for the connected Flash */
#endif

#ifndef I2C_DEV_1_USED
#define I2C_DEV_1_USED 1 /**< Enable I2C_DEV(1) by default */
#endif

#include "periph_cpu.h"
#include "periph_common_conf.h"
Expand Down
39 changes: 39 additions & 0 deletions boards/sipeed-longan-nano-tft/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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
default "sipeed-longan-nano-tft" if BOARD_SIPEED_LONGAN_NANO_TFT

config BOARD_SIPEED_LONGAN_NANO_TFT
bool
default y
select CPU_MODEL_GD32VF103CBT6
select BOARD_HAS_HXTAL
select BOARD_HAS_LXTAL
select HAS_HIGHLEVEL_STDIO
select HAS_PERIPH_ADC
select HAS_PERIPH_DAC
select HAS_PERIPH_I2C
select HAS_PERIPH_PWM
select HAS_PERIPH_SPI
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAS_PERIPH_USBDEV
select HAS_RIOTBOOT
select HAS_TINYUSB_DEVICE

select HAVE_MTD_SDCARD_DEFAULT
select HAVE_SAUL_GPIO
select HAVE_ST7735

select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT
select MODULE_USB_BOARD_RESET if KCONFIG_USB && TEST_KCONFIG

config FORCE_USB_STDIO
default y

source "$(RIOTBOARD)/common/gd32v/Kconfig"
2 changes: 2 additions & 0 deletions boards/sipeed-longan-nano-tft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DIRS = $(RIOTBOARD)/sipeed-longan-nano
include $(RIOTBASE)/Makefile.base
5 changes: 5 additions & 0 deletions boards/sipeed-longan-nano-tft/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ifneq (,$(filter disp_dev,$(USEMODULE)))
USEMODULE += st7735
endif

include $(RIOTBOARD)/sipeed-longan-nano/Makefile.dep
1 change: 1 addition & 0 deletions boards/sipeed-longan-nano-tft/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBOARD)/sipeed-longan-nano/Makefile.features
2 changes: 2 additions & 0 deletions boards/sipeed-longan-nano-tft/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INCLUDES += -I$(RIOTBOARD)/sipeed-longan-nano/include
include $(RIOTBOARD)/sipeed-longan-nano/Makefile.include
21 changes: 21 additions & 0 deletions boards/sipeed-longan-nano-tft/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
@defgroup boards_sipeed_longan_nano_tft Sipeed Longan Nano with TFT
@ingroup boards
@brief Support for the Sipeed Longan Nano board with TFT display
@author Gunar Schorcht <[email protected]>

The [Sipeed Longan Nano TFT](https://longan.sipeed.com/en) board is a version
of the \ref sipeed_longan_nano "Sipeed Longan Nano" development board
that is equipped with a TFT display 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

@image html "https://media-cdn.seeedstudio.com/media/catalog/product/cache/7f7f32ef807b8c2c2215b49801c56084/1/1/114992425_1.jpg" "Sipeed Longan Nano" width=600

Detailed information about the board configuration and flashing can be found
in the \ref sipeed_longan_nano "Sipeed Longan Nano" documentation.
*/
16 changes: 3 additions & 13 deletions boards/sipeed-longan-nano/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Inria
# 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
Expand All @@ -25,24 +25,14 @@ config BOARD_SIPEED_LONGAN_NANO
select HAS_PERIPH_USBDEV
select HAS_RIOTBOOT
select HAS_TINYUSB_DEVICE
select HAVE_SAUL_GPIO

select HAVE_MTD_SDCARD_DEFAULT
select HAVE_SAUL_GPIO

select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT
select MODULE_USB_BOARD_RESET if KCONFIG_USB && TEST_KCONFIG

config FORCE_USB_STDIO
default y

menu "Sipeed Longan Nano Board Configuration"

config SIPEED_LONGAN_NANO_WITH_TFT
bool "Board with TFT display"
default y if MODULE_DISP_DEV
select HAVE_ST7735
help
Indicates that a Sipeed Longan Nano board with TFT display is used.

endmenu

source "$(RIOTBOARD)/common/gd32v/Kconfig"
4 changes: 0 additions & 4 deletions boards/sipeed-longan-nano/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ ifneq (,$(filter vfs_default,$(USEMODULE)))
USEMODULE += mtd
endif

ifneq (,$(filter disp_dev,$(USEMODULE)))
USEMODULE += st7735
endif

include $(RIOTBOARD)/common/makefiles/stdio_cdc_acm.dep.mk
include $(RIOTBOARD)/common/gd32v/Makefile.dep
4 changes: 0 additions & 4 deletions boards/sipeed-longan-nano/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
PORT_LINUX ?= /dev/ttyACM0
PROGRAMMER ?= dfu-util

ifneq (,$(filter st7735,$(USEMODULE)))
CFLAGS += '-DCONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1'
endif

include $(RIOTBOARD)/common/gd32v/Makefile.include
62 changes: 35 additions & 27 deletions boards/sipeed-longan-nano/doc.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
@defgroup boards_sipeed_longan_nano Sipeed Longan Nano board
@defgroup boards_sipeed_longan_nano Sipeed Longan Nano
@ingroup boards
@brief Support for the Sipeed Longan Nano board
@author Gunar Schorcht <[email protected]>

\section sipeed_longan_nano Sipeed Longan Nano

## Overview

The [Sipeed Longan Nano](https://longan.sipeed.com/en) is a
Expand Down Expand Up @@ -64,15 +66,15 @@ by pins.
| ADC_LINE(1) | PA3 | ADC01_IN3 | | |
| ADC_LINE(2) | - | ADC01_IN16 | | internal Temperature channel |
| ADC_LINE(3) | - | ADC01_IN17 | | internal VFEF channel |
| ADC_LINE(4) | PB0 | ADC01_IN8 | TFT RS | N/A if TFT is used |
| ADC_LINE(5) | PB1 | ADC01_IN9 | TFT RST | N/A if TFT is used |
| ADC_LINE(6) | PA6 | ADC01_IN6 | | N/A if TFT is used |
| ADC_LINE(7) | PA7 | ADC01_IN7 | | N/A if TFT is used |
| ADC_LINE(8) | PA4 | ADC01_IN4 | | N/A if TFT is used |
| ADC_LINE(9) | PA5 | ADC01_IN5 | | N/A if TFT is used |
| ADC_LINE(4)* | PA4 | ADC01_IN4 | | N/A if DAC is used |
| ADC_LINE(5)* | PB0 | ADC01_IN8 | TFT RS | N/A if TFT is used |
| ADC_LINE(6)* | PB1 | ADC01_IN9 | TFT RST | N/A if TFT is used |
| ADC_LINE(7)* | PA6 | ADC01_IN6 | | N/A if TFT/SPI_DEV(1) is used |
| ADC_LINE(8)* | PA7 | ADC01_IN7 | | N/A if TFT/SPI_DEV(1) is used |
| ADC_LINE(9)* | PA5 | ADC01_IN5 | | N/A if TFT/SPI_DEV(1)/DAC used |
| BTN0 | PA8 | BOOT0 | BOOT | |
| DAC_LINE(0) | PA4 | DAC0 | | N/A if TFT is used |
| DAC_LINE(1) | PA5 | DAC1 | | N/A if TFT is used |
| DAC_LINE(0) | PA4 | DAC0 | | |
| DAC_LINE(1)* | PA5 | DAC1 | | N/A if TFT is used |
| GPIO_PIN(1, 2) | PB2 | | TFT CS | |
| I2C_DEV(0) SCL | PB6 | I2C0 SCL | | |
| I2C_DEV(0) SDA | PB7 | I2C0 SDA | | |
Expand All @@ -83,25 +85,26 @@ by pins.
| LED2 | PA2 | | LED blue | |
| PWM_DEV(0) CH0 | PA1 | | LED green | |
| PWM_DEV(0) CH1 | PA2 | | LED blue | |
| PWM_DEV(1) CH0 | PB8 | | | N/A if CAN is used |
| PWM_DEV(1) CH1 | PB9 | | | N/A if CAN is used |
| PWM_DEV(1) CH0* | PB8 | | | N/A if CAN is used |
| PWM_DEV(1) CH1* | PB9 | | | N/A if CAN is used |
| SPI_DEV(0) CS | PB12 | SPI1 CS | SD CS | |
| SPI_DEV(0) SCLK | PB13 | SPI1 SCLK | SD SCK | |
| SPI_DEV(0) MISO | PB14 | SPI1 MISO | SD MISO | |
| SPI_DEV(0) MOSI | PB15 | SPI1 MOSI | SD MOSI | |
| SPI_DEV(1) CS | PA4 | SPI0 CS | | |
| SPI_DEV(1) CS | PB5 | SPI0 CS | | |
| SPI_DEV(1) SCLK | PA5 | SPI0 SCLK | TFT SCL | |
| SPI_DEV(1) MISO | PA6 | SPI0 MISO | | |
| SPI_DEV(1) MOSI | PA7 | SPI0 MOSI | TFT SDA | |
| UART_DEV(0) TX | PA9 | USART0 TX | UART TX | |
| UART_DEV(0) RX | PA10 | USART0 RX | UART RX | |

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

\n
@note To use the TFT display of a Sipeed Longan Nano board, if available, the
macro `CONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1` has to be defined, for
example using the `CFLAGS` variable in the make command:
@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 CFLAGS='-DCONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1' make ...
BOARD=sipeed-longan-nano-tft make ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| Pin | Board Function | RIOT Function 1 | RIOT Function 2 | RIOT Function 3 |
Expand All @@ -110,10 +113,10 @@ BOARD=sipeed-longan-nano CFLAGS='-DCONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1' make ..
| PA1 | LED green | PWM_DEV(0) CH0 | | LED0 |
| PA2 | LED blue | PWM_DEV(0) CH1 | | LED1 |
| PA3 | | | ADC_LINE(1) | |
| PA4 | | SPI_DEV(1) CS | ADC_LINE(8)* | DAC_LINE(0)* |
| PA4 | | | ADC_LINE(4)* | DAC_LINE(0) |
| PA5 | TFT SCL | SPI_DEV(1) SCLK | ADC_LINE(9)* | DAC_LINE(1)* |
| PA6 | | SPI_DEV(1) MISO | ADC_LINE(6)* | |
| PA7 | TFT SDA | SPI_DEV(1) MOSI | ADC_LINE(7)* | |
| PA6 | | SPI_DEV(1) MISO | ADC_LINE(7)* | |
| PA7 | TFT SDA | SPI_DEV(1) MOSI | ADC_LINE(8)* | |
| PA8 | BOOT | | | BTN0 |
| PA9 | | UART_DEV(0) TX | | |
| PA10 | | UART_DEV(0) RX | | |
Expand All @@ -122,12 +125,12 @@ BOARD=sipeed-longan-nano CFLAGS='-DCONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1' make ..
| PA13 | JTAG TMS | | | |
| PA14 | JTAG TCK | | | |
| PA15 | JTAG TDI | | | |
| PB0 | TFT RS | | ADC_LINE(4) | |
| PB1 | TFT RST | | ADC_LINE(5) | |
| PB0 | TFT RS | | ADC_LINE(5)* | |
| PB1 | TFT RST | | ADC_LINE(6)* | |
| PB2 | TFT CS | | | |
| PB3 | JTAG TDO | | | |
| PB4 | JTAG NRST | | | |
| PB5 | | | | |
| PB5 | | SPI_DEV(1) CS | | |
| PB6 | | I2C_DEV(0) SCL | | |
| PB7 | | I2C_DEV(0) SDA | | |
| PB8 | | PWM_DEV(1) CH0 | | |
Expand All @@ -138,7 +141,7 @@ BOARD=sipeed-longan-nano CFLAGS='-DCONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1' make ..
| PB13 | SD SCK | SPI_DEV(0) SCLK | | |
| PB14 | SD MISO | SPI_DEV(0) MISO | | |
| PB15 | SD MOSI | SPI_DEV(0) MOSI | | |
| PC13 | LED red | | | LED3 |
| PC13 | LED red | | | LED2 |
| PC14 | OSC32IN | | | |
| PC15 | OSC32OUT | | | |
| - | Temperature | | ADC_LINE(2) | |
Expand All @@ -162,6 +165,12 @@ BOARD=sipeed-longan-nano make -C examples/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/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]
Expand All @@ -187,11 +196,10 @@ PROGRAMMER=openocd OPENOCD_DEBUG_ADAPTER=jlink BOARD=sipeed-longan-nano make -C

## Using the TFT Display

To use the TFT display of a Sipeed Longan Nano board, if available, the
macro `CONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1` has to be defined, for
example using the `CFLAGS` variable in the make command:
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 CFLAGS='-DCONFIG_SIPEED_LONGAN_NANO_WITH_TFT=1' make -C tests/drivers/st7735 flash
BOARD=sipeed-longan-nano-tft make -C tests/drivers/st7735 flash
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

## Accessing STDIO
Expand Down
2 changes: 1 addition & 1 deletion boards/sipeed-longan-nano/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern "C" {
#define SDCARD_SPI_PARAM_MOSI GPIO_PIN(PORT_B, 15)
#endif

#if defined(MODULE_ST7735) && defined(CONFIG_SIPEED_LONGAN_NANO_WITH_TFT)
#if defined(MODULE_ST7735) && defined(BOARD_SIPEED_LONGAN_NANO_TFT)
#define ST7735_PARAM_SPI SPI_DEV(1) /**< SPI device */
#define ST7735_PARAM_SPI_CLK SPI_CLK_5MHZ /**< SPI clock frequency */
#define ST7735_PARAM_SPI_MODE SPI_MODE_0 /**< SPI mode */
Expand Down
Loading