1# SPDX-License-Identifier: Apache-2.0
2
3# Infer nrf51 vs nrf52 etc from the BOARD name. This enforces a board
4# naming convention: "nrf5x" must appear somewhere in the board name
5# for this to work.
6#
7# Boards which don't meet this convention can set this variable before
8# including this script.
9if (NOT DEFINED OPENOCD_NRF5_SUBFAMILY)
10  string(REGEX MATCH nrf5. OPENOCD_NRF5_SUBFAMILY "${BOARD}")
11endif()
12if("${OPENOCD_NRF5_SUBFAMILY}" STREQUAL "")
13  message(FATAL_ERROR
14    "Can't match nrf5 subfamily from BOARD name. "
15    "To fix, set CMake variable OPENOCD_NRF5_SUBFAMILY.")
16endif()
17
18if (NOT DEFINED OPENOCD_NRF5_INTERFACE)
19  set(OPENOCD_NRF5_INTERFACE "jlink")
20endif()
21
22# We can do the right thing for supported subfamilies using a generic
23# script, at least for openocd 0.10.0 and the openocd shipped with
24# Zephyr SDK 0.10.3.
25set(pre_init_cmds
26  "set WORKAREASIZE 0x4000"	# 16 kB RAM used for flashing
27  "source [find interface/${OPENOCD_NRF5_INTERFACE}.cfg]"
28  "transport select swd"
29  "source [find target/${OPENOCD_NRF5_SUBFAMILY}.cfg]"
30)
31
32foreach(cmd ${pre_init_cmds})
33  board_runner_args(openocd --cmd-pre-init "${cmd}")
34endforeach()
35
36include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
37