From a12b61e9af1988fbdc37aa8999fda6ad8524550e Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 23 Aug 2018 17:20:22 +0200 Subject: [PATCH] boards/nrf52840-mdk: initial support --- boards/nrf52840-mdk/Makefile | 3 + boards/nrf52840-mdk/Makefile.dep | 5 ++ boards/nrf52840-mdk/Makefile.features | 5 ++ boards/nrf52840-mdk/Makefile.include | 18 ++++++ boards/nrf52840-mdk/board.c | 38 ++++++++++++ boards/nrf52840-mdk/dist/openocd.cfg | 2 + boards/nrf52840-mdk/doc.txt | 50 ++++++++++++++++ boards/nrf52840-mdk/include/board.h | 69 ++++++++++++++++++++++ boards/nrf52840-mdk/include/gpio_params.h | 66 +++++++++++++++++++++ boards/nrf52840-mdk/include/periph_conf.h | 72 +++++++++++++++++++++++ 10 files changed, 328 insertions(+) create mode 100644 boards/nrf52840-mdk/Makefile create mode 100644 boards/nrf52840-mdk/Makefile.dep create mode 100644 boards/nrf52840-mdk/Makefile.features create mode 100644 boards/nrf52840-mdk/Makefile.include create mode 100644 boards/nrf52840-mdk/board.c create mode 100644 boards/nrf52840-mdk/dist/openocd.cfg create mode 100644 boards/nrf52840-mdk/doc.txt create mode 100644 boards/nrf52840-mdk/include/board.h create mode 100644 boards/nrf52840-mdk/include/gpio_params.h create mode 100644 boards/nrf52840-mdk/include/periph_conf.h diff --git a/boards/nrf52840-mdk/Makefile b/boards/nrf52840-mdk/Makefile new file mode 100644 index 0000000000..f8fcbb53a0 --- /dev/null +++ b/boards/nrf52840-mdk/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/nrf52840-mdk/Makefile.dep b/boards/nrf52840-mdk/Makefile.dep new file mode 100644 index 0000000000..7317b22d44 --- /dev/null +++ b/boards/nrf52840-mdk/Makefile.dep @@ -0,0 +1,5 @@ +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio +endif + +include $(RIOTBOARD)/common/nrf52/Makefile.dep diff --git a/boards/nrf52840-mdk/Makefile.features b/boards/nrf52840-mdk/Makefile.features new file mode 100644 index 0000000000..e201287c34 --- /dev/null +++ b/boards/nrf52840-mdk/Makefile.features @@ -0,0 +1,5 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_uart + +include $(RIOTBOARD)/common/nrf52/Makefile.features diff --git a/boards/nrf52840-mdk/Makefile.include b/boards/nrf52840-mdk/Makefile.include new file mode 100644 index 0000000000..8c03241645 --- /dev/null +++ b/boards/nrf52840-mdk/Makefile.include @@ -0,0 +1,18 @@ +export CPU_MODEL = nrf52840xxaa + +# This board uses a DAP-Link programmer +# Flashing support is provided through pyocd (default) and openocd. +# For openocd, a version built against the development branch and containing +# the support for nrf52 cpu is required. +PROGRAMMER ?= pyocd +ifeq (pyocd,$(PROGRAMMER)) + # The board is not recognized automatically by pyocd, so the CPU target + # option is passed explicitly + export FLASH_TARGET_TYPE ?= -t $(CPU) + include $(RIOTMAKE)/tools/pyocd.inc.mk +else ifeq (openocd,$(PROGRAMMER)) + export DEBUG_ADAPTER ?= dap + include $(RIOTMAKE)/tools/openocd.inc.mk +endif + +include $(RIOTBOARD)/common/nrf52/Makefile.include diff --git a/boards/nrf52840-mdk/board.c b/boards/nrf52840-mdk/board.c new file mode 100644 index 0000000000..7b7f6bab01 --- /dev/null +++ b/boards/nrf52840-mdk/board.c @@ -0,0 +1,38 @@ +/* + * 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_nrf52840-mdk + * @{ + * + * @file + * @brief Board initialization for the nRF52840-MDK + * + * @author Alexandre Abadie + * + * @} + */ + +#include "cpu.h" +#include "board.h" + +#include "periph/gpio.h" + +void board_init(void) +{ + /* initialize the boards LEDs */ + gpio_init(LED0_PIN, GPIO_OUT); + gpio_set(LED0_PIN); + gpio_init(LED1_PIN, GPIO_OUT); + gpio_set(LED1_PIN); + gpio_init(LED2_PIN, GPIO_OUT); + gpio_set(LED2_PIN); + + /* initialize the CPU */ + cpu_init(); +} diff --git a/boards/nrf52840-mdk/dist/openocd.cfg b/boards/nrf52840-mdk/dist/openocd.cfg new file mode 100644 index 0000000000..60f0681d52 --- /dev/null +++ b/boards/nrf52840-mdk/dist/openocd.cfg @@ -0,0 +1,2 @@ +transport select swd +source [find target/nrf52.cfg] diff --git a/boards/nrf52840-mdk/doc.txt b/boards/nrf52840-mdk/doc.txt new file mode 100644 index 0000000000..b02b5c96f8 --- /dev/null +++ b/boards/nrf52840-mdk/doc.txt @@ -0,0 +1,50 @@ +/** +@defgroup boards_nrf52840-mdk nRF52840-MDK +@ingroup boards +@brief Support for the nRF52840-MDK + +### General information + +The Makerdiary [nRF52840-MDK](https://github.com/makerdiary/nrf52840-mdk) board +is an opensource, micro development kit using the nRF52840 SoC. +This board provides 802.15.4 and BLE connectivity. + +### Pinout + +pinout + +### Flash the board + +By default, the board is flashed with PyOCD programmer via a DAPLink. + +PyOCD can be installed using Python package manager: +``` + pip install pyocd --user -U +``` + +To flash the board `BOARD=nrf52840-mdk` with the `make` command.
+Example with `hello-world` application: +``` + make BOARD=nrf52840-mdk -C examples/hello-world flash +``` + +OpenOCD can also be used. For the moment, the latest stable version of OpenOCD +(0.10) doesn't contain any support for nrf52 but versions built against the +actual development version can be used. + +To flash the board with OpenOCD, use the `PROGRAMMER` variable: +``` + PROGRAMMER=openocd make BOARD=nrf52840-mdk -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=nrf52840-mdk -C examples/hello-world term +``` + */ diff --git a/boards/nrf52840-mdk/include/board.h b/boards/nrf52840-mdk/include/board.h new file mode 100644 index 0000000000..34a773eba7 --- /dev/null +++ b/boards/nrf52840-mdk/include/board.h @@ -0,0 +1,69 @@ +/* + * 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_nrf52840-mdk + * @{ + * + * @file + * @brief Board specific configuration for the nRF52840-MDK + * + * @author Alexandre Abadie + */ + +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" +#include "board_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name LED pin configuration + * @{ + */ +#define LED0_PIN GPIO_PIN(0, 23) +#define LED1_PIN GPIO_PIN(0, 22) +#define LED2_PIN GPIO_PIN(0, 24) + +#define LED_PORT (NRF_P0) +#define LED0_MASK (1 << 23) +#define LED1_MASK (1 << 22) +#define LED2_MASK (1 << 24) +#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 Button pin configuration + * @{ + */ +#define BTN0_PIN GPIO_PIN(1, 0) +#define BTN0_MODE GPIO_IN_PU +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/nrf52840-mdk/include/gpio_params.h b/boards/nrf52840-mdk/include/gpio_params.h new file mode 100644 index 0000000000..b94c9499aa --- /dev/null +++ b/boards/nrf52840-mdk/include/gpio_params.h @@ -0,0 +1,66 @@ +/* + * 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_nrf52840-mdk + * @{ + * + * @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 Red", + .pin = LED0_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "Led Green", + .pin = LED1_PIN, + .mode = GPIO_OUT, + .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR), + }, + { + .name = "Led Blue", + .pin = LED2_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, + }, +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/nrf52840-mdk/include/periph_conf.h b/boards/nrf52840-mdk/include/periph_conf.h new file mode 100644 index 0000000000..8d92ec2818 --- /dev/null +++ b/boards/nrf52840-mdk/include/periph_conf.h @@ -0,0 +1,72 @@ +/* + * 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_nrf52840-mdk + * @{ + * + * @file + * @brief Peripheral configuration for the nRF52840-MDK + * + * @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,19), + .tx_pin = GPIO_PIN(0,20), + .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 (sizeof(uart_config) / sizeof(uart_config[0])) +/** @} */ + +/** + * @name SPI configuration + * @{ + */ +static const spi_conf_t spi_config[] = { + { + .dev = NRF_SPI0, + .sclk = 15, + .mosi = 13, + .miso = 14 + } +}; + +#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0])) +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */