This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit bf8c9d47d5c2b503c214b503ed92df2b4b1c29be
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri Mar 29 10:45:37 2024 +0100

    scripts/stm32_programmer: Add debug functionality
    
    stm32_programmer.sh so far supported only download functionality
    
    With new STM32 devices it is the only possibly to use
    ST-LINK_gdbserver or Jlink other tools may not support
    latest chips
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 hw/scripts/stm32_programmer.sh | 57 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/hw/scripts/stm32_programmer.sh b/hw/scripts/stm32_programmer.sh
index 1e846cdf5..18c067308 100644
--- a/hw/scripts/stm32_programmer.sh
+++ b/hw/scripts/stm32_programmer.sh
@@ -46,3 +46,60 @@ stlink_load () {
     fi
     return 0
 }
+
+#
+# NO_GDB should be set if gdb should not be started
+# FILE_NAME should point to elf-file being debugged
+#
+stlink_debug () {
+    windows_detect
+    gdb_detect
+    set -x
+
+    PORT=3333
+
+    parse_extra_jtag_cmd $EXTRA_JTAG_CMD
+
+    if [ -z "$NO_GDB" ]; then
+        if [ -z $FILE_NAME ]; then
+            echo "Missing filename"
+            exit 1
+        fi
+        if [ ! -f "$FILE_NAME" ]; then
+            echo "Cannot find file" $FILE_NAME
+            exit 1
+        fi
+
+        #
+        # Block Ctrl-C from getting passed to gdb server.
+        #
+        set -m
+        ST-LINK_gdbserver -d -p $PORT -cp ${CUBEPROGRAMMER_PATH} -g 
>stlink.log 2>&1 &
+        stpid=$!
+        set +m
+
+        GDB_CMD_FILE=.gdb_cmds
+
+        echo "target remote localhost:$PORT" > $GDB_CMD_FILE
+        if [ ! -z "$RESET" ]; then
+            echo "mon reset halt" >> $GDB_CMD_FILE
+        fi
+
+        echo "$EXTRA_GDB_CMDS" >> $GDB_CMD_FILE
+
+        set -m
+        $GDB -x $GDB_CMD_FILE $FILE_NAME
+        set +m
+        rm $GDB_CMD_FILE
+        sleep 1
+        if [ -d /proc/$stpid ] ; then
+            kill -9 $stpid
+        fi
+    else
+        # No GDB, wait for ST-LINK_gdbserver to exit
+        ST-LINK_gdbserver -d -p $PORT -cp ${CUBEPROGRAMMER_PATH} -g
+        return $?
+    fi
+
+    return 0
+}

Reply via email to