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

kasjer 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 525e674b1 hw/scripts: Add JTAG interface option to PIC32 download 
script
525e674b1 is described below

commit 525e674b1c6fe1c8819a99be36553a0efac8a305
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Oct 20 20:58:12 2026 +0200

    hw/scripts: Add JTAG interface option to PIC32 download script
    
    J-Link can program PIC32 over ICSP or JTAG. PIC32_JLINK_IF environment
    variable now selects the interface (ICSP by default). JTAG requires
    JTAGEN configuration bit set in the target.
    
    With JTAG interface J-Link Commander asks for device position in JTAG
    chain unless -JTAGConf is given. In command file mode the question
    consumes following commands, nothing is programmed and no error is
    reported. Pass -JTAGConf -1,-1 (auto-detect) for JTAG, treat
    JTAGConf prompt as an error and check that loadfile reported O.K.
    
    Over JTAG at 12 MHz J-Link programs and verifies PIC32MZ flash at
    about 160 KB/s compared to about 60 KB/s over ICSP.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 hw/scripts/pic32_download.sh | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/hw/scripts/pic32_download.sh b/hw/scripts/pic32_download.sh
index 7a2da1ca0..691919f91 100755
--- a/hw/scripts/pic32_download.sh
+++ b/hw/scripts/pic32_download.sh
@@ -38,6 +38,11 @@
 #  - MCU_NO_BOOTLOADER_BUILD set when application is built to run without
 #    bootloader
 #
+# Environment variables used with J-Link:
+#  - PIC32_JLINK_IF interface to use: ICSP (default) or JTAG, JTAG requires
+#    JTAGEN configuration bit set (MCU_JTAG_ENABLE: 1)
+#  - PIC32_JLINK_SPEED interface speed in kHz (default 12000)
+#
 
 . $CORE_PATH/hw/scripts/jlink.sh
 
@@ -45,14 +50,30 @@ PIC32_DEVICE=${MYNEWT_VAL_JLINK_TARGET}
 IMAGE_FLASH_ADDR=${FLASH_OFFSET}
 IMAGE_FLASH_SIZE=${FLASH_AREA_SIZE}
 PIC32_JLINK_SPEED=${PIC32_JLINK_SPEED:-12000}
+PIC32_JLINK_IF=${PIC32_JLINK_IF:-ICSP}
+
+case "${PIC32_JLINK_IF}" in
+    ICSP)
+        PIC32_JLINK_IF_ARGS="-If ICSP"
+        ;;
+    JTAG)
+        # Without -JTAGConf J-Link Commander asks for device position in
+        # JTAG chain and the question consumes commands from command file.
+        PIC32_JLINK_IF_ARGS="-If JTAG -JTAGConf -1,-1"
+        ;;
+    *)
+        >&2 echo "Unsupported PIC32_JLINK_IF=${PIC32_JLINK_IF} (ICSP or JTAG)"
+        exit 1
+        ;;
+esac
 
-# Runs JLinkExe with command file; fails if J-Link reported an error
+# Runs JLinkExe with command file; fails if J-Link reported an error.
+# Output is kept in JLINK_OUT for additional checks by caller.
 pic32_jlink_run() {
-    local out
-    out=$(JLink${COMSPEC:+.}Exe -Device ${PIC32_DEVICE} -If ICSP 
$EXTRA_JTAG_CMD "$@" 2>&1)
+    JLINK_OUT=$(JLink${COMSPEC:+.}Exe -Device ${PIC32_DEVICE} 
${PIC32_JLINK_IF_ARGS} $EXTRA_JTAG_CMD "$@" 2>&1)
     local rc=$?
-    echo "$out"
-    if [ $rc -ne 0 ] || echo "$out" | grep -q -E "Error occurred|Could not 
connect|Failed to"; then
+    echo "$JLINK_OUT"
+    if [ $rc -ne 0 ] || echo "$JLINK_OUT" | grep -q -E "Error occurred|Could 
not connect|Failed to|^JTAGConf>"; then
         echo "J-Link operation failed"
         exit 1
     fi
@@ -77,6 +98,12 @@ pic32_jlink_load() {
     echo "q" >> $script
 
     pic32_jlink_run -AutoConnect 1 -speed ${PIC32_JLINK_SPEED} -CommandFile 
$script
+    # loadfile prints O.K. when done, J-Link does not always report an error
+    # when target could not be reached
+    if ! echo "$JLINK_OUT" | grep -q -E "^O\.K\.[[:space:]]*$"; then
+        echo "J-Link did not program the image"
+        exit 1
+    fi
 
     # Code started by debugger reset and go does not run reliably (first
     # context switch never happens). Pulse MCLR without connecting to the

Reply via email to