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}")
11
12  if(HWMv2 AND "${OPENOCD_NRF5_SUBFAMILY}" STREQUAL "")
13    string(REGEX MATCH nrf5. OPENOCD_NRF5_SUBFAMILY "${BOARD_QUALIFIERS}")
14  endif()
15endif()
16
17if("${OPENOCD_NRF5_SUBFAMILY}" STREQUAL "")
18  message(FATAL_ERROR
19    "Can't match nrf5 subfamily from BOARD name. "
20    "To fix, set CMake variable OPENOCD_NRF5_SUBFAMILY.")
21endif()
22
23if (NOT DEFINED OPENOCD_NRF5_INTERFACE)
24  set(OPENOCD_NRF5_INTERFACE "jlink")
25endif()
26
27# We can do the right thing for supported subfamilies using a generic
28# script, at least for openocd 0.10.0 and the openocd shipped with
29# Zephyr SDK 0.10.3.
30set(pre_init_cmds
31  "set WORKAREASIZE 0x4000"	# 16 kB RAM used for flashing
32  "source [find interface/${OPENOCD_NRF5_INTERFACE}.cfg]"
33  "transport select swd"
34  "source [find target/${OPENOCD_NRF5_SUBFAMILY}.cfg]"
35)
36
37foreach(cmd ${pre_init_cmds})
38  board_runner_args(openocd --cmd-pre-init "${cmd}")
39endforeach()
40
41include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
42