From 84cdab8c0b5cebc890b9e6861c82ce2f74d0b8cf Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 17:55:23 +0200 Subject: [PATCH 1/9] boards/common/nrf51: introduce common location --- boards/airfy-beacon/board.c | 28 ---------- boards/common/nrf51/Makefile | 3 + boards/common/nrf51/Makefile.dep | 3 + boards/common/nrf51/Makefile.features | 5 ++ boards/common/nrf51/Makefile.include | 18 ++++++ .../{yunjia-nrf51822 => common/nrf51}/board.c | 4 +- .../nrf51}/dist/openocd.cfg | 0 boards/common/nrf51/include/board_common.h | 50 +++++++++++++++++ .../common/nrf51/include/periph_conf_common.h | 56 +++++++++++++++++++ boards/yunjia-nrf51822/dist/openocd.cfg | 3 - 10 files changed, 137 insertions(+), 33 deletions(-) delete mode 100644 boards/airfy-beacon/board.c create mode 100644 boards/common/nrf51/Makefile create mode 100644 boards/common/nrf51/Makefile.dep create mode 100644 boards/common/nrf51/Makefile.features create mode 100644 boards/common/nrf51/Makefile.include rename boards/{yunjia-nrf51822 => common/nrf51}/board.c (79%) rename boards/{airfy-beacon => common/nrf51}/dist/openocd.cfg (100%) create mode 100644 boards/common/nrf51/include/board_common.h create mode 100644 boards/common/nrf51/include/periph_conf_common.h delete mode 100644 boards/yunjia-nrf51822/dist/openocd.cfg diff --git a/boards/airfy-beacon/board.c b/boards/airfy-beacon/board.c deleted file mode 100644 index ef39f2bac0..0000000000 --- a/boards/airfy-beacon/board.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2014 Christian Mehlis - * - * 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_airfy-beacon - * @{ - * - * @file - * @brief Board specific implementations for the Airfy Beacon board - * - * @author Christian Mehlis - * - * @} - */ - -#include "board.h" -#include "cpu.h" - -void board_init(void) -{ - /* initialize the CPU */ - cpu_init(); -} diff --git a/boards/common/nrf51/Makefile b/boards/common/nrf51/Makefile new file mode 100644 index 0000000000..3a930db95c --- /dev/null +++ b/boards/common/nrf51/Makefile @@ -0,0 +1,3 @@ +MODULE = boards_common_nrf51 + +include $(RIOTBASE)/Makefile.base diff --git a/boards/common/nrf51/Makefile.dep b/boards/common/nrf51/Makefile.dep new file mode 100644 index 0000000000..7de44689f6 --- /dev/null +++ b/boards/common/nrf51/Makefile.dep @@ -0,0 +1,3 @@ +ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE))) + USEMODULE += nrfmin +endif diff --git a/boards/common/nrf51/Makefile.features b/boards/common/nrf51/Makefile.features new file mode 100644 index 0000000000..e1e4f8a581 --- /dev/null +++ b/boards/common/nrf51/Makefile.features @@ -0,0 +1,5 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_rtt +FEATURES_PROVIDED += periph_timer + +-include $(RIOTCPU)/nrf51/Makefile.features diff --git a/boards/common/nrf51/Makefile.include b/boards/common/nrf51/Makefile.include new file mode 100644 index 0000000000..ac436a8ae7 --- /dev/null +++ b/boards/common/nrf51/Makefile.include @@ -0,0 +1,18 @@ +# define the used CPU +export CPU = nrf51 + +# setup serial terminal +include $(RIOTMAKE)/tools/serial.inc.mk + +# include common nrf51 headers +INCLUDES += -I$(RIOTBOARD)/common/nrf51/include + +ifeq ($(PROGRAMMER),openocd) + # use common openocd configuration for nrf51 + export OPENOCD_CONFIG = $(RIOTBOARD)/common/nrf51/dist/openocd.cfg + include $(RIOTMAKE)/tools/openocd.inc.mk +else ifeq ($(PROGRAMMER),jlink) + # setup JLink for flashing + export JLINK_DEVICE := nrf51822 + include $(RIOTMAKE)/tools/jlink.inc.mk +endif diff --git a/boards/yunjia-nrf51822/board.c b/boards/common/nrf51/board.c similarity index 79% rename from boards/yunjia-nrf51822/board.c rename to boards/common/nrf51/board.c index 43c50241cb..e0be826613 100644 --- a/boards/yunjia-nrf51822/board.c +++ b/boards/common/nrf51/board.c @@ -7,11 +7,11 @@ */ /** - * @ingroup boards_yunjia-nrf51822 + * @ingroup boards_common_nrf51 * @{ * * @file - * @brief Board specific implementations for the Yunjia NRF51822 board + * @brief Board initialization for the nRF51 based boards * * @author Hauke Petersen * diff --git a/boards/airfy-beacon/dist/openocd.cfg b/boards/common/nrf51/dist/openocd.cfg similarity index 100% rename from boards/airfy-beacon/dist/openocd.cfg rename to boards/common/nrf51/dist/openocd.cfg diff --git a/boards/common/nrf51/include/board_common.h b/boards/common/nrf51/include/board_common.h new file mode 100644 index 0000000000..f7bb9d3dee --- /dev/null +++ b/boards/common/nrf51/include/board_common.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 Freie Universität Berlin + * 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. + */ + +/** + * @defgroup boards_common_nrf51 NRF51 common + * @ingroup boards_common + * @brief Shared files and configuration for some nRF51 boards. + * @{ + * + * @file + * @brief Shared configuration for some nRF51-based boards + * + * @author Hauke Petersen + * @author Alexandre Abadie + */ + +#ifndef BOARD_COMMON_H +#define BOARD_COMMON_H + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Xtimer configuration + * @{ + */ +#define XTIMER_WIDTH (24) +#define XTIMER_BACKOFF (40) +/** @} */ + +/** + * @brief Initialize the platform + */ +void board_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_COMMON_H */ +/** @} */ diff --git a/boards/common/nrf51/include/periph_conf_common.h b/boards/common/nrf51/include/periph_conf_common.h new file mode 100644 index 0000000000..e4c296d305 --- /dev/null +++ b/boards/common/nrf51/include/periph_conf_common.h @@ -0,0 +1,56 @@ +/* + * 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_common_nrf51 + * @{ + * + * @file + * @brief Common peripheral MCU configuration for some nrf51 based boards + * + * @author Alexandre Abadie + */ + +#ifndef PERIPH_CONF_COMMON_H +#define PERIPH_CONF_COMMON_H + +#include "periph_cpu.h" + +#ifdef __cplusplus + extern "C" { +#endif + +/** + * @name Timer configuration + * @{ + */ +static const timer_conf_t timer_config[] = { + /* dev, channels, width */ + { NRF_TIMER0, 3, TIMER_BITMODE_BITMODE_24Bit, TIMER0_IRQn } +}; + +#define TIMER_0_ISR isr_timer0 + +#define TIMER_NUMOF (sizeof(timer_config) / sizeof(timer_config[0])) +/** @} */ + +/** + * @name Real time counter configuration + * @{ + */ +#define RTT_NUMOF (1U) +#define RTT_DEV (1) /* NRF_RTC1 */ +#define RTT_MAX_VALUE (0x00ffffff) +#define RTT_FREQUENCY (1024) +/** @} */ + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* PERIPH_CONF_COMMON_H */ diff --git a/boards/yunjia-nrf51822/dist/openocd.cfg b/boards/yunjia-nrf51822/dist/openocd.cfg deleted file mode 100644 index d16a15a3ec..0000000000 --- a/boards/yunjia-nrf51822/dist/openocd.cfg +++ /dev/null @@ -1,3 +0,0 @@ -set WORKAREASIZE 0x4000 -source [find target/nrf51.cfg] -$_TARGETNAME configure -rtos auto From 0842eb56ceca29015759b36254148904a6ce9513 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 17:55:43 +0200 Subject: [PATCH 2/9] boards/airfy-beacon: factorize common code --- boards/airfy-beacon/Makefile | 1 + boards/airfy-beacon/Makefile.dep | 4 +--- boards/airfy-beacon/Makefile.features | 11 ++-------- boards/airfy-beacon/Makefile.include | 18 ++++++++-------- boards/airfy-beacon/include/board.h | 21 ++----------------- boards/airfy-beacon/include/periph_conf.h | 25 +---------------------- 6 files changed, 17 insertions(+), 63 deletions(-) diff --git a/boards/airfy-beacon/Makefile b/boards/airfy-beacon/Makefile index f8fcbb53a0..83d059dc34 100644 --- a/boards/airfy-beacon/Makefile +++ b/boards/airfy-beacon/Makefile @@ -1,3 +1,4 @@ MODULE = board +DIRS = $(RIOTBOARD)/common/nrf51 include $(RIOTBASE)/Makefile.base diff --git a/boards/airfy-beacon/Makefile.dep b/boards/airfy-beacon/Makefile.dep index 7de44689f6..babcd96228 100644 --- a/boards/airfy-beacon/Makefile.dep +++ b/boards/airfy-beacon/Makefile.dep @@ -1,3 +1 @@ -ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE))) - USEMODULE += nrfmin -endif +include $(RIOTBOARD)/common/nrf51/Makefile.dep diff --git a/boards/airfy-beacon/Makefile.features b/boards/airfy-beacon/Makefile.features index 32008a8330..e5a4957546 100644 --- a/boards/airfy-beacon/Makefile.features +++ b/boards/airfy-beacon/Makefile.features @@ -1,15 +1,8 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc -FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_i2c -FEATURES_PROVIDED += periph_rtt FEATURES_PROVIDED += periph_spi -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart -# Various other features (if any) - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = cortex_m0_2 - -include $(RIOTCPU)/nrf51/Makefile.features +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features diff --git a/boards/airfy-beacon/Makefile.include b/boards/airfy-beacon/Makefile.include index e4c6cac363..e73b42a69b 100644 --- a/boards/airfy-beacon/Makefile.include +++ b/boards/airfy-beacon/Makefile.include @@ -1,16 +1,18 @@ -# define the used CPU -export CPU = nrf51 +# define the used CPU model export CPU_MODEL = nrf51x22xxaa +# include common nrf51 boards module into the build +USEMODULE += boards_common_nrf51 + # define the default port depending on the host OS PORT_LINUX ?= /dev/ttyUSB0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk +# this board uses an ST-Link v2 debug adapter +DEBUG_ADAPTER ?= stlink +STLINK_VERSION ?= 2 -export DEBUG_ADAPTER ?= stlink -export STLINK_VERSION ?= 2 +PROGRAMMER = openocd -# this board uses openocd -include $(RIOTMAKE)/tools/openocd.inc.mk +# include nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/airfy-beacon/include/board.h b/boards/airfy-beacon/include/board.h index c83bd8d0ee..d5c83e217a 100644 --- a/boards/airfy-beacon/include/board.h +++ b/boards/airfy-beacon/include/board.h @@ -19,27 +19,10 @@ #ifndef BOARD_H #define BOARD_H -#include "cpu.h" +#include "board_common.h" #ifdef __cplusplus - extern "C" { -#endif - -/** - * @name Xtimer configuration - * @{ - */ -#define XTIMER_WIDTH (24) -#define XTIMER_BACKOFF (40) -/** @} */ - -/** - * @brief Initialize board specific hardware, including clock, LEDs and std-IO - */ -void board_init(void); - -#ifdef __cplusplus -} /* end extern "C" */ + extern "C" {} #endif #endif /* BOARD_H */ diff --git a/boards/airfy-beacon/include/periph_conf.h b/boards/airfy-beacon/include/periph_conf.h index 69d3f16bd6..916f3e5494 100644 --- a/boards/airfy-beacon/include/periph_conf.h +++ b/boards/airfy-beacon/include/periph_conf.h @@ -21,6 +21,7 @@ #define PERIPH_CONF_H #include "periph_cpu.h" +#include "periph_conf_common.h" #ifdef __cplusplus extern "C" { @@ -41,20 +42,6 @@ * 2: derived from HFCLK */ /** @} */ -/** - * @name Timer configuration - * @{ - */ -static const timer_conf_t timer_config[] = { - /* dev, channels, width */ - { NRF_TIMER0, 3, TIMER_BITMODE_BITMODE_24Bit, TIMER0_IRQn } -}; - -#define TIMER_0_ISR isr_timer0 - -#define TIMER_NUMOF (sizeof(timer_config) / sizeof(timer_config[0])) -/** @} */ - /** * @name UART configuration * @@ -66,16 +53,6 @@ static const timer_conf_t timer_config[] = { #define UART_PIN_TX 18 /** @} */ -/** - * @name Real time counter configuration - * @{ - */ -#define RTT_NUMOF (1U) -#define RTT_DEV (1) /* NRF_RTC1 */ -#define RTT_MAX_VALUE (0x00ffffff) -#define RTT_FREQUENCY (1024) -/** @} */ - /** * @name SPI configuration * @{ From a1d65583cbaae5ab5ddcdd5ffc9dad3962692286 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 17:56:13 +0200 Subject: [PATCH 3/9] boards/yunjia-nrf51822: factorize common code --- boards/yunjia-nrf51822/Makefile | 1 + boards/yunjia-nrf51822/Makefile.dep | 4 +--- boards/yunjia-nrf51822/Makefile.features | 11 ++------- boards/yunjia-nrf51822/Makefile.include | 17 +++++++------ boards/yunjia-nrf51822/include/board.h | 21 ++-------------- boards/yunjia-nrf51822/include/periph_conf.h | 25 +------------------- 6 files changed, 17 insertions(+), 62 deletions(-) diff --git a/boards/yunjia-nrf51822/Makefile b/boards/yunjia-nrf51822/Makefile index f8fcbb53a0..83d059dc34 100644 --- a/boards/yunjia-nrf51822/Makefile +++ b/boards/yunjia-nrf51822/Makefile @@ -1,3 +1,4 @@ MODULE = board +DIRS = $(RIOTBOARD)/common/nrf51 include $(RIOTBASE)/Makefile.base diff --git a/boards/yunjia-nrf51822/Makefile.dep b/boards/yunjia-nrf51822/Makefile.dep index 7de44689f6..babcd96228 100644 --- a/boards/yunjia-nrf51822/Makefile.dep +++ b/boards/yunjia-nrf51822/Makefile.dep @@ -1,3 +1 @@ -ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE))) - USEMODULE += nrfmin -endif +include $(RIOTBOARD)/common/nrf51/Makefile.dep diff --git a/boards/yunjia-nrf51822/Makefile.features b/boards/yunjia-nrf51822/Makefile.features index 32008a8330..e5a4957546 100644 --- a/boards/yunjia-nrf51822/Makefile.features +++ b/boards/yunjia-nrf51822/Makefile.features @@ -1,15 +1,8 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_adc -FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_i2c -FEATURES_PROVIDED += periph_rtt FEATURES_PROVIDED += periph_spi -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart -# Various other features (if any) - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = cortex_m0_2 - -include $(RIOTCPU)/nrf51/Makefile.features +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features diff --git a/boards/yunjia-nrf51822/Makefile.include b/boards/yunjia-nrf51822/Makefile.include index e4c6cac363..637067fab0 100644 --- a/boards/yunjia-nrf51822/Makefile.include +++ b/boards/yunjia-nrf51822/Makefile.include @@ -1,16 +1,19 @@ -# define the used CPU -export CPU = nrf51 +# define the used CPU model export CPU_MODEL = nrf51x22xxaa +# include common nrf51 boards module into the build +USEMODULE += boards_common_nrf51 + # define the default port depending on the host OS PORT_LINUX ?= /dev/ttyUSB0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk - +# This board uses an ST-Link v2 debug adapter export DEBUG_ADAPTER ?= stlink export STLINK_VERSION ?= 2 -# this board uses openocd -include $(RIOTMAKE)/tools/openocd.inc.mk +# use openocd to program this board +PROGRAMMER = openocd + +# import nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/yunjia-nrf51822/include/board.h b/boards/yunjia-nrf51822/include/board.h index 0e3d004b38..5d4a51e420 100644 --- a/boards/yunjia-nrf51822/include/board.h +++ b/boards/yunjia-nrf51822/include/board.h @@ -19,27 +19,10 @@ #ifndef BOARD_H #define BOARD_H -#include "cpu.h" +#include "board_common.h" #ifdef __cplusplus -extern "C" { -#endif - -/** - * @name Xtimer configuration - * @{ - */ -#define XTIMER_WIDTH (24) -#define XTIMER_BACKOFF (40) -/** @} */ - -/** - * @brief Initialize board specific hardware, including clock, LEDs and std-IO - */ -void board_init(void); - -#ifdef __cplusplus -} +extern "C" {} #endif #endif /* BOARD_H */ diff --git a/boards/yunjia-nrf51822/include/periph_conf.h b/boards/yunjia-nrf51822/include/periph_conf.h index a74e361f88..57538297d0 100644 --- a/boards/yunjia-nrf51822/include/periph_conf.h +++ b/boards/yunjia-nrf51822/include/periph_conf.h @@ -20,6 +20,7 @@ #define PERIPH_CONF_H #include "periph_cpu.h" +#include "periph_conf_common.h" #ifdef __cplusplus extern "C" { @@ -40,20 +41,6 @@ extern "C" { * 2: derived from HFCLK */ /** @} */ -/** - * @name Timer configuration - * @{ - */ -static const timer_conf_t timer_config[] = { - /* dev, channels, width */ - { NRF_TIMER0, 3, TIMER_BITMODE_BITMODE_24Bit, TIMER0_IRQn } -}; - -#define TIMER_0_ISR isr_timer0 - -#define TIMER_NUMOF (sizeof(timer_config) / sizeof(timer_config[0])) -/** @} */ - /** * @name UART configuration * @{ @@ -64,16 +51,6 @@ static const timer_conf_t timer_config[] = { #define UART_PIN_TX 2 /** @} */ -/** - * @name Real time counter configuration - * @{ - */ -#define RTT_NUMOF (1U) -#define RTT_DEV (1) /* NRF_RTC1 */ -#define RTT_MAX_VALUE (0x00ffffff) -#define RTT_FREQUENCY (1024) -/** @} */ - /** * @name SPI configuration * @{ From a4463be1e39f9c483fe0d18efe7b2a82712b24f3 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 17:56:24 +0200 Subject: [PATCH 4/9] boards/microbit: factorize common code --- boards/microbit/Makefile.dep | 4 +--- boards/microbit/Makefile.features | 11 ++--------- boards/microbit/Makefile.include | 15 +++++---------- boards/microbit/include/board.h | 16 +--------------- 4 files changed, 9 insertions(+), 37 deletions(-) diff --git a/boards/microbit/Makefile.dep b/boards/microbit/Makefile.dep index e54ceaf6ec..73cf142b58 100644 --- a/boards/microbit/Makefile.dep +++ b/boards/microbit/Makefile.dep @@ -7,6 +7,4 @@ ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += saul_gpio endif -ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE))) - USEMODULE += nrfmin -endif +include $(RIOTBOARD)/common/nrf51/Makefile.dep diff --git a/boards/microbit/Makefile.features b/boards/microbit/Makefile.features index 2c53068f05..e8d2c5b39d 100644 --- a/boards/microbit/Makefile.features +++ b/boards/microbit/Makefile.features @@ -1,13 +1,6 @@ # Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_i2c -FEATURES_PROVIDED += periph_rtt -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart -# Various other features (if any) - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = cortex_m0_1 - -include $(RIOTCPU)/nrf51/Makefile.features +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features diff --git a/boards/microbit/Makefile.include b/boards/microbit/Makefile.include index 6349546dbd..8fb097901b 100644 --- a/boards/microbit/Makefile.include +++ b/boards/microbit/Makefile.include @@ -1,15 +1,12 @@ # define the used CPU -export CPU = nrf51 export CPU_MODEL = nrf51x22xxab # define the default port depending on the host OS PORT_LINUX ?= /dev/ttyACM0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk - -# we support flashing through plain fscopy or using JLink +# this board supports flashing through plain fscopy, using JLink or using +# openocd. Default programmer is fscopy PROGRAMMER ?= fscopy ifeq (fscopy,$(PROGRAMMER)) export FFLAGS = @@ -18,9 +15,7 @@ ifeq (fscopy,$(PROGRAMMER)) export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh export DEBUGGER = export DEBUGSERVER = -else ifeq (jlink,$(PROGRAMMER)) - export JLINK_DEVICE := nrf51822 - include $(RIOTMAKE)/tools/jlink.inc.mk -else - $(info ERROR: invalid flash tool specified) endif + +# include nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/microbit/include/board.h b/boards/microbit/include/board.h index c2c0d8daa4..5a4d74755b 100644 --- a/boards/microbit/include/board.h +++ b/boards/microbit/include/board.h @@ -20,21 +20,12 @@ #ifndef BOARD_H #define BOARD_H -#include "cpu.h" -#include "periph_conf.h" +#include "board_common.h" #ifdef __cplusplus extern "C" { #endif -/** - * @name Xtimer configuration - * @{ - */ -#define XTIMER_WIDTH (24) -#define XTIMER_BACKOFF (40) -/** @} */ - /** * @name LED matrix pin configuration * @{ @@ -80,11 +71,6 @@ extern "C" { #define MAG3110_PARAM_ADDR 0x0e /** @} */ -/** - * @brief Initialize the board, also triggers the CPU initialization - */ -void board_init(void); - #ifdef __cplusplus } #endif From 5e8c92d69c16b686c794970aa5c431b5d02dde19 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 17:59:02 +0200 Subject: [PATCH 5/9] boards/nrf51dongle: factorize common code --- boards/nrf51dongle/Makefile.dep | 4 +--- boards/nrf51dongle/Makefile.features | 11 ++--------- boards/nrf51dongle/Makefile.include | 15 ++++++++------ boards/nrf51dongle/include/board.h | 16 +-------------- boards/nrf51dongle/include/periph_conf.h | 25 +----------------------- 5 files changed, 14 insertions(+), 57 deletions(-) diff --git a/boards/nrf51dongle/Makefile.dep b/boards/nrf51dongle/Makefile.dep index 7de44689f6..babcd96228 100644 --- a/boards/nrf51dongle/Makefile.dep +++ b/boards/nrf51dongle/Makefile.dep @@ -1,3 +1 @@ -ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE))) - USEMODULE += nrfmin -endif +include $(RIOTBOARD)/common/nrf51/Makefile.dep diff --git a/boards/nrf51dongle/Makefile.features b/boards/nrf51dongle/Makefile.features index 0b44820578..93dbc67187 100644 --- a/boards/nrf51dongle/Makefile.features +++ b/boards/nrf51dongle/Makefile.features @@ -1,12 +1,5 @@ # Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio periph_gpio_irq -FEATURES_PROVIDED += periph_rtt -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart -# Various other features (if any) - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = cortex_m0_1 - -include $(RIOTCPU)/nrf51/Makefile.features +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features diff --git a/boards/nrf51dongle/Makefile.include b/boards/nrf51dongle/Makefile.include index 089340c484..26796a8950 100644 --- a/boards/nrf51dongle/Makefile.include +++ b/boards/nrf51dongle/Makefile.include @@ -1,14 +1,17 @@ # define the used CPU -export CPU = nrf51 export CPU_MODEL = nrf51x22xxab # define the default port depending on the host OS PORT_LINUX ?= /dev/ttyACM0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) -# setup JLink for flashing -export JLINK_DEVICE := nrf51822 -include $(RIOTMAKE)/tools/jlink.inc.mk +# use jlink to program this board +PROGRAMMER ?= jlink -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk +# set required jlink debug adapter for openocd if it's used +ifeq (openocd,$(PROGRAMMER)) + DEBUG_ADAPTER = jlink +endif + +# include nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/nrf51dongle/include/board.h b/boards/nrf51dongle/include/board.h index 5298a776b5..b6392359f5 100644 --- a/boards/nrf51dongle/include/board.h +++ b/boards/nrf51dongle/include/board.h @@ -19,21 +19,12 @@ #ifndef BOARD_H #define BOARD_H -#include "cpu.h" -#include "periph_conf.h" +#include "board_common.h" #ifdef __cplusplus extern "C" { #endif -/** - * @name Xtimer configuration - * @{ - */ -#define XTIMER_WIDTH (24) -#define XTIMER_BACKOFF (40) -/** @} */ - /** * @name LED pin definitions and handlers * @{ @@ -59,11 +50,6 @@ extern "C" { #define LED2_TOGGLE (NRF_GPIO->OUT ^= LED2_MASK) /** @} */ -/** - * @brief Initialize the board, also triggers the CPU initialization - */ -void board_init(void); - #ifdef __cplusplus } #endif diff --git a/boards/nrf51dongle/include/periph_conf.h b/boards/nrf51dongle/include/periph_conf.h index 3fda308cff..9831276b60 100644 --- a/boards/nrf51dongle/include/periph_conf.h +++ b/boards/nrf51dongle/include/periph_conf.h @@ -20,6 +20,7 @@ #define PERIPH_CONF_H #include "periph_cpu.h" +#include "periph_conf_common.h" #ifdef __cplusplus extern "C" { @@ -40,30 +41,6 @@ extern "C" { * 2: derived from HFCLK */ /** @} */ -/** - * @name Timer configuration - * @{ - */ -static const timer_conf_t timer_config[] = { - /* dev, channels, width */ - { NRF_TIMER0, 3, TIMER_BITMODE_BITMODE_24Bit, TIMER0_IRQn } -}; - -#define TIMER_0_ISR isr_timer0 - -#define TIMER_NUMOF (sizeof(timer_config) / sizeof(timer_config[0])) -/** @} */ - -/** - * @name Real time counter configuration - * @{ - */ -#define RTT_NUMOF (1U) -#define RTT_DEV (1) /* NRF_RTC1 */ -#define RTT_MAX_VALUE (0x00ffffff) -#define RTT_FREQUENCY (1024) -/** @} */ - /** * @name UART configuration * @{ From 871d72ffb464c6c30601b9b352902c3670b68010 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 18:01:16 +0200 Subject: [PATCH 6/9] boards/nrf6310: factorize common code --- boards/nrf6310/Makefile.dep | 4 +--- boards/nrf6310/Makefile.features | 9 ++------- boards/nrf6310/Makefile.include | 20 ++++++++------------ boards/nrf6310/dist/debug.sh | 17 ----------------- boards/nrf6310/dist/flash.sh | 25 ------------------------- boards/nrf6310/dist/reset.sh | 18 ------------------ boards/nrf6310/include/periph_conf.h | 25 +------------------------ 7 files changed, 12 insertions(+), 106 deletions(-) delete mode 100755 boards/nrf6310/dist/debug.sh delete mode 100755 boards/nrf6310/dist/flash.sh delete mode 100755 boards/nrf6310/dist/reset.sh diff --git a/boards/nrf6310/Makefile.dep b/boards/nrf6310/Makefile.dep index 7de44689f6..babcd96228 100644 --- a/boards/nrf6310/Makefile.dep +++ b/boards/nrf6310/Makefile.dep @@ -1,3 +1 @@ -ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE))) - USEMODULE += nrfmin -endif +include $(RIOTBOARD)/common/nrf51/Makefile.dep diff --git a/boards/nrf6310/Makefile.features b/boards/nrf6310/Makefile.features index 6cec355f5f..d2712cafab 100644 --- a/boards/nrf6310/Makefile.features +++ b/boards/nrf6310/Makefile.features @@ -1,13 +1,8 @@ # Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio periph_gpio_irq -FEATURES_PROVIDED += periph_rtt FEATURES_PROVIDED += periph_spi -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart -# Various other features (if any) - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = cortex_m0_2 +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features include $(RIOTCPU)/nrf51/Makefile.features diff --git a/boards/nrf6310/Makefile.include b/boards/nrf6310/Makefile.include index 7cb45a324f..a70b6acf73 100644 --- a/boards/nrf6310/Makefile.include +++ b/boards/nrf6310/Makefile.include @@ -1,21 +1,17 @@ # define the used CPU -export CPU = nrf51 export CPU_MODEL = nrf51x22xxaa # set default port depending on operating system PORT_LINUX ?= /dev/ttyUSB0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) -# define flash and debugging environment -export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh -export DEBUGGER = $(RIOTBOARD)/$(BOARD)/dist/debug.sh -export DEBUGSERVER = JLinkGDBServer -device nrf51822 -if SWD -export RESET = $(RIOTBOARD)/$(BOARD)/dist/reset.sh +# use jlink to program this board +PROGRAMMER ?= jlink -HEXFILE = $(BINFILE) -export FFLAGS = $(BINDIR) $(HEXFILE) -export DEBUGGER_FLAGS = $(BINDIR) $(ELFFILE) -export RESET_FLAGS = $(BINDIR) +# set required debug adapter for openocd if it's used +ifeq (openocd,$(PROGRAMMER)) + DEBUG_ADAPTER = jlink +endif -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk +# include nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/nrf6310/dist/debug.sh b/boards/nrf6310/dist/debug.sh deleted file mode 100755 index 24bdbae0f6..0000000000 --- a/boards/nrf6310/dist/debug.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -# Start in-circuit debugging on this board: this script starts up the GDB -# client and connects to a GDB server. -# -# Start the GDB server first using the 'make debugserver' target - -# @author Hauke Petersen - -BINDIR=$1 -ELFFILE=$2 - -# write GDB config file -echo "target extended-remote 127.0.0.1:2331" > $BINDIR/gdb.cfg - -# run GDB -arm-none-eabi-gdb -tui -command=$BINDIR/gdb.cfg $ELFFILE diff --git a/boards/nrf6310/dist/flash.sh b/boards/nrf6310/dist/flash.sh deleted file mode 100755 index 0f4bbb33c7..0000000000 --- a/boards/nrf6310/dist/flash.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -# This flash script dynamically generates a file with a set of commands which -# have to be handed to the flashing script of SEGGER (JLinkExe >4.84). -# After that, JLinkExe will be executed with that set of commands to flash the -# latest .bin file to the board. - -# @author Timo Ziegler -# @author Hauke Petersen - -BINDIR=$1 -HEXFILE=$2 - -# setup JLink command file -echo "device nrf51822" > $BINDIR/burn.seg -echo "speed 1000" >> $BINDIR/burn.seg -echo "w4 4001e504 1" >> $BINDIR/burn.seg -echo "loadbin $HEXFILE 0" >> $BINDIR/burn.seg -echo "r" >> $BINDIR/burn.seg -echo "g" >> $BINDIR/burn.seg -echo "exit" >> $BINDIR/burn.seg -echo "" >> $BINDIR/burn.seg - -# flash new binary to the board -JLinkExe < $BINDIR/burn.seg diff --git a/boards/nrf6310/dist/reset.sh b/boards/nrf6310/dist/reset.sh deleted file mode 100755 index 509f127ea4..0000000000 --- a/boards/nrf6310/dist/reset.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# This script resets a nrf51822 target using JLink called -# with a pre-defined reset sequence. - -# @author Hauke Petersen - -BINDIR=$1 - -# create JLink command file for resetting the board -echo "device nrf51822" > $BINDIR/reset.seg -echo "r" >> $BINDIR/reset.seg -echo "g" >> $BINDIR/reset.seg -echo "exit" >> $BINDIR/reset.seg -echo " " >> $BINDIR/reset.seg - -# reset the board -JLinkExe < $BINDIR/reset.seg diff --git a/boards/nrf6310/include/periph_conf.h b/boards/nrf6310/include/periph_conf.h index d1afa91ae3..7f00dffbb4 100644 --- a/boards/nrf6310/include/periph_conf.h +++ b/boards/nrf6310/include/periph_conf.h @@ -23,6 +23,7 @@ #define PERIPH_CONF_H #include "periph_cpu.h" +#include "periph_conf_common.h" #ifdef __cplusplus extern "C" { @@ -43,30 +44,6 @@ extern "C" { * 2: derived from HFCLK */ /** @} */ -/** - * @name Timer configuration - * @{ - */ -static const timer_conf_t timer_config[] = { - /* dev, channels, width */ - { NRF_TIMER0, 3, TIMER_BITMODE_BITMODE_24Bit, TIMER0_IRQn } -}; - -#define TIMER_0_ISR isr_timer0 - -#define TIMER_NUMOF (sizeof(timer_config) / sizeof(timer_config[0])) -/** @} */ - -/** - * @name Real time counter configuration - * @{ - */ -#define RTT_NUMOF (1U) -#define RTT_DEV (1) /* NRF_RTC1 */ -#define RTT_MAX_VALUE (0x00ffffff) -#define RTT_FREQUENCY (1024) -/** @} */ - /** * @name UART configuration * @{ From c71c27cf5cc11ecf56fd406a7946c60ddf81a789 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 21:19:41 +0200 Subject: [PATCH 7/9] cpu/nrf51: add gpio to features provided --- cpu/nrf51/Makefile.features | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu/nrf51/Makefile.features b/cpu/nrf51/Makefile.features index 7d12728b90..1a47295f06 100644 --- a/cpu/nrf51/Makefile.features +++ b/cpu/nrf51/Makefile.features @@ -1 +1,3 @@ +FEATURES_PROVIDED += periph_gpio periph_gpio_irq + -include $(RIOTCPU)/nrf5x_common/Makefile.features From 59b3252888c9a860440599ddf0261e48e663b611 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 24 Oct 2018 21:36:49 +0200 Subject: [PATCH 8/9] boards/microbit: add possibility to flash with openocd --- boards/microbit/Makefile.include | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/boards/microbit/Makefile.include b/boards/microbit/Makefile.include index 8fb097901b..8eb617dd3b 100644 --- a/boards/microbit/Makefile.include +++ b/boards/microbit/Makefile.include @@ -8,6 +8,7 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) # this board supports flashing through plain fscopy, using JLink or using # openocd. Default programmer is fscopy PROGRAMMER ?= fscopy + ifeq (fscopy,$(PROGRAMMER)) export FFLAGS = export DEBUGGER_FLAGS = @@ -15,6 +16,9 @@ ifeq (fscopy,$(PROGRAMMER)) export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh export DEBUGGER = export DEBUGSERVER = +else ifeq (openocd,$(PROGRAMMER)) + # this board uses a daplink adapter by default + DEBUG_ADAPTER = dap endif # include nrf51 boards common configuration From b3b0cd921a1075b7933b4b2adcf9b47989e693b8 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 26 Oct 2018 10:13:40 +0200 Subject: [PATCH 9/9] boards/calliope-mini: factorize common code --- boards/calliope-mini/Makefile.features | 11 ++--------- boards/calliope-mini/Makefile.include | 18 ++++++++---------- boards/calliope-mini/include/board.h | 16 +--------------- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/boards/calliope-mini/Makefile.features b/boards/calliope-mini/Makefile.features index 937a642587..18eeae03c8 100644 --- a/boards/calliope-mini/Makefile.features +++ b/boards/calliope-mini/Makefile.features @@ -1,14 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_i2c -FEATURES_PROVIDED += periph_rtt -FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart FEATURES_PROVIDED += periph_pwm -# Various other features (if any) - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = cortex_m0_1 - -include $(RIOTCPU)/nrf51/Makefile.features +# include common nrf51 based boards features +include $(RIOTBOARD)/common/nrf51/Makefile.features diff --git a/boards/calliope-mini/Makefile.include b/boards/calliope-mini/Makefile.include index 7fe765e3a7..6f969e2c20 100644 --- a/boards/calliope-mini/Makefile.include +++ b/boards/calliope-mini/Makefile.include @@ -1,16 +1,14 @@ # define the used CPU -export CPU = nrf51 export CPU_MODEL = nrf51x22xxab # define the default port depending on the host OS PORT_LINUX ?= /dev/ttyACM0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk - -# we support flashing through plain fscopy or using JLink +# this board supports flashing through plain fscopy, using JLink or using +# openocd PROGRAMMER ?= fscopy + ifeq (fscopy,$(PROGRAMMER)) export FFLAGS = export DEBUGGER_FLAGS = @@ -18,9 +16,9 @@ ifeq (fscopy,$(PROGRAMMER)) export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh export DEBUGGER = export DEBUGSERVER = -else ifeq (jlink,$(PROGRAMMER)) - export JLINK_DEVICE := nrf51822 - include $(RIOTMAKE)/tools/jlink.inc.mk -else - $(info ERROR: invalid flash tool specified) +else ifeq (openocd,$(PROGRAMMER)) + DEBUG_ADAPTER = jlink endif + +# include nrf51 boards common configuration +include $(RIOTBOARD)/common/nrf51/Makefile.include diff --git a/boards/calliope-mini/include/board.h b/boards/calliope-mini/include/board.h index 553b3a4815..099284158d 100644 --- a/boards/calliope-mini/include/board.h +++ b/boards/calliope-mini/include/board.h @@ -22,21 +22,12 @@ #ifndef BOARD_H #define BOARD_H -#include "cpu.h" -#include "periph_conf.h" +#include "board_common.h" #ifdef __cplusplus extern "C" { #endif -/** - * @name Xtimer configuration - * @{ - */ -#define XTIMER_WIDTH (24) -#define XTIMER_BACKOFF (40) -/** @} */ - /** * @name LED matrix pin configuration * @{ @@ -65,11 +56,6 @@ extern "C" { #define BTN1_MODE GPIO_IN /** @} */ -/** - * @brief Initialize the board, also triggers the CPU initialization - */ -void board_init(void); - #ifdef __cplusplus } #endif