From a636cfe394781c10a191adad0a59721216a1bd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikolai=20G=C3=BCtschow?= Date: Fri, 1 Nov 2024 18:16:47 +0100 Subject: [PATCH] boards/seeedstudio-xiao-nrf52840: initial board support --- boards/seeedstudio-xiao-nrf52840/Kconfig | 16 ++++ boards/seeedstudio-xiao-nrf52840/Makefile | 3 + boards/seeedstudio-xiao-nrf52840/Makefile.dep | 17 ++++ .../Makefile.features | 12 +++ .../Makefile.include | 1 + boards/seeedstudio-xiao-nrf52840/doc.txt | 30 ++++++ .../seeedstudio-xiao-nrf52840/include/board.h | 91 ++++++++++++++++++ .../include/gpio_params.h | 59 ++++++++++++ .../include/periph_conf.h | 96 +++++++++++++++++++ boards/seeedstudio-xiao-nrf52840/mtd.c | 60 ++++++++++++ boards/seeedstudio-xiao-nrf52840/reset.c | 1 + 11 files changed, 386 insertions(+) create mode 100644 boards/seeedstudio-xiao-nrf52840/Kconfig create mode 100644 boards/seeedstudio-xiao-nrf52840/Makefile create mode 100644 boards/seeedstudio-xiao-nrf52840/Makefile.dep create mode 100644 boards/seeedstudio-xiao-nrf52840/Makefile.features create mode 120000 boards/seeedstudio-xiao-nrf52840/Makefile.include create mode 100644 boards/seeedstudio-xiao-nrf52840/doc.txt create mode 100644 boards/seeedstudio-xiao-nrf52840/include/board.h create mode 100644 boards/seeedstudio-xiao-nrf52840/include/gpio_params.h create mode 100644 boards/seeedstudio-xiao-nrf52840/include/periph_conf.h create mode 100644 boards/seeedstudio-xiao-nrf52840/mtd.c create mode 120000 boards/seeedstudio-xiao-nrf52840/reset.c diff --git a/boards/seeedstudio-xiao-nrf52840/Kconfig b/boards/seeedstudio-xiao-nrf52840/Kconfig new file mode 100644 index 0000000000..e9b0729f1a --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/Kconfig @@ -0,0 +1,16 @@ +# Copyright (c) 2024 TU Dresden +# +# 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 "seeedstudio-xiao-nrf52840" if BOARD_XIAO_NRF52840 + +config BOARD_XIAO_NRF52840 + bool + default y + select BOARD_COMMON_NRF52 + select CPU_MODEL_NRF52840XXAA + +source "$(RIOTBOARD)/common/nrf52/Kconfig" diff --git a/boards/seeedstudio-xiao-nrf52840/Makefile b/boards/seeedstudio-xiao-nrf52840/Makefile new file mode 100644 index 0000000000..f8fcbb53a0 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/seeedstudio-xiao-nrf52840/Makefile.dep b/boards/seeedstudio-xiao-nrf52840/Makefile.dep new file mode 100644 index 0000000000..08ee2d52af --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/Makefile.dep @@ -0,0 +1,17 @@ +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio +endif + +ifneq (,$(filter mtd,$(USEMODULE))) + USEMODULE += mtd_spi_nor +endif + +# default to using littlefs2 on the external flash +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEPKG += littlefs2 + USEMODULE += mtd +endif + +# include common nrf52 dependencies +include $(RIOTBOARD)/common/nrf52/bootloader_nrfutil.dep.mk +include $(RIOTBOARD)/common/nrf52/Makefile.dep diff --git a/boards/seeedstudio-xiao-nrf52840/Makefile.features b/boards/seeedstudio-xiao-nrf52840/Makefile.features new file mode 100644 index 0000000000..1f4969f6d9 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/Makefile.features @@ -0,0 +1,12 @@ +CPU_MODEL = nrf52840xxaa + +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_uart +FEATURES_PROVIDED += periph_usbdev + +# Various other features (if any) +FEATURES_PROVIDED += highlevel_stdio + +include $(RIOTBOARD)/common/nrf52/Makefile.features diff --git a/boards/seeedstudio-xiao-nrf52840/Makefile.include b/boards/seeedstudio-xiao-nrf52840/Makefile.include new file mode 120000 index 0000000000..a2ad50e198 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/Makefile.include @@ -0,0 +1 @@ +../feather-nrf52840/Makefile.include \ No newline at end of file diff --git a/boards/seeedstudio-xiao-nrf52840/doc.txt b/boards/seeedstudio-xiao-nrf52840/doc.txt new file mode 100644 index 0000000000..d3102a6ba0 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/doc.txt @@ -0,0 +1,30 @@ +/** +@defgroup boards_xiao-nrf52840 Seeed Studio XIAO nRF52840 +@ingroup boards +@brief Support for the Seeed Studio XIAO nRF52840 + +### General information + +The [XIAO nRF52840][seeedstudio-xiao-nrf52840] (formally known as XIAO BLE) +is a development board from Seeed Studio's XIAO board family. + +It provides native USB support, Bluetooth +Low Energy and IEEE 802.15.4 support via the nRF52840 MCU. + +top-down view on seeedstudio-xiao-nrf52840 + +[seeedstudio-xiao-nrf52840]: https://wiki.seeedstudio.com/XIAO_BLE/ + +### Flashing, Bootloader, and Terminal + +Refer to the [Feather nRF52840 Express +documentation](https://doc.riot-os.org/group__boards__feather-nrf52840.html) for further details. +Both use the same flasher, bootloader, and terminal settings. + +Example with `hello-world` application: +``` + make BOARD=seeedstudio-xiao-nrf52840 -C examples/hello-world flash term +``` + +*/ diff --git a/boards/seeedstudio-xiao-nrf52840/include/board.h b/boards/seeedstudio-xiao-nrf52840/include/board.h new file mode 100644 index 0000000000..b28fe141cb --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/include/board.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2024 TU Dresden + * + * 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_seeedstudio-xiao-nrf52840 + * @{ + * + * @file + * @brief Board specific configuration for the Seeed Studio XIAO nRF52840 + * + * @author Mikolai Gütschow + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" +#include "board_common.h" +#include "periph/gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name LED pin configuration + * @{ + */ +#define LED0_PIN GPIO_PIN(0, 26) +#define LED1_PIN GPIO_PIN(0, 30) +#define LED2_PIN GPIO_PIN(0, 6) + +#define LED_PORT (NRF_P0) +#define LED0_MASK (1 << 26) +#define LED1_MASK (1 << 30) +#define LED2_MASK (1 << 6) +#define LED_MASK (LED0_MASK | LED1_MASK | LED2_MASK) + +#define LED0_ON (LED_PORT->OUTCLR = LED0_MASK) +#define LED0_OFF (LED_PORT->OUTSET = LED0_MASK) +#define LED0_TOGGLE (LED_PORT->OUT ^= LED0_MASK) + +#define LED1_ON (LED_PORT->OUTCLR = LED1_MASK) +#define LED1_OFF (LED_PORT->OUTSET = LED1_MASK) +#define LED1_TOGGLE (LED_PORT->OUT ^= LED1_MASK) + +#define LED2_ON (LED_PORT->OUTCLR = LED2_MASK) +#define LED2_OFF (LED_PORT->OUTSET = LED2_MASK) +#define LED2_TOGGLE (LED_PORT->OUT ^= LED2_MASK) +/** @} */ + +/** + * @name SPI NOR flash hardware configuration + * + * A 2MB P25Q16H flash is present on the board. + * @{ + */ +#define XIAO_NRF52840_NOR_PAGE_SIZE (256) +#define XIAO_NRF52840_NOR_PAGES_PER_SECTOR (16) +#define XIAO_NRF52840_NOR_SECTOR_COUNT (512) +#define XIAO_NRF52840_NOR_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | SPI_NOR_F_SECT_64K) +#define XIAO_NRF52840_NOR_SPI_DEV SPI_DEV(1) +#define XIAO_NRF52840_NOR_SPI_CLK SPI_CLK_10MHZ +#define XIAO_NRF52840_NOR_SPI_CS GPIO_PIN(0, 25) +#define XIAO_NRF52840_NOR_SPI_WP GPIO_PIN(0, 22) +#define XIAO_NRF52840_NOR_SPI_HOLD GPIO_PIN(0, 23) +#define XIAO_NRF52840_NOR_SPI_MODE SPI_MODE_0 +/** @} */ + +/** Default MTD device */ +#define MTD_0 mtd_dev_get(0) + +/** + * @name ztimer configuration values + * @{ + */ +#define CONFIG_ZTIMER_USEC_ADJUST_SET 7 +#define CONFIG_ZTIMER_USEC_ADJUST_SLEEP 22 +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/seeedstudio-xiao-nrf52840/include/gpio_params.h b/boards/seeedstudio-xiao-nrf52840/include/gpio_params.h new file mode 100644 index 0000000000..0b263ec8f4 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/include/gpio_params.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024 TU Dresden + * + * 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_feather-nrf52840-sense + * @{ + * + * @file + * @brief Configuration of SAUL mapped GPIO pins + * + * @author Mikolai Gütschow + */ + +#ifndef GPIO_PARAMS_H +#define GPIO_PARAMS_H + +#include "board.h" +#include "saul/periph.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief LED configuration + */ +static const saul_gpio_params_t saul_gpio_params[] = +{ + { + .name = "LED Red (USR/D11)", + .pin = LED0_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "LED Green (USR/D13)", + .pin = LED1_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "LED Blue (USR/D12)", + .pin = LED2_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INIT_CLEAR), + }, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/seeedstudio-xiao-nrf52840/include/periph_conf.h b/boards/seeedstudio-xiao-nrf52840/include/periph_conf.h new file mode 100644 index 0000000000..4eef48a22e --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/include/periph_conf.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2024 TU Dresden + * + * 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_seeedstudio-xiao-nrf52840 + * @{ + * + * @file + * @brief Peripheral configuration for the Seeed Studio XIAO nRF52840 + * + * @author Mikolai Gütschow + * + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#include "periph_cpu.h" +#include "cfg_clock_32_1.h" +#include "cfg_rtt_default.h" +#include "cfg_timer_default.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name UART configuration + * @{ + */ +static const uart_conf_t uart_config[] = { + { + .dev = NRF_UARTE0, + .rx_pin = GPIO_PIN(1, 12), + .tx_pin = GPIO_PIN(1, 11), +#ifdef MODULE_PERIPH_UART_HW_FC + .rts_pin = GPIO_UNDEF, + .cts_pin = GPIO_UNDEF, +#endif + .irqn = UARTE0_UART0_IRQn, + }, +}; + +#define UART_0_ISR (isr_uart0) + +#define UART_NUMOF ARRAY_SIZE(uart_config) +/** @} */ + +/** + * @name SPI configuration + * @{ + */ +static const spi_conf_t spi_config[] = { + { + .dev = NRF_SPIM0, + .sclk = GPIO_PIN(1, 13), + .mosi = GPIO_PIN(1, 15), + .miso = GPIO_PIN(1, 14), + }, + { + .dev = NRF_SPIM1, + .sclk = GPIO_PIN(0, 21), + .mosi = GPIO_PIN(0, 20), + .miso = GPIO_PIN(0, 24), + } +}; + +#define SPI_NUMOF ARRAY_SIZE(spi_config) +/** @} */ + +/** + * @name I2C configuration + * @{ + */ +static const i2c_conf_t i2c_config[] = { + { + .dev = NRF_TWIM1, + .scl = GPIO_PIN(0, 5), + .sda = GPIO_PIN(0, 4), + .speed = I2C_SPEED_NORMAL + } +}; +#define I2C_NUMOF ARRAY_SIZE(i2c_config) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */ +/** @} */ diff --git a/boards/seeedstudio-xiao-nrf52840/mtd.c b/boards/seeedstudio-xiao-nrf52840/mtd.c new file mode 100644 index 0000000000..37221c9c04 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/mtd.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 TU Dresden + * + * 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_seeedstudio-xiao-nrf52840 + * @{ + * + * @file + * @brief MTD configuration for the XIAO nRF52840 + * + * @author Mikolai Gütschow + * + * @} + */ + +#ifdef MODULE_MTD + +#include "board.h" +#include "mtd.h" +#include "mtd_spi_nor.h" +#include "periph_conf.h" +#include "timex.h" + +static const mtd_spi_nor_params_t _xiao_nrf52840_nor_params = { + .opcode = &mtd_spi_nor_opcode_default, + .wait_chip_erase = 20LU * US_PER_SEC, + .wait_32k_erase = 20LU *US_PER_MS, + .wait_sector_erase = 20LU * US_PER_MS, + .wait_chip_wake_up = 35LU * US_PER_MS, + .clk = XIAO_NRF52840_NOR_SPI_CLK, + .flag = XIAO_NRF52840_NOR_FLAGS, + .spi = XIAO_NRF52840_NOR_SPI_DEV, + .mode = XIAO_NRF52840_NOR_SPI_MODE, + .cs = XIAO_NRF52840_NOR_SPI_CS, + .wp = XIAO_NRF52840_NOR_SPI_WP, + .hold = XIAO_NRF52840_NOR_SPI_HOLD, +}; + +static mtd_spi_nor_t xiao_nrf52840_nor_dev = { + .base = { + .driver = &mtd_spi_nor_driver, + .page_size = XIAO_NRF52840_NOR_PAGE_SIZE, + .pages_per_sector = XIAO_NRF52840_NOR_PAGES_PER_SECTOR, + .sector_count = XIAO_NRF52840_NOR_SECTOR_COUNT, + }, + .params = &_xiao_nrf52840_nor_params, +}; + +MTD_XFA_ADD(xiao_nrf52840_nor_dev, 0); + +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(xiao_nrf52840_nor_dev), VFS_DEFAULT_NVM(0), 0); +#endif +#endif diff --git a/boards/seeedstudio-xiao-nrf52840/reset.c b/boards/seeedstudio-xiao-nrf52840/reset.c new file mode 120000 index 0000000000..fe94c2c228 --- /dev/null +++ b/boards/seeedstudio-xiao-nrf52840/reset.c @@ -0,0 +1 @@ +../feather-nrf52840/reset.c \ No newline at end of file