From 900875c6036ec91c2ecd9f03bf3295fb297d64b6 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 2 Sep 2019 14:12:14 +0200 Subject: [PATCH 1/2] dist/tools/openocd: add OPENOCD_EXTRA_INIT_RESET - Add a variable to add extra openocd commands before resetting a board. These will not be called when `debug`, in contrast to OPENOCD_CONFIG, OPENOCD_EXTRA_INIT and OPENOCD_ADAPTER_INIT. - Add connect_assert_srst to reset config if OPENOCD_RESET_USE_CONNECT_ASSERT_SRST=1 --- dist/tools/openocd/openocd.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh index 41b5adacb1..1e41add8e5 100755 --- a/dist/tools/openocd/openocd.sh +++ b/dist/tools/openocd/openocd.sh @@ -73,6 +73,8 @@ : ${OPENOCD_EXTRA_INIT:=} # Debugger interface initialization commands to pass to OpenOCD : ${OPENOCD_ADAPTER_INIT:=} +# If set to 1 'reset_config' will use 'connect_assert_srst' before 'flash' or 'reset. +: ${OPENOCD_RESET_USE_CONNECT_ASSERT_SRST:=} # The setsid command is needed so that Ctrl+C in GDB doesn't kill OpenOCD : ${SETSID:=setsid} # GDB command, usually a separate command for each platform (e.g. arm-none-eabi-gdb) @@ -106,7 +108,6 @@ # # Examples of alternative debugger configurations # - # Using the GDB text UI: # DBG_EXTRA_FLAGS=-tui make debug # or to always use TUI, put in your .profile: @@ -119,6 +120,11 @@ # export DBG_FLAGS='--debugger "${GDB} ${DBG_DEFAULT_FLAGS}"' # The single quotes are important on the line above, or it will not work. +# Handle OPENOCD_RESET_USE_CONNECT_ASSERT_SRST +if [ "${OPENOCD_RESET_USE_CONNECT_ASSERT_SRST}" -eq 1 ]; then + OPENOCD_EXTRA_RESET_INIT+="-c 'reset_config connect_assert_srst'" +fi + # # a couple of tests for certain configuration options # @@ -205,6 +211,7 @@ _flash_list_raw() { sh -c "${OPENOCD} \ ${OPENOCD_ADAPTER_INIT} \ -f '${OPENOCD_CONFIG}' \ + ${OPENOCD_EXTRA_RESET_INIT} \ -c 'init' \ -c 'flash probe 0' \ -c 'flash list' \ @@ -274,6 +281,7 @@ do_flash() { ${OPENOCD_ADAPTER_INIT} \ -f '${OPENOCD_CONFIG}' \ ${OPENOCD_EXTRA_INIT} \ + ${OPENOCD_EXTRA_RESET_INIT} \ -c 'tcl_port 0' \ -c 'telnet_port 0' \ -c 'gdb_port 0' \ @@ -353,6 +361,7 @@ do_reset() { ${OPENOCD_ADAPTER_INIT} \ -f '${OPENOCD_CONFIG}' \ ${OPENOCD_EXTRA_INIT} \ + ${OPENOCD_EXTRA_RESET_INIT} \ -c 'tcl_port 0' \ -c 'telnet_port 0' \ -c 'gdb_port 0' \ From 06c830e8cda61e4f25f2dd2ff692be972726f087 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 2 Sep 2019 14:16:04 +0200 Subject: [PATCH 2/2] boards/nucleo-f091rc: set OPENOCD_RESET_USE_CONNECT_ASSERT_SRST - Nucleo-f091rc can become unflashable when hardfaults occure. To make sure flashing succeeds `connect_assert_srst` is called before connecting to flash threw openocd. --- boards/nucleo-f091rc/Makefile.include | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/boards/nucleo-f091rc/Makefile.include b/boards/nucleo-f091rc/Makefile.include index 8db8eaed90..d01fb044ac 100644 --- a/boards/nucleo-f091rc/Makefile.include +++ b/boards/nucleo-f091rc/Makefile.include @@ -1,2 +1,6 @@ +# nucleo-f091rc can become un-flashable after a hardfault, use connect_assert_srst +# to always be able to flash or reset the board. +export OPENOCD_RESET_USE_CONNECT_ASSERT_SRST ?= 1 + # load the common Makefile.include for Nucleo boards include $(RIOTBOARD)/common/nucleo64/Makefile.include