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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4e013e8d9 hw/scripts: Add shortcut for accessing STLink via USB S/N
4e013e8d9 is described below

commit 4e013e8d96a5a8dab15e9d5c5e626f5ec84833bc
Author: Slawomir Kasenberg <[email protected]>
AuthorDate: Mon Jul 14 13:20:37 2025 +0200

    hw/scripts: Add shortcut for accessing STLink via USB S/N
    
    STLINK_SN=<serial> env allows to specify STLink USB S/N. This is
    convenient shortcut for '--extrajtagcmd "--serial <serial>"' for
    st-flash or '--extrajtagcmd "sn=<serial>"' for STM32_Programmer_CLI.
---
 hw/scripts/stlink.sh           | 16 ++++++++++++++--
 hw/scripts/stm32_programmer.sh | 10 +++++++++-
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/scripts/stlink.sh b/hw/scripts/stlink.sh
index d4bf9589b..675f105c5 100755
--- a/hw/scripts/stlink.sh
+++ b/hw/scripts/stlink.sh
@@ -21,7 +21,19 @@
 # FILE_NAME must contain the name of the file to load
 # FLASH_OFFSET must contain the offset in flash where to place it
 #
+stlink_sn () {
+    if [ -n "$STLINK_SN" ]; then
+        if [ "$STLINK_USE_STM32_PROGRAMMER_CLI" == 1 ] ; then
+            EXTRA_JTAG_CMD="sn=$STLINK_SN " $EXTRA_JTAG_CMD
+        else
+            EXTRA_JTAG_CMD="--serial $STLINK_SN " $EXTRA_JTAG_CMD
+        fi
+    fi
+}
+
 stlink_load () {
+    stlink_sn
+
     if [ -z $FILE_NAME ]; then
         echo "Missing filename"
         exit 1
@@ -40,9 +52,9 @@ stlink_load () {
     echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
 
     if [ "$STLINK_USE_STM32_PROGRAMMER_CLI" == 1 ] ; then
-      STM32_Programmer_CLI -c port=SWD -d $FILE_NAME $FLASH_OFFSET -rst
+        STM32_Programmer_CLI -c port=SWD $EXTRA_JTAG_CMD -d $FILE_NAME 
$FLASH_OFFSET -rst
     else
-      st-flash --reset write $FILE_NAME $FLASH_OFFSET
+        st-flash $EXTRA_JTAG_CMD --reset write $FILE_NAME $FLASH_OFFSET
     fi
     if [ $? -ne 0 ]; then
         exit 1
diff --git a/hw/scripts/stm32_programmer.sh b/hw/scripts/stm32_programmer.sh
index 18c067308..fa0ddb333 100755
--- a/hw/scripts/stm32_programmer.sh
+++ b/hw/scripts/stm32_programmer.sh
@@ -21,7 +21,15 @@
 # FILE_NAME must contain the name of the file to load
 # FLASH_OFFSET must contain the offset in flash where to place it
 #
+stlink_sn () {
+    if [ -n "$STLINK_SN" ]; then
+        EXTRA_JTAG_CMD="sn=$STLINK_SN " $EXTRA_JTAG_CMD
+    fi
+}
+
 stlink_load () {
+    stlink_sn
+
     if [ -z $FILE_NAME ]; then
         echo "Missing filename"
         exit 1
@@ -39,7 +47,7 @@ stlink_load () {
 
     echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
 
-    STM32_Programmer_CLI -c port=SWD -d $FILE_NAME $FLASH_OFFSET -rst
+    STM32_Programmer_CLI -c port=SWD $EXTRA_JTAG_CMD -d $FILE_NAME 
$FLASH_OFFSET -rst
 
     if [ $? -ne 0 ]; then
         exit 1

Reply via email to