diff --git a/boards/arm/frdm_k64f/Makefile.board b/boards/arm/frdm_k64f/Makefile.board index 6684d0a01e5..7178b100820 100644 --- a/boards/arm/frdm_k64f/Makefile.board +++ b/boards/arm/frdm_k64f/Makefile.board @@ -6,4 +6,6 @@ OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_A JLINK_DEVICE = MK64FN1M0xxx12 -export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD JLINK_DEVICE +PYOCD_TARGET = k64f + +export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD JLINK_DEVICE PYOCD_TARGET diff --git a/boards/arm/frdm_kl25z/Makefile.board b/boards/arm/frdm_kl25z/Makefile.board index 2823a94f957..efc6bf0c17c 100644 --- a/boards/arm/frdm_kl25z/Makefile.board +++ b/boards/arm/frdm_kl25z/Makefile.board @@ -2,4 +2,6 @@ DEBUG_SCRIPT = jlink.sh JLINK_DEVICE = MKL25Z128xxx4 -export JLINK_DEVICE +PYOCD_TARGET = kl25z + +export JLINK_DEVICE PYOCD_TARGET diff --git a/boards/arm/hexiwear_k64/Makefile.board b/boards/arm/hexiwear_k64/Makefile.board index ef762a998e9..973ede6ce33 100644 --- a/boards/arm/hexiwear_k64/Makefile.board +++ b/boards/arm/hexiwear_k64/Makefile.board @@ -2,4 +2,6 @@ DEBUG_SCRIPT = jlink.sh JLINK_DEVICE = MK64FN1M0xxx12 -export JLINK_DEVICE +PYOCD_TARGET = k64f + +export JLINK_DEVICE PYOCD_TARGET diff --git a/boards/arm/hexiwear_kw40z/Makefile.board b/boards/arm/hexiwear_kw40z/Makefile.board index ad405ee7d8f..04ccf15b7e7 100644 --- a/boards/arm/hexiwear_kw40z/Makefile.board +++ b/boards/arm/hexiwear_kw40z/Makefile.board @@ -2,4 +2,6 @@ DEBUG_SCRIPT = jlink.sh JLINK_DEVICE = MKW40Z160xxx4 -export JLINK_DEVICE +PYOCD_TARGET = kw40z4 + +export JLINK_DEVICE PYOCD_TARGET diff --git a/scripts/support/pyocd.sh b/scripts/support/pyocd.sh new file mode 100755 index 00000000000..11f4fdc1203 --- /dev/null +++ b/scripts/support/pyocd.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +# This script is loosly based on a script with same purpose provided +# by RIOT-OS (https://github.com/RIOT-OS/RIOT) + +PYOCD_FLASHTOOL=${PYOCD_FLASHTOOL:-pyocd-flashtool} +PYOCD_GDBSERVER=${PYOCD_GDBSERVER:-pyocd-gdbserver} +BIN_NAME=${O}/${KERNEL_BIN_NAME} +ELF_NAME=${O}/${KERNEL_ELF_NAME} +GDB_PORT=${GDB_PORT:-3333} + +test_config() { + if ! which ${PYOCD_FLASHTOOL} >/dev/null 2>&1; then + echo "Error: Unable to locate pyOCD flash tool: ${PYOCD_FLASHTOOL}" + exit 1 + fi + if ! which ${PYOCD_GDBSERVER} >/dev/null 2>&1; then + echo "Error: Unable to locate pyOCD GDB server: ${PYOCD_GDBSERVER}" + exit 1 + fi +} + +test_bin() { + if [ ! -f "${BIN_NAME}" ]; then + echo "Error: Unable to locate image binary: ${BIN_NAME}" + exit 1 + fi +} + +do_flash() { + test_config + test_bin + + # flash device with specified image + echo "Flashing Target Device" + ${PYOCD_FLASHTOOL} -t ${PYOCD_TARGET} ${BIN_NAME} +} + + +do_debug() { + do_debugserver 1 & + + # connect to the GDB server + ${GDB} ${TUI} ${ELF_NAME} \ + -ex "target remote :${GDB_PORT}" \ + -ex 'load' \ + -ex 'monitor reset halt' +} + +do_debugserver() { + test_config + + # Calling with an arg will result in setsid being used, which will prevent + # Ctrl-C in GDB from killing the server. The server automatically exits + # when the remote GDB disconnects. + if [ -n "$1" ]; then + SETSID=/usr/bin/setsid + else + SETSID= + fi + echo "pyOCD GDB server running on port ${GDB_PORT}" + ${SETSID} ${PYOCD_GDBSERVER} -p ${GDB_PORT} -t ${PYOCD_TARGET} +} + +CMD="$1" +shift + +case "${CMD}" in + flash) + do_flash "$@" + ;; + debugserver) + do_debugserver "$@" + ;; + debug) + do_debug "$@" + ;; +esac