diff --git a/boards/adafruit-clue/Makefile b/boards/adafruit-clue/Makefile new file mode 100644 index 0000000000..f8fcbb53a0 --- /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 0000000000..130b71241b --- /dev/null +++ b/boards/adafruit-clue/Makefile.dep @@ -0,0 +1,18 @@ +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio + USEMODULE += apds9960 + USEMODULE += bmp280_i2c + USEMODULE += lis3mdl + USEMODULE += sht3x +endif + +# use nrfutil-bootloader/stdio_cdc_acm only if no other stdio_% other than stdio_cdc_acm +# is requested +ifeq (,$(filter-out stdio_cdc_acm,$(filter stdio_% slipdev_stdio,$(USEMODULE)))) + FEATURES_REQUIRED += bootloader_nrfutil + USEMODULE += usb_board_reset + USEMODULE += stdio_cdc_acm +endif + +# 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 0000000000..a14380c081 --- /dev/null +++ b/boards/adafruit-clue/Makefile.features @@ -0,0 +1,13 @@ +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 +FEATURES_PROVIDED += bootloader_nrfutil + +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 0000000000..c50d8b0686 --- /dev/null +++ b/boards/adafruit-clue/Makefile.include @@ -0,0 +1,26 @@ +# Adafruit-nrfutil is the default programmer +PROGRAMMER ?= adafruit-nrfutil + +include $(RIOTBOARD)/common/nrf52/Makefile.include + +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 ?= $(TERM_DELAY) +$(call target-export-variables,test,TESTRUNNER_CONNECT_DELAY) diff --git a/boards/adafruit-clue/board.c b/boards/adafruit-clue/board.c new file mode 100644 index 0000000000..f531f517d3 --- /dev/null +++ b/boards/adafruit-clue/board.c @@ -0,0 +1,37 @@ +/* + * 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 */ + + /* initialize the screen backlight, turn it off by default */ + gpio_init(BACKLIGHT_PIN, GPIO_OUT); + gpio_clear(BACKLIGHT_PIN); +} diff --git a/boards/adafruit-clue/doc.txt b/boards/adafruit-clue/doc.txt new file mode 100644 index 0000000000..662902cfef --- /dev/null +++ b/boards/adafruit-clue/doc.txt @@ -0,0 +1,45 @@ +/** +@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 `adafruit-nrfutil` Python package: +``` + $ pip install --user adafruit-nrfutil +``` + +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 +``` + +The `TERM_DELAY` environment variable can be used to add a delay (in second) +before opening the serial terminal. The default value is 2s which should be +enough in most of the situations. + */ diff --git a/boards/adafruit-clue/include/board.h b/boards/adafruit-clue/include/board.h new file mode 100644 index 0000000000..2de1266f2f --- /dev/null +++ b/boards/adafruit-clue/include/board.h @@ -0,0 +1,115 @@ +/* + * 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->OUTSET = LED0_MASK) +#define LED0_OFF (NRF_P1->OUTCLR = LED0_MASK) +#define LED0_TOGGLE (NRF_P1->OUT ^= LED0_MASK) +/** @} */ + +/** + * @name Button pin configuration + * @{ + */ +#define BTN0_PIN GPIO_PIN(1, 2) /* Button A */ +#define BTN0_MODE GPIO_IN_PU + +#define BTN1_PIN GPIO_PIN(1, 10) /* Button B */ +#define BTN1_MODE GPIO_IN_PU +/** @} */ + +/** + * @name APDS9960 sensor configuration + * @{ + */ +#define APDS99XX_PARAM_DEV I2C_DEV(1) +#define APDS99XX_PARAM_INT_PIN GPIO_PIN(0, 9) +/** @} */ + +/** + * @name BMP280 sensor configuration + * @{ + */ +#define BMX280_PARAM_I2C_DEV I2C_DEV(1) +/** @} */ + +/** + * @name LIS3MDL 3-axis magnetometer I2C address + */ +#define LIS3MDL_PARAM_I2C I2C_DEV(1) +#define LIS3MDL_PARAM_ADDR (0x1C) +/** @} */ + +/** + * @name STH31 temperature and humidity sensor I2C address + */ +#define SHT3X_PARAM_I2C_DEV I2C_DEV(1) +#define SHT3X_PARAM_I2C_ADDR (SHT3X_I2C_ADDR_1) +/** @} */ + +/** + * @name Speaker pin + * @{ + */ +#define SPKR_PIN GPIO_PIN(1, 0) +/** @ */ + +/** + * @name Backlight control defines, default uses LCD_BACKLIGHT_LOW values + * @{ + */ +#define BACKLIGHT_PIN GPIO_PIN(1, 5) +#define BACKLIGHT_MASK (1 << 5) +#define BACKLIGHT_ON (NRF_P1->OUTSET = BACKLIGHT_MASK) +#define BACKLIGHT_OFF (NRF_P1->OUTCLR = BACKLIGHT_MASK) +/** @ */ + +/** + * @name Display 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_RST GPIO_PIN(1, 3) +#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 0000000000..2dad21d464 --- /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 A", + .pin = BTN0_PIN, + .mode = BTN0_MODE, + .flags = SAUL_GPIO_INVERTED, + }, + { + .name = "Button B", + .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 0000000000..ecc68417ce --- /dev/null +++ b/boards/adafruit-clue/include/periph_conf.h @@ -0,0 +1,102 @@ +/* + * 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), +#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 I2C configuration + * @{ + */ +static const i2c_conf_t i2c_config[] = { + { /* External connectors */ + .dev = NRF_TWIM0, + .scl = GPIO_PIN(0, 0), /* D19 */ + .sda = GPIO_PIN(0, 30), /* D20 */ + .speed = I2C_SPEED_NORMAL + }, + { /* On board sensors */ + .dev = NRF_TWIM1, + .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[] = { + { /* External connectors */ + .dev = NRF_SPI0, + .sclk = GPIO_PIN(0, 23), /* D13 */ + .mosi = GPIO_PIN(0, 21), /* D15 */ + .miso = GPIO_PIN(0, 22), /* D14 */ + }, + { /* 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 0000000000..f73da298a5 --- /dev/null +++ b/boards/adafruit-clue/reset.c @@ -0,0 +1,37 @@ +/* + * 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 Implementation for managing the nrfutil bootloader + * + * @author Alexandre Abadie + * + * @} + */ + +#ifdef MODULE_USB_BOARD_RESET + +#define USB_H_USER_IS_RIOT_INTERNAL + +#include "usb_board_reset.h" + +/* Set the value used by the bootloader to select between boot in + application and boot in bootloader mode. */ +#define NRF52_DOUBLE_TAP_MAGIC_NUMBER (0x4e) + +void usb_board_reset_in_bootloader(void) +{ + NRF_POWER->GPREGRET = NRF52_DOUBLE_TAP_MAGIC_NUMBER; + + usb_board_reset_in_application(); +} + +#endif /* MODULE_USB_BOARD_RESET */