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 937e6d81a hw/scripts: Add adapter selection for pyocd
937e6d81a is described below

commit 937e6d81a6e1a2d213f928c46509acb6fcea7838
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Tue Jul 15 16:47:39 2025 +0200

    hw/scripts: Add adapter selection for pyocd
    
    Added support for selecting a specific debug probe using USB serial
    number via environment variables.
    
    This is useful when multiple boards are connected and pyocd cannot
    choose which one is target.
    
    Supported variables:
    - CMSIS_DAP_SN  for CMSIS-DAP
    - STLINK_SN for ST-Link
    - JLINK_SN  for J-Link
    
    Example:
    STLINK_SN=0666FF495157808667171335 newt load nucleo-f767zi-blinky
---
 hw/scripts/pyocd.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/hw/scripts/pyocd.sh b/hw/scripts/pyocd.sh
index 59a76dfe2..80550421e 100755
--- a/hw/scripts/pyocd.sh
+++ b/hw/scripts/pyocd.sh
@@ -26,6 +26,18 @@ CONNECTION_MODE_DEFAULT="halt"
 # TARGET must be correectly set by the BSP; check `pyocd list --targets`
 # CONNECTION_MODE can be one of "attach", "halt" (default), "pre-reset", 
"under-reset"
 #
+pyocd_sn() {
+    if [ -n "$JLINK_SN" ]; then
+        UID_ARG="-u $JLINK_SN"
+    elif [ -n "$STLINK_SN" ]; then
+        UID_ARG="-u $STLINK_SN"
+    elif [ -n "$CMSIS_DAP_SN" ]; then
+        UID_ARG="-u $CMSIS_DAP_SN"
+    else
+        UID_ARG=""
+    fi
+}
+
 pyocd_load () {
     if [ -z $TARGET ]; then
         echo "Missing TARGET (get a list with 'pyocd list --targets')"
@@ -51,9 +63,11 @@ pyocd_load () {
         exit 1
     fi
 
+    pyocd_sn
+
     echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
 
-    pyocd flash -e sector -M $CONNECTION_MODE -t $TARGET 
$FILE_NAME@$FLASH_OFFSET --format bin ${JLINK_SN:+-u $JLINK_SN}
+    pyocd flash -e sector -M $CONNECTION_MODE -t $TARGET 
$FILE_NAME@$FLASH_OFFSET --format bin $UID_ARG
     if [ $? -ne 0 ]; then
         exit 1
     fi

Reply via email to