From 63c6917234c1a61b96fa6b76c7613167b9b9276b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Fri, 1 Nov 2019 16:08:28 +0100 Subject: [PATCH] boards: arm: add generic openocd-via-jlink support for nRF5x boards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This support is Zephyr RTOS aware, so you can debug threads as well. Add a CMake fragment which adds openocd support for nrf5 boards which can also be flashed via JLink. This ought to work for nRF51 and nRF52 based boards at time of writing with openocd 0.10.0 or later (zephyr SDK 0.10.3 also worked when I tried for nrf52840_pca10056). Use it from the nRF DKs from Nordic which have interface MCUs with Segger compatible firmware. I'm also including Thingy:52, even though it doesn't, to make it easier when connecting to it via a standalone JLink dongle. The board has a nice connector for that. I'm leaving non-Nordic boards alone for now because I don't know them. It's just one line of CMake to add it for other boards, which should be easy for their maintainers to do. Suggested-by: Radosław Koppel Signed-off-by: Martí Bolívar --- boards/arm/nrf51_pca10028/board.cmake | 1 + boards/arm/nrf52810_pca10040/board.cmake | 1 + boards/arm/nrf52811_pca10056/board.cmake | 1 + boards/arm/nrf52840_pca10056/board.cmake | 1 + boards/arm/nrf52840_pca10090/board.cmake | 1 + boards/arm/nrf52_pca10040/board.cmake | 1 + boards/arm/nrf52_pca20020/board.cmake | 1 + boards/common/openocd-nrf5.board.cmake | 33 ++++++++++++++++++++++++ 8 files changed, 40 insertions(+) create mode 100644 boards/common/openocd-nrf5.board.cmake diff --git a/boards/arm/nrf51_pca10028/board.cmake b/boards/arm/nrf51_pca10028/board.cmake index a29fa16976c..62012e8d503 100644 --- a/boards/arm/nrf51_pca10028/board.cmake +++ b/boards/arm/nrf51_pca10028/board.cmake @@ -4,3 +4,4 @@ board_runner_args(nrfjprog "--nrf-family=NRF51") board_runner_args(jlink "--device=nrf51" "--speed=4000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/nrf52810_pca10040/board.cmake b/boards/arm/nrf52810_pca10040/board.cmake index ddd57ab8839..ca0a3abd7dc 100644 --- a/boards/arm/nrf52810_pca10040/board.cmake +++ b/boards/arm/nrf52810_pca10040/board.cmake @@ -4,3 +4,4 @@ board_runner_args(nrfjprog "--nrf-family=NRF52") board_runner_args(jlink "--device=nrf52" "--speed=4000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/nrf52811_pca10056/board.cmake b/boards/arm/nrf52811_pca10056/board.cmake index 7ede32d1f4a..7f7930e70de 100644 --- a/boards/arm/nrf52811_pca10056/board.cmake +++ b/boards/arm/nrf52811_pca10056/board.cmake @@ -6,3 +6,4 @@ board_runner_args(nrfjprog "--nrf-family=NRF52") board_runner_args(jlink "--device=nrf52" "--speed=4000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/nrf52840_pca10056/board.cmake b/boards/arm/nrf52840_pca10056/board.cmake index f9e8b267728..5990fda82ae 100644 --- a/boards/arm/nrf52840_pca10056/board.cmake +++ b/boards/arm/nrf52840_pca10056/board.cmake @@ -6,3 +6,4 @@ board_runner_args(pyocd "--target=nrf52840" "--frequency=4000000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/nrf52840_pca10090/board.cmake b/boards/arm/nrf52840_pca10090/board.cmake index ddd57ab8839..ca0a3abd7dc 100644 --- a/boards/arm/nrf52840_pca10090/board.cmake +++ b/boards/arm/nrf52840_pca10090/board.cmake @@ -4,3 +4,4 @@ board_runner_args(nrfjprog "--nrf-family=NRF52") board_runner_args(jlink "--device=nrf52" "--speed=4000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/nrf52_pca10040/board.cmake b/boards/arm/nrf52_pca10040/board.cmake index c7ab9b4254f..6963c542217 100644 --- a/boards/arm/nrf52_pca10040/board.cmake +++ b/boards/arm/nrf52_pca10040/board.cmake @@ -6,3 +6,4 @@ board_runner_args(pyocd "--target=nrf52" "--frequency=4000000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/nrf52_pca20020/board.cmake b/boards/arm/nrf52_pca20020/board.cmake index ceef68ad051..dd51220a30e 100644 --- a/boards/arm/nrf52_pca20020/board.cmake +++ b/boards/arm/nrf52_pca20020/board.cmake @@ -4,3 +4,4 @@ board_runner_args(nrfjprog "--nrf-family=NRF52" "--softreset") board_runner_args(jlink "--device=nrf52" "--speed=4000") include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/common/openocd-nrf5.board.cmake b/boards/common/openocd-nrf5.board.cmake new file mode 100644 index 00000000000..a378b00398b --- /dev/null +++ b/boards/common/openocd-nrf5.board.cmake @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Infer nrf51 vs nrf52 etc from the BOARD name. This enforces a board +# naming convention: "nrf5x" must appear somewhere in the board name +# for this to work. +# +# Boards which don't meet this convention can set this variable before +# including this script. +if (NOT DEFINED OPENOCD_NRF5_SUBFAMILY) + string(REGEX MATCH nrf5. OPENOCD_NRF5_SUBFAMILY "${BOARD}") +endif() +if("${OPENOCD_NRF5_SUBFAMILY}" STREQUAL "") + message(FATAL_ERROR + "Can't match nrf5 subfamily from BOARD name. " + "To fix, set CMake variable OPENOCD_NRF5_SUBFAMILY.") +endif() + +# We can do the right thing for supported subfamilies using a generic +# script, at least for openocd 0.10.0 and the openocd shipped with +# Zephyr SDK 0.10.3. +set(pre_init_cmds + "set WORKAREASIZE 0x4000" # 16 kB RAM used for flashing + "source [find interface/jlink.cfg]" + "transport select swd" + "source [find target/${OPENOCD_NRF5_SUBFAMILY}.cfg]" + "$_TARGETNAME configure -rtos auto" +) + +foreach(cmd ${pre_init_cmds}) + board_runner_args(openocd --cmd-pre-init "-c ${cmd}") +endforeach() + +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)