RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

Added USB_LOCATION to OpenOCD.sh

Open greedystack opened this issue 3 years ago • 3 comments

Now able to select USB-Port on which to flash via the ENV-Var OPENOCD_USB_LOCATION. Useful, when more than 1 device simultaneously attached to computer.

Contribution description

Adding argument to openocd to support usb-port location when flashing

  • describe which part(s) of RIOT is (are) involved: only openocd.sh

Testing procedure

Flashing with this config tested approx. a thousand times while working with RIOT on my Bachelor Thesis

Issues/PRs references

/

greedystack avatar Aug 03 '22 11:08 greedystack

After applying this patch:

diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh
index 6695f221d5..718b9b0568 100755
--- a/dist/tools/openocd/openocd.sh
+++ b/dist/tools/openocd/openocd.sh
@@ -146,13 +146,12 @@ if [ "${OPENOCD_RESET_USE_CONNECT_ASSERT_SRST}" = "1" ]; then
   OPENOCD_EXTRA_RESET_INIT+="-c 'reset_config connect_assert_srst'"
 fi
 
-${OPENOCD_ADAPTER_USB_LOCATION:=}
 # Choose USB-Port to use openocd on (via ENV-Var $OPENOCD_USB_LOCATION). Useful, when more than 1 device attached.
-    if [[ ! -z ${OPENOCD_USB_LOCATION} ]] ; then
-        ${OPENOCD_ADAPTER_USB_LOCATION:="-c 'adapter usb location ${OPENOCD_USB_LOCATION}'"}
-        # adapter usb location [<bus>-<port>[.<port>]...]
-        # Page 37 in Manual: https://openocd.org/doc/pdf/openocd.pdf
-    fi
+if [[ -n "${OPENOCD_USB_LOCATION}" ]] ; then
+    export OPENOCD_ADAPTER_USB_LOCATION="-c 'adapter usb location ${OPENOCD_USB_LOCATION}'"
+    # adapter usb location [<bus>-<port>[.<port>]...]
+    # Page 37 in Manual: https://openocd.org/doc/pdf/openocd.pdf
+fi
 
 #
 # a couple of tests for certain configuration options
@@ -360,7 +359,6 @@ do_flash() {
         echo "Flashing with IMAGE_OFFSET: ${IMAGE_OFFSET}"
     fi
 
-    
     # flash device
     sh -c "${OPENOCD} \
             ${OPENOCD_ADAPTER_INIT} \

it worked for me as advertised. Could you apply the patch? Ideally this would be documented by adding a special section for using OpenOCD via the RIOT build system, but there is no such page. I think for this reason it is fine to merge this undocumented.

I plan to open a PR to add the documentation for using OpenOCD via the RIOT build system to fill this gab. I can also document this new option then.

maribu avatar Aug 10 '22 15:08 maribu

There now is a place upstream the new option can be documented:

doc/doxgen/src/flashing.md in section OpenOCD Configuration

Please add this option to the documentation, so that others are more likely to find and profit from this feature :)

maribu avatar Aug 16 '22 20:08 maribu

Ping :)

maribu avatar Sep 14 '22 12:09 maribu

@maribu I don't think the author is going to react anytime soon. We can either pick this work up or close the PR. Opinion?

Teufelchen1 avatar Mar 26 '24 13:03 Teufelchen1