From 00ff7a14da1474b3589ff5b08eb09696ad690a41 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 3 Feb 2020 20:53:01 +0100 Subject: [PATCH] boards/adafruit-clue: add initial support --- boards/adafruit-clue/Makefile | 3 + boards/adafruit-clue/Makefile.dep | 18 +++++ boards/adafruit-clue/Makefile.features | 12 +++ boards/adafruit-clue/Makefile.include | 26 ++++++ boards/adafruit-clue/board.c | 33 ++++++++ boards/adafruit-clue/doc.txt | 39 +++++++++ boards/adafruit-clue/include/board.h | 80 ++++++++++++++++++ boards/adafruit-clue/include/gpio_params.h | 58 +++++++++++++ boards/adafruit-clue/include/periph_conf.h | 94 ++++++++++++++++++++++ boards/adafruit-clue/reset.c | 36 +++++++++ 10 files changed, 399 insertions(+) create mode 100644 boards/adafruit-clue/Makefile create mode 100644 boards/adafruit-clue/Makefile.dep create mode 100644 boards/adafruit-clue/Makefile.features create mode 100644 boards/adafruit-clue/Makefile.include create mode 100644 boards/adafruit-clue/board.c create mode 100644 boards/adafruit-clue/doc.txt create mode 100644 boards/adafruit-clue/include/board.h create mode 100644 boards/adafruit-clue/include/gpio_params.h create mode 100644 boards/adafruit-clue/include/periph_conf.h create mode 100644 boards/adafruit-clue/reset.c diff --git a/boards/adafruit-clue/Makefile b/boards/adafruit-clue/Makefile new file mode 100644 index 0000000000000..f8fcbb53a0659 --- /dev/null +++ b/boards/adafruit-clue/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/adafruit-clue/Makefile.dep b/boards/adafruit-clue/Makefile.dep new file mode 100644 index 0000000000000..96b683181ce15 --- /dev/null +++ b/boards/adafruit-clue/Makefile.dep @@ -0,0 +1,18 @@ +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio + USEMODULE += bmp280_i2c + USEMODULE += lis3mdl + USEMODULE += sht3x +endif + +# Provide stdio over USB by default +DEFAULT_MODULE += stdio_cdc_acm + +# Default auto-initialization of usbus for stdio other USB +DEFAULT_MODULE += auto_init_usbus + +# This boards requires support for Arduino bootloader. +USEMODULE += arduino_bootloader + +# include common nrf52 dependencies +include $(RIOTBOARD)/common/nrf52/Makefile.dep diff --git a/boards/adafruit-clue/Makefile.features b/boards/adafruit-clue/Makefile.features new file mode 100644 index 0000000000000..bb77f3ce1c32a --- /dev/null +++ b/boards/adafruit-clue/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 += radio_nrf802154 + +include $(RIOTBOARD)/common/nrf52/Makefile.features diff --git a/boards/adafruit-clue/Makefile.include b/boards/adafruit-clue/Makefile.include new file mode 100644 index 0000000000000..2cb268396393c --- /dev/null +++ b/boards/adafruit-clue/Makefile.include @@ -0,0 +1,26 @@ +# Bossa is the default programmer +PROGRAMMER ?= adafruit-nrfutil + +ifeq ($(PROGRAMMER),adafruit-nrfutil) + # The preinstalled bootloader must also be taken into account so + # ROM_OFFSET skips the space taken by such bootloader. + ROM_OFFSET = 0x26000 + + ifneq (,$(filter reset flash flash-only, $(MAKECMDGOALS))) + # Add 2 seconds delay before opening terminal: this is required when opening + # the terminal right after flashing. In this case, the stdio over USB needs + # some time after reset before being ready. + TERM_DELAY = 2 + TERMDEPS += term-delay + endif + + include $(RIOTMAKE)/tools/adafruit-nrfutil.inc.mk +endif + +term-delay: + sleep $(TERM_DELAY) + +TESTRUNNER_CONNECT_DELAY ?= 2 +$(call target-export-variables,test,TESTRUNNER_CONNECT_DELAY) + +include $(RIOTBOARD)/common/nrf52/Makefile.include diff --git a/boards/adafruit-clue/board.c b/boards/adafruit-clue/board.c new file mode 100644 index 0000000000000..844079418963e --- /dev/null +++ b/boards/adafruit-clue/board.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 Inria + * + * 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_adafruit-clue + * @{ + * + * @file + * @brief Board initialization for the Adafruit Clue + * + * @author Alexandre Abadie + * + * @} + */ + +#include "cpu.h" +#include "board.h" + +#include "periph/gpio.h" + +void board_init(void) +{ + /* initialize the CPU */ + cpu_init(); + + /* initialize the boards LEDs */ + gpio_init(LED0_PIN, GPIO_OUT); /* Red LED */ +} diff --git a/boards/adafruit-clue/doc.txt b/boards/adafruit-clue/doc.txt new file mode 100644 index 0000000000000..4c73a27bd6e62 --- /dev/null +++ b/boards/adafruit-clue/doc.txt @@ -0,0 +1,39 @@ +/** +@defgroup boards_adafruit-clue Adafruit Clue +@ingroup boards +@brief Support for the Adafruit Clue + +### General information + +The [Adafruit Clue](https://www.adafruit.com/clue) board +is an opensource, micro development kit using the nRF52840 SoC. +This board provides 802.15.4 and BLE connectivity. + +Adafruit Clue + +### Schematics + +The board detailed description and schematic is available +[here](https://github.com/adafruit/Adafruit-CLUE-PCB). + +### Flash the board + +The board is flashed using the `nrfutil` Python package. + +Once `nrfutil` is installed, ase `BOARD=adafruit-clue` with the `make` command.
+Example with `hello-world` application: +``` + make BOARD=adafruit-clue -C examples/hello-world flash +``` + +### Accessing STDIO via UART + +The STDIO is directly accessible via the USB port. On a Linux host, it's +generally mapped to `/dev/ttyACM0`. + +Use the `term` target to connect to the board serial port
+``` + make BOARD=adafruit-clue -C examples/hello-world term +``` + */ diff --git a/boards/adafruit-clue/include/board.h b/boards/adafruit-clue/include/board.h new file mode 100644 index 0000000000000..f7a260d889b83 --- /dev/null +++ b/boards/adafruit-clue/include/board.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020 Inria + * + * 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_adafruit-clue + * @{ + * + * @file + * @brief Board specific configuration for the Adafruit Clue board + * + * @author Alexandre Abadie + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" +#include "board_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name LEDs pin configuration + * @{ + */ +#define LED0_PIN GPIO_PIN(1, 1) +#define LED0_MASK (1 << 1) +#define LED0_ON (NRF_P1->OUTCLR = LED0_MASK) +#define LED0_OFF (NRF_P1->OUTSET = LED0_MASK) +#define LED0_TOGGLE (NRF_P1->OUT ^= LED0_MASK) +/** @} */ + +/** + * @name Button pin configuration + * @{ + */ +#define BTN0_PIN GPIO_PIN(1, 10) /* Right button */ +#define BTN0_MODE GPIO_IN_PU + +#define BTN1_PIN GPIO_PIN(1, 2) /* Left button */ +#define BTN1_MODE GPIO_IN_PU +/** @} */ + +/** + * @name LIS3MDL 3-axis magnetometer I2C address + */ +#define LIS3MDL_PARAM_ADDR (0x1C) +/** @} */ + +/** + * @name STH31 temperature and humidity sensor I2C address + */ +#define SHT3X_PARAM_I2C_ADDR (SHT3X_I2C_ADDR_1) +/** @} */ + +/** + * @name Button pin configuration + * @{ + */ +#define ILI9341_PARAM_SPI SPI_DEV(1) +#define ILI9341_PARAM_CS GPIO_PIN(0, 12) +#define ILI9341_PARAM_DCX GPIO_PIN(0, 13) +#define ILI9341_PARAM_NUM_LINES (240U) +#define ILI9341_PARAM_RGB (1) +#define ILI9341_PARAM_INVERTED (1) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/adafruit-clue/include/gpio_params.h b/boards/adafruit-clue/include/gpio_params.h new file mode 100644 index 0000000000000..00b9336066900 --- /dev/null +++ b/boards/adafruit-clue/include/gpio_params.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 Inria + * + * 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_adafruit-clue + * @{ + * + * @file + * @brief Configuration of SAUL mapped GPIO pins + * + * @author Alexandre Abadie + */ + +#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 = "LED0 (Red)", + .pin = LED0_PIN, + .mode = GPIO_OUT, + }, + { + .name = "Button (Right)", + .pin = BTN0_PIN, + .mode = BTN0_MODE, + .flags = SAUL_GPIO_INVERTED, + }, + { + .name = "Button (Left)", + .pin = BTN1_PIN, + .mode = BTN1_MODE, + .flags = SAUL_GPIO_INVERTED, + } +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/adafruit-clue/include/periph_conf.h b/boards/adafruit-clue/include/periph_conf.h new file mode 100644 index 0000000000000..2abf71589bec9 --- /dev/null +++ b/boards/adafruit-clue/include/periph_conf.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2020 Inria + * + * 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_adafruit-clue + * @{ + * + * @file + * @brief Peripheral configuration for the Adafruit Clue board + * + * @author Alexandre Abadie + * + */ + +#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(0, 4), + .tx_pin = GPIO_PIN(0, 5), + .rts_pin = (uint8_t)GPIO_UNDEF, + .cts_pin = (uint8_t)GPIO_UNDEF, + .irqn = UARTE0_UART0_IRQn, + }, +}; + +#define UART_0_ISR (isr_uart0) + +#define UART_NUMOF ARRAY_SIZE(uart_config) +/** @} */ + +/** + * @name I2C configuration + * @{ + */ +static const i2c_conf_t i2c_config[] = { + { + .dev = NRF_TWIM0, + .scl = GPIO_PIN(0, 25), + .sda = GPIO_PIN(0, 24), + .speed = I2C_SPEED_NORMAL + }, +}; + +#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0])) +/** @} */ + +/** + * @name SPI configuration + * @{ + */ +static const spi_conf_t spi_config[] = { + { + .dev = NRF_SPI0, + .sclk = GPIO_PIN(0, 8), + .mosi = GPIO_PIN(0, 26), + .miso = GPIO_PIN(0, 06), + }, + { /* TFT LCD screen */ + .dev = NRF_SPI1, + .sclk = GPIO_PIN(0, 14), + .mosi = GPIO_PIN(0, 15), + .miso = GPIO_PIN(0, 0), + }, +}; + +#define SPI_NUMOF ARRAY_SIZE(spi_config) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */ diff --git a/boards/adafruit-clue/reset.c b/boards/adafruit-clue/reset.c new file mode 100644 index 0000000000000..85a099f08f013 --- /dev/null +++ b/boards/adafruit-clue/reset.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 Inria + * + * 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_arduino-nano-33-ble + * @{ + * @file + * @brief Implementation for managing the Arduino bootloader + * + * @author Alexandre Abadie + * + * @} + */ + +#include "periph/pm.h" + + +#define NRF52_DOUBLE_TAP_MAGIC_NUMBER (0x4e) + +void reset_in_application(void) +{ + pm_reboot(); + while (1) {} +} + +void reset_in_bootloader(void) +{ + NRF_POWER->GPREGRET = NRF52_DOUBLE_TAP_MAGIC_NUMBER; + + reset_in_application(); +}