Skip to content

Commit

Permalink
Add OPENOCD_ADAPTER_SERIAL
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Oct 16, 2022
1 parent 081cde4 commit 4412cc4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
31 changes: 29 additions & 2 deletions tools/cmake/upload_methods/UploadMethodOPENOCD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,47 @@
### OpenOCD Upload Method
# This method needs the following parameters:
# OPENOCD_CHIP_CONFIG_COMMANDS - Specifies all OpenOCD commands needed to configure openocd for your target processor.
# This method creates the following options:
# OPENOCD_ADAPTER_SERIAL - Serial number of the debug adapter to select for OpenOCD. Set to empty to detect any matching adapter.

set(UPLOAD_SUPPORTS_DEBUG TRUE)

### Check if upload method can be enabled on this machine
find_package(OpenOCD)
set(UPLOAD_OPENOCD_FOUND ${OpenOCD_FOUND})

### Setup options
set(OPENOCD_ADAPTER_SERIAL "" CACHE STRING "Serial number of the debug adapter to select for OpenOCD. Set to empty to detect any matching adapter.")

### Function to generate upload target
set(OPENOCD_ADAPTER_SERIAL_COMMAND "")
if(NOT "${OPENOCD_ADAPTER_SERIAL}" STREQUAL "")

# Generate script file that tells OpenOCD how to find the correct debug adapter.
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/openocd_adapter_config.cfg CONTENT
"# Script to select the correct debug adapter with OpenOCD.
# This file is generated by UploadMethodOPENOCD.cmake. Your edits will be overwritten.
# As of OpenOCD 0.11, it appears that the 'hla' adapter driver (used for stlinks and some others)
# does not support the standard 'adapter serial' command, and instead requires its own 'hla_serial' command.
if { [adapter name] == \"hla\" } {
hla_serial \"${OPENOCD_ADAPTER_SERIAL}\"
} else {
adapter serial \"${OPENOCD_ADAPTER_SERIAL}\"
}")

set(OPENOCD_ADAPTER_SERIAL_COMMAND -f ${CMAKE_BINARY_DIR}/openocd_adapter_config.cfg)
endif()

function(gen_upload_target TARGET_NAME BIN_FILE)

# unlike other upload methods, OpenOCD uses the elf file
add_custom_target(flash-${TARGET_NAME}
COMMENT "Flashing ${TARGET_NAME} with OpenOCD..."
COMMAND ${OpenOCD}
${OPENOCD_CHIP_CONFIG_COMMANDS}
-c "program $<TARGET_FILE:${TARGET_NAME}> reset exit")
${OPENOCD_ADAPTER_SERIAL_COMMAND}
-c "program $<TARGET_FILE:${TARGET_NAME}> reset exit"
VERBATIM)

add_dependencies(flash-${TARGET_NAME} ${TARGET_NAME})
endfunction(gen_upload_target)
Expand All @@ -30,5 +55,7 @@ add_custom_target(gdbserver
COMMAND
${OpenOCD}
${OPENOCD_CHIP_CONFIG_COMMANDS}
${OPENOCD_ADAPTER_SERIAL_COMMAND}
-c "gdb_port ${GDB_PORT}"
USES_TERMINAL)
USES_TERMINAL
VERBATIM)
11 changes: 6 additions & 5 deletions tools/cmake/upload_methods/UploadMethodPYOCD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# PYOCD_TARGET_NAME - Name of your processor as passed to the -t option of pyOCD. This is usually the full or partial model number.
# PYOCD_CLOCK_SPEED - Clock speed of the JTAG or SWD connection. Default is in Hz, but can use k and M suffixes for MHz and GHz
# This method creates the following options:
# PYOCD_PROBE_UID - Probe UID to pass to pyOCD commands. You can get the UIDs from `python -m pyocd list`.
# PYOCD_PROBE_UID - Probe UID to pass to pyOCD commands. You can get the UIDs from `python -m pyocd list`. Set to empty to detect any probe.

set(UPLOAD_SUPPORTS_DEBUG TRUE)

Expand All @@ -15,12 +15,13 @@ include(CheckPythonPackage)
check_python_package(pyocd HAVE_PYOCD)
set(UPLOAD_PYOCD_FOUND ${HAVE_PYOCD})

### Setup options
set(PYOCD_PROBE_UID "" CACHE STRING "Probe UID to pass to pyOCD commands. You can get the UIDs from `python -m pyocd list`. Set to empty to detect any probe.")

### Function to generate upload target
set(PYOCD_PROBE_ARGS "")
if(DEFINED PYOCD_PROBE_UID)
if(NOT "${PYOCD_PROBE_UID}" STREQUAL "")
set(PYOCD_PROBE_ARGS --probe ${PYOCD_PROBE_UID})
endif()
if(NOT "${PYOCD_PROBE_UID}" STREQUAL "")
set(PYOCD_PROBE_ARGS --probe ${PYOCD_PROBE_UID})
endif()

function(gen_upload_target TARGET_NAME BIN_FILE)
Expand Down

0 comments on commit 4412cc4

Please sign in to comment.