Skip to content

Commit 428b56e

Browse files
author
Jamie Smith
authored
Allow upload method configs to specify an OpenOCD version range (#340)
1 parent fa86c2b commit 428b56e

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

targets/upload_method_cfg/LPC1768.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ set(OPENOCD_UPLOAD_ENABLED TRUE)
3737
set(OPENOCD_CHIP_CONFIG_COMMANDS
3838
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/lpc1768.cfg)
3939

40+
# For some reason, as of summer 2024, git version of OpenOCD does not work with LPC1768. So, it seems like
41+
# the last compatible version will be the current release 0.12.
42+
set(OPENOCD_VERSION_RANGE 0.10...<0.13)
43+
4044
# Config options for LINKSERVER
4145
# -------------------------------------------------------------
4246
set(LINKSERVER_UPLOAD_ENABLED TRUE)

tools/cmake/upload_methods/FindOpenOCD.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ find_path(OpenOCD_SCRIPT_DIR
4343
PATHS /usr/share/openocd/scripts/
4444
DOC "Path to OpenOCD scripts folder. Should contain interface/cmsis-dap.cfg.")
4545

46-
find_package_handle_standard_args(OpenOCD FOUND_VAR OpenOCD_FOUND REQUIRED_VARS OpenOCD OpenOCD_SCRIPT_DIR)
46+
if(OpenOCD AND EXISTS "${OpenOCD}")
47+
# Detect version (it writes to stderr)
48+
execute_process(COMMAND ${OpenOCD} --version
49+
ERROR_VARIABLE OpenOCD_VERSION_OUTPUT)
50+
51+
# Use a regex to grab the version number
52+
string(REGEX MATCH "Open On-Chip Debugger ([^ ]+)" OpenOCD_VERSION_UNUSED_MATCH "${OpenOCD_VERSION_OUTPUT}")
53+
set(OpenOCD_VERSION ${CMAKE_MATCH_1})
54+
endif()
55+
56+
find_package_handle_standard_args(OpenOCD
57+
HANDLE_VERSION_RANGE
58+
FOUND_VAR OpenOCD_FOUND
59+
VERSION_VAR OpenOCD_VERSION
60+
REQUIRED_VARS OpenOCD OpenOCD_SCRIPT_DIR)
4761

4862

tools/cmake/upload_methods/UploadMethodOPENOCD.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
# OPENOCD_CHIP_CONFIG_COMMANDS - Specifies all OpenOCD commands needed to configure openocd for your target processor.
77
# This method creates the following options:
88
# OPENOCD_ADAPTER_SERIAL - Serial number of the debug adapter to select for OpenOCD. Set to empty to detect any matching adapter.
9+
# OPENOCD_VERSION_RANGE - Acceptable version range of OpenOCD. This may be a single version, in which case it is treated as
10+
# a minimum, or a versionMin...<versionMax constraint, e.g. 0.12...<0.13, to accept any 0.12.x version but not 0.13 or higher.
911

1012
set(UPLOAD_SUPPORTS_DEBUG TRUE)
1113

1214
### Check if upload method can be enabled on this machine
13-
find_package(OpenOCD)
15+
find_package(OpenOCD ${OPENOCD_VERSION_RANGE})
1416
set(UPLOAD_OPENOCD_FOUND ${OpenOCD_FOUND})
1517

1618
### Setup options

0 commit comments

Comments
 (0)