Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: Add support for 'make debug' using Segger JLink on NXP boards #31

Merged
merged 1 commit into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion boards/arm/frdm_k64f/Makefile.board
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ DEBUG_SCRIPT = openocd.sh
OPENOCD_LOAD_CMD = "flash write_image erase ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"
OPENOCD_VERIFY_CMD = "verify_image ${O}/${KERNEL_BIN_NAME} ${CONFIG_FLASH_BASE_ADDRESS}"

export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD
JLINK_DEVICE = MK64FN1M0xxx12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to make this jlink only? OpenOCD does not seem to work with current SDK and only works with latest openocd. If it works with Jlink we might want to switch to that and document it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a reason to remove the OpenOCD support. I presume we'll update the OpenOCD version in a future SDK? I've also been looking at pyOCD as another option, since that is being actively maintained for NXP devices and is open source.

About documentation, this is something I plan to work on next after these scripts are cleaned up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add support for different flashing methods via 'make flash', right now only one is supported...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Segger flash tool is Windows only. I've had some success getting 'make flash' to work with pyOCD on k64 and kl25z, but I'm looking into when pyOCD can support kw41 before submitting a PR for it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a PR for pyOCD for kw41 support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


export FLASH_SCRIPT OPENOCD_LOAD_CMD OPENOCD_VERIFY_CMD JLINK_DEVICE
5 changes: 5 additions & 0 deletions boards/arm/frdm_kl25z/Makefile.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEBUG_SCRIPT = jlink.sh

JLINK_DEVICE = MKL25Z128xxx4

export JLINK_DEVICE
5 changes: 5 additions & 0 deletions boards/arm/frdm_kw41z/Makefile.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEBUG_SCRIPT = jlink.sh

JLINK_DEVICE = MKW41Z512xxx4

export JLINK_DEVICE
5 changes: 5 additions & 0 deletions boards/arm/hexiwear_k64/Makefile.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEBUG_SCRIPT = jlink.sh

JLINK_DEVICE = MK64FN1M0xxx12

export JLINK_DEVICE
5 changes: 5 additions & 0 deletions boards/arm/hexiwear_kw40z/Makefile.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEBUG_SCRIPT = jlink.sh

JLINK_DEVICE = MKW40Z160xxx4

export JLINK_DEVICE
67 changes: 67 additions & 0 deletions scripts/support/jlink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

# This script is loosly based on a script with same purpose provided
# by RIOT-OS (https://github.com/RIOT-OS/RIOT)

JLINK_GDBSERVER=${JLINK_GDBSERVER:-JLinkGDBServer}
JLINK_IF=${JLINK_IF:-swd}
BIN_NAME=${O}/${KERNEL_BIN_NAME}
ELF_NAME=${O}/${KERNEL_ELF_NAME}
GDB_PORT=${GDB_PORT:-2331}

test_config() {
if ! which ${JLINK_GDBSERVER} >/dev/null 2>&1; then
echo "Error: Unable to locate JLink GDB server: ${JLINK_GDBSERVER}"
exit 1
fi
}

test_bin() {
if [ ! -f "${BIN_NAME}" ]; then
echo "Error: Unable to locate image binary: ${BIN_NAME}"
exit 1
fi
}

do_debug() {
do_debugserver 1 &

# connect to the GDB server
${GDB} ${TUI} ${ELF_NAME} \
-ex "target remote :${GDB_PORT}" \
-ex 'monitor halt' \
-ex 'load' \
-ex 'monitor reset'
}

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 "JLink GDB server running on port ${GDB_PORT}"
${SETSID} ${JLINK_GDBSERVER} \
-port ${GDB_PORT} \
-if ${JLINK_IF} \
-device ${JLINK_DEVICE} \
-singlerun
}

CMD="$1"
shift

case "${CMD}" in
debugserver)
do_debugserver "$@"
;;
debug)
do_debug "$@"
;;
esac