Skip to content

Commit

Permalink
openocd: added script to reset devices (#399)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7a2aeaf)
  • Loading branch information
dayjaby authored and Acuadros95 committed Oct 26, 2021
1 parent 2b326a3 commit fcf4459
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ install(
scripts/create_firmware_ws.sh
scripts/configure_firmware.sh
scripts/flash_firmware.sh
scripts/reset_firmware.sh
scripts/build_firmware.sh
scripts/build_agent.sh
scripts/yaml_filter.py
Expand Down
17 changes: 17 additions & 0 deletions config/freertos/nucleo_f446re/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f446re_extensions

pushd $EXTENSIONS_DIR > /dev/null

echo "Resetting firmware for $RTOS platform $PLATFORM"
if lsusb -d 0483:374b; then
ST_INTERFACE=interface/stlink-v2-1.cfg
elif lsusb -d 0483:3748; then
ST_INTERFACE=interface/stlink-v2.cfg
else
# TODO: add stlink v3, should it be stlink.cfg ?
echo "Error. Unsuported OpenOCD USB programmer"
exit 1
fi
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"

popd > /dev/null
17 changes: 17 additions & 0 deletions config/freertos/nucleo_f446ze/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f446ze_extensions

pushd $EXTENSIONS_DIR > /dev/null

echo "Resetting firmware for $RTOS platform $PLATFORM"
if lsusb -d 0483:374b; then
ST_INTERFACE=interface/stlink-v2-1.cfg
elif lsusb -d 0483:3748; then
ST_INTERFACE=interface/stlink-v2.cfg
else
# TODO: add stlink v3, should it be stlink.cfg ?
echo "Error. Unsuported OpenOCD USB programmer"
exit 1
fi
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"

popd > /dev/null
17 changes: 17 additions & 0 deletions config/freertos/nucleo_f746zg/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f746zg_extensions

pushd $EXTENSIONS_DIR > /dev/null

echo "Resetting firmware for $RTOS platform $PLATFORM"
if lsusb -d 0483:374b; then
ST_INTERFACE=interface/stlink-v2-1.cfg
elif lsusb -d 0483:3748; then
ST_INTERFACE=interface/stlink-v2.cfg
else
# TODO: add stlink v3, should it be stlink.cfg ?
echo "Error. Unsuported OpenOCD USB programmer"
exit 1
fi
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"

popd > /dev/null
17 changes: 17 additions & 0 deletions config/freertos/nucleo_f767zi/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f767zi_extensions

pushd $EXTENSIONS_DIR > /dev/null

echo "Resetting firmware for $RTOS platform $PLATFORM"
if lsusb -d 0483:374b; then
ST_INTERFACE=interface/stlink-v2-1.cfg
elif lsusb -d 0483:3748; then
ST_INTERFACE=interface/stlink-v2.cfg
else
# TODO: add stlink v3, should it be stlink.cfg ?
echo "Error. Unsuported OpenOCD USB programmer"
exit 1
fi
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"

popd > /dev/null
19 changes: 19 additions & 0 deletions config/freertos/olimex-stm32-e407/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
OLIMEX_EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_olimex_e407_extensions

pushd $OLIMEX_EXTENSIONS_DIR > /dev/null

if lsusb -d 15BA:002a; then
PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
elif lsusb -d 15BA:0003;then
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
elif lsusb -d 15BA:002b;then
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
else
echo "Error. Unsuported OpenOCD USB programmer"
exit 1
fi

openocd -f $PROGRAMMER -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"

popd > /dev/null

2 changes: 2 additions & 0 deletions config/host/generic/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "Nothing to reset: running in host mode"
echo "Use 'RMW_IMPLEMENTATION=rmw_microxrcedds ros2 run micro_ros_demos_rcl int32_subscriber' to start with examples"
32 changes: 32 additions & 0 deletions config/nuttx/generic/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /bin/bash

set -e
set -o nounset
set -o pipefail


pushd $FW_TARGETDIR/NuttX > /dev/null

if [ "$PLATFORM" = "olimex-stm32-e407" ]; then
echo "Resetting firmware for $RTOS platform $PLATFORM"

if lsusb -d 15BA:002a; then
PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
elif lsusb -d 15BA:0003;then
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
elif lsusb -d 15BA:002b;then
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
elif lsusb -d 0483:3748;then
PROGRAMMER=interface/stlink-v2.cfg
else
echo "Error. Unsuported OpenOCD USB programmer"
exit 1
fi

openocd -f $PROGRAMMER -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
else
echo "Unrecognized board: $PLATFORM"
exit 1
fi

popd > /dev/null
Empty file modified config/raspbian/generic/flash.sh
100644 → 100755
Empty file.
74 changes: 74 additions & 0 deletions config/zephyr/generic/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
pushd $FW_TARGETDIR > /dev/null

ZEPHYR_BUILD_DIR="$FW_TARGETDIR/build/zephyr"

# Host platform (=native_posix) is special, as resetting is stopping and re-executing the binary
if [ "$PLATFORM" = "host" ]; then

# TODO: stop the previous process
$ZEPHYR_BUILD_DIR/zephyr.exe

else

# These boards need special openocd rules
RESET_OPENOCD=false
if [ "$PLATFORM" = "olimex-stm32-e407" ]; then

RESET_OPENOCD=true
OPENOCD_TARGET="stm32f4x.cfg"
if lsusb -d 15BA:002a; then
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
elif lsusb -d 15BA:0003;then
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
elif lsusb -d 15BA:002b;then
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
else
echo "Error: Unsuported OpenOCD USB programmer"
exit 1
fi

elif [ "$PLATFORM" = "nucleo_f446re" ]; then

RESET_OPENOCD=true
OPENOCD_TARGET="stm32f4x.cfg"

if lsusb -d 0483:374b;then
OPENOCD_PROGRAMMER=interface/stlink-v2-1.cfg
else
echo "Error: Unsupported OpenOCD programmer"
exit 1
fi

elif [ "$PLATFORM" = "nucleo_h743zi" ]; then

RESET_OPENOCD=true
OPENOCD_TARGET="stm32h7x.cfg"

if lsusb -d 0483:374e;then
OPENOCD_PROGRAMMER=interface/stlink.cfg
else
echo "Error: Unsupported OpenOCD programmer"
exit 1
fi

fi



if [ "$RESET_OPENOCD" = true ]; then

openocd -f $OPENOCD_PROGRAMMER -f target/$OPENOCD_TARGET \
-c init \
-c "reset halt" \
-c "reset run; exit"

else

echo "Error: Resetting device is only supported with OpenOCD"
exit 1

fi

fi

popd > /dev/null
34 changes: 34 additions & 0 deletions scripts/reset_firmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /bin/bash

set -e
set -o nounset
set -o pipefail

FW_TARGETDIR=$(pwd)/firmware
PREFIX=$(ros2 pkg prefix micro_ros_setup)

# Checking if firmware exists
if [ -d $FW_TARGETDIR ]; then
RTOS=$(head -n1 $FW_TARGETDIR/PLATFORM)
PLATFORM=$(head -n2 firmware/PLATFORM | tail -n1)
else
echo "Firmware folder not found. Please use ros2 run micro_ros_setup create_firmware_ws.sh to create a new project."
exit 1
fi

# Reset specific firmware
if [ $PLATFORM != "generic" ] && [ -d "$PREFIX/config/$RTOS/generic" ]; then
if [ -f $PREFIX/config/$RTOS/generic/reset.sh ]; then
echo "Resetting firmware for $RTOS platform $PLATFORM"
. $PREFIX/config/$RTOS/generic/reset.sh
else
echo "No reset step found for $RTOS platform $PLATFORM"
fi
else
if [ -f $PREFIX/config/$RTOS/$PLATFORM/reset.sh ]; then
echo "Resetting firmware for $RTOS platform $PLATFORM"
. $PREFIX/config/$RTOS/$PLATFORM/reset.sh
else
echo "No reset step found for $RTOS platform $PLATFORM"
fi
fi

0 comments on commit fcf4459

Please sign in to comment.