From 94b7b242b2d450a168de8c1bf310e80a0dfb2622 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 14 Nov 2018 18:45:12 +0100 Subject: [PATCH] boards/nrf51dk: add initial support --- boards/nrf51dk/Makefile | 3 + boards/nrf51dk/Makefile.dep | 5 ++ boards/nrf51dk/Makefile.features | 7 +++ boards/nrf51dk/Makefile.include | 17 ++++++ boards/nrf51dk/board.c | 44 ++++++++++++++ boards/nrf51dk/doc.txt | 33 +++++++++++ boards/nrf51dk/include/board.h | 78 ++++++++++++++++++++++++ boards/nrf51dk/include/gpio_params.h | 89 ++++++++++++++++++++++++++++ boards/nrf51dk/include/periph_conf.h | 81 +++++++++++++++++++++++++ 9 files changed, 357 insertions(+) create mode 100644 boards/nrf51dk/Makefile create mode 100644 boards/nrf51dk/Makefile.dep create mode 100644 boards/nrf51dk/Makefile.features create mode 100644 boards/nrf51dk/Makefile.include create mode 100644 boards/nrf51dk/board.c create mode 100644 boards/nrf51dk/doc.txt create mode 100644 boards/nrf51dk/include/board.h create mode 100644 boards/nrf51dk/include/gpio_params.h create mode 100644 boards/nrf51dk/include/periph_conf.h diff --git a/boards/nrf51dk/Makefile b/boards/nrf51dk/Makefile new file mode 100644 index 0000000000..f8fcbb53a0 --- /dev/null +++ b/boards/nrf51dk/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/nrf51dk/Makefile.dep b/boards/nrf51dk/Makefile.dep new file mode 100644 index 0000000000..6df82abd16 --- /dev/null +++ b/boards/nrf51dk/Makefile.dep @@ -0,0 +1,5 @@ +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio +endif + +include $(RIOTBOARD)/common/nrf51/Makefile.dep diff --git a/boards/nrf51dk/Makefile.features b/boards/nrf51dk/Makefile.features new file mode 100644 index 0000000000..94158d8eed --- /dev/null +++ b/boards/nrf51dk/Makefile.features @@ -0,0 +1,7 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_uart + +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features diff --git a/boards/nrf51dk/Makefile.include b/boards/nrf51dk/Makefile.include new file mode 100644 index 0000000000..1290b19c62 --- /dev/null +++ b/boards/nrf51dk/Makefile.include @@ -0,0 +1,17 @@ +# define the used CPU +export CPU_MODEL = nrf51x22xxac + +# define the default port depending on the host OS +PORT_LINUX ?= /dev/ttyACM0 +PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) + +# use openocd by default to program this board +PROGRAMMER ?= openocd + +# dap debug adapter is required for openocd +ifeq (openocd,$(PROGRAMMER)) + DEBUG_ADAPTER = dap +endif + +# include nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/nrf51dk/board.c b/boards/nrf51dk/board.c new file mode 100644 index 0000000000..5b72baa4da --- /dev/null +++ b/boards/nrf51dk/board.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 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_nrf51dk + * @{ + * + * @file + * @brief Board initialization code for the nRF51DK + * + * @author Alexandre Abadie + * + * @} + */ + +#include "board.h" +#include "periph/gpio.h" + +void board_init(void) +{ + /* initialize the board LEDs, set pins as output and turn LEDs off */ + gpio_init(LED0_PIN, GPIO_OUT); + gpio_init(LED1_PIN, GPIO_OUT); + gpio_init(LED2_PIN, GPIO_OUT); + gpio_init(LED3_PIN, GPIO_OUT); + gpio_set(LED0_PIN); + gpio_set(LED1_PIN); + gpio_set(LED2_PIN); + gpio_set(LED3_PIN); + + /* initialize the board buttons */ + gpio_init(BTN0_PIN, BTN0_MODE); + gpio_init(BTN1_PIN, BTN1_MODE); + gpio_init(BTN2_PIN, BTN2_MODE); + gpio_init(BTN3_PIN, BTN3_MODE); + + /* initialize the CPU */ + cpu_init(); +} diff --git a/boards/nrf51dk/doc.txt b/boards/nrf51dk/doc.txt new file mode 100644 index 0000000000..93090d1bee --- /dev/null +++ b/boards/nrf51dk/doc.txt @@ -0,0 +1,33 @@ +/** +@defgroup boards_nrf51dk nRF51DK Development Kit +@ingroup boards +@brief Support for the Nordic nRF51DK Development Kit + +## Overview: + +The nRF51 DK is a low-cost, versatile single-board development kit for +Bluetooth low energy, ANT and 2.4GHz proprietary applications using the nRF51 +Series SoC. + +## Flashing the Device: + +The nRF51DK board is shipped with an on-board JLink debugger that doesn't work +well with UART: the shell is only working on RX but not TX. + +Thus, we recommend to update the flasher ship with DAPLink as described +[here](https://armmbed.github.io/DAPLink/?board=Nordic-nRF51-DK): +1. Download [this firmware](https://armmbed.github.io/DAPLink//firmware/0251_sam3u2c_mkit_dk_dongle_nrf5x_0x5000.bin) +2. While holding down the boards reset button, connect the boards USB debug + port to the computer. It should enumerate as `BOOTLOADER` +3. Using a filesystem browser, drag-n-drop the firmware file to the + `BOOTLOADER` folder +4. Power-cycle the board, a new DAPLink mount point should appear + +The programmer used to flash this board is OpenOCD. + +To flash the board, use the following command: +``` +$ make BOARD=nrf51dk flash +``` +from any application directory. + */ diff --git a/boards/nrf51dk/include/board.h b/boards/nrf51dk/include/board.h new file mode 100644 index 0000000000..6e14b6de3f --- /dev/null +++ b/boards/nrf51dk/include/board.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2018 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_nrf51dk + * @{ + * + * @file + * @brief Board specific configuration for the nRF51DK + * + * @author Alexandre Abadie + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "board_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name LED pin definitions and handlers + * @{ + */ +#define LED0_PIN GPIO_PIN(0, 21) +#define LED1_PIN GPIO_PIN(0, 22) +#define LED2_PIN GPIO_PIN(0, 23) +#define LED3_PIN GPIO_PIN(0, 24) + +#define LED0_MASK (1 << 21) +#define LED1_MASK (1 << 22) +#define LED2_MASK (1 << 23) +#define LED3_MASK (1 << 24) + +#define LED0_ON (NRF_GPIO->OUTCLR = LED0_MASK) +#define LED0_OFF (NRF_GPIO->OUTSET = LED0_MASK) +#define LED0_TOGGLE (NRF_GPIO->OUT ^= LED0_MASK) + +#define LED1_ON (NRF_GPIO->OUTCLR = LED1_MASK) +#define LED1_OFF (NRF_GPIO->OUTSET = LED1_MASK) +#define LED1_TOGGLE (NRF_GPIO->OUT ^= LED1_MASK) + +#define LED2_ON (NRF_GPIO->OUTCLR = LED2_MASK) +#define LED2_OFF (NRF_GPIO->OUTSET = LED2_MASK) +#define LED2_TOGGLE (NRF_GPIO->OUT ^= LED2_MASK) + +#define LED3_ON (NRF_GPIO->OUTCLR = LED3_MASK) +#define LED3_OFF (NRF_GPIO->OUTSET = LED3_MASK) +#define LED3_TOGGLE (NRF_GPIO->OUT ^= LED3_MASK) +/** @} */ + +/** + * @name Button pin definitions + * @{ + */ +#define BTN0_PIN GPIO_PIN(0, 17) +#define BTN0_MODE GPIO_IN_PU +#define BTN1_PIN GPIO_PIN(0, 18) +#define BTN1_MODE GPIO_IN_PU +#define BTN2_PIN GPIO_PIN(0, 19) +#define BTN2_MODE GPIO_IN_PU +#define BTN3_PIN GPIO_PIN(0, 20) +#define BTN3_MODE GPIO_IN_PU +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/nrf51dk/include/gpio_params.h b/boards/nrf51dk/include/gpio_params.h new file mode 100644 index 0000000000..44210728a2 --- /dev/null +++ b/boards/nrf51dk/include/gpio_params.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2018 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_nrf51dk + * @{ + * + * @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 = "LED 1", + .pin = LED0_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "LED 2", + .pin = LED1_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "LED 3", + .pin = LED2_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "LED 4", + .pin = LED3_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "Button 1", + .pin = BTN0_PIN, + .mode = BTN0_MODE, + .flags = SAUL_GPIO_INVERTED, + }, + { + .name = "Button 2", + .pin = BTN1_PIN, + .mode = BTN1_MODE, + .flags = SAUL_GPIO_INVERTED, + }, + { + .name = "Button 3", + .pin = BTN2_PIN, + .mode = BTN2_MODE, + .flags = SAUL_GPIO_INVERTED, + }, + { + .name = "Button 4", + .pin = BTN3_PIN, + .mode = BTN3_MODE, + .flags = SAUL_GPIO_INVERTED, + }, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/nrf51dk/include/periph_conf.h b/boards/nrf51dk/include/periph_conf.h new file mode 100644 index 0000000000..8b58aea3ce --- /dev/null +++ b/boards/nrf51dk/include/periph_conf.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2018 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_nrf51dk + * @{ + * + * @file + * @brief Peripheral configuration for the Nordic nRF51DK + * + * @author Alexandre Abadie + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#include "periph_cpu.h" +#include "periph_conf_common.h" +#include "cfg_clock_16_1.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name UART configuration + * @{ + */ +#define UART_NUMOF (1U) +/* UART pin configuration */ +#define UART_HWFLOWCTRL 1 +#define UART_PIN_RX 11 +#define UART_PIN_TX 9 +#define UART_PIN_RTS 8 +#define UART_PIN_CTS 10 +/** @} */ + +/** + * @name SPI configuration + * @{ + */ +static const spi_conf_t spi_config[] = { + { + .dev = NRF_SPI0, + .sclk = 29, + .mosi = 25, + .miso = 28 + } +}; + +#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0])) +/** @} */ + +/** + * @name I2C configuration + * @{ + */ +static const i2c_conf_t i2c_config[] = { + { + .dev = NRF_TWI1, + .pin_scl = 7, + .pin_sda = 30, + .ppi = 0, + .speed = I2C_SPEED_NORMAL + } +}; + +#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0])) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */ +/** @} */