Skip to content

Commit b1fde2a

Browse files
committed
openocd: added script to reset devices
1 parent 98467eb commit b1fde2a

File tree

11 files changed

+230
-0
lines changed

11 files changed

+230
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ install(
4545
scripts/create_firmware_ws.sh
4646
scripts/configure_firmware.sh
4747
scripts/flash_firmware.sh
48+
scripts/reset_firmware.sh
4849
scripts/build_firmware.sh
4950
scripts/build_agent.sh
5051
scripts/yaml_filter.py
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f446re_extensions
2+
3+
pushd $EXTENSIONS_DIR > /dev/null
4+
5+
echo "Resetting firmware for $RTOS platform $PLATFORM"
6+
if lsusb -d 0483:374b; then
7+
ST_INTERFACE=interface/stlink-v2-1.cfg
8+
elif lsusb -d 0483:3748; then
9+
ST_INTERFACE=interface/stlink-v2.cfg
10+
else
11+
# TODO: add stlink v3, should it be stlink.cfg ?
12+
echo "Error. Unsuported OpenOCD USB programmer"
13+
exit 1
14+
fi
15+
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
16+
17+
popd > /dev/null
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f446ze_extensions
2+
3+
pushd $EXTENSIONS_DIR > /dev/null
4+
5+
echo "Resetting firmware for $RTOS platform $PLATFORM"
6+
if lsusb -d 0483:374b; then
7+
ST_INTERFACE=interface/stlink-v2-1.cfg
8+
elif lsusb -d 0483:3748; then
9+
ST_INTERFACE=interface/stlink-v2.cfg
10+
else
11+
# TODO: add stlink v3, should it be stlink.cfg ?
12+
echo "Error. Unsuported OpenOCD USB programmer"
13+
exit 1
14+
fi
15+
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
16+
17+
popd > /dev/null
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f746zg_extensions
2+
3+
pushd $EXTENSIONS_DIR > /dev/null
4+
5+
echo "Resetting firmware for $RTOS platform $PLATFORM"
6+
if lsusb -d 0483:374b; then
7+
ST_INTERFACE=interface/stlink-v2-1.cfg
8+
elif lsusb -d 0483:3748; then
9+
ST_INTERFACE=interface/stlink-v2.cfg
10+
else
11+
# TODO: add stlink v3, should it be stlink.cfg ?
12+
echo "Error. Unsuported OpenOCD USB programmer"
13+
exit 1
14+
fi
15+
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
16+
17+
popd > /dev/null
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_nucleo_f767zi_extensions
2+
3+
pushd $EXTENSIONS_DIR > /dev/null
4+
5+
echo "Resetting firmware for $RTOS platform $PLATFORM"
6+
if lsusb -d 0483:374b; then
7+
ST_INTERFACE=interface/stlink-v2-1.cfg
8+
elif lsusb -d 0483:3748; then
9+
ST_INTERFACE=interface/stlink-v2.cfg
10+
else
11+
# TODO: add stlink v3, should it be stlink.cfg ?
12+
echo "Error. Unsuported OpenOCD USB programmer"
13+
exit 1
14+
fi
15+
openocd -f $ST_INTERFACE -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
16+
17+
popd > /dev/null
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
OLIMEX_EXTENSIONS_DIR=$FW_TARGETDIR/freertos_apps/microros_olimex_e407_extensions
2+
3+
pushd $OLIMEX_EXTENSIONS_DIR > /dev/null
4+
5+
if lsusb -d 15BA:002a; then
6+
PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
7+
elif lsusb -d 15BA:0003;then
8+
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
9+
elif lsusb -d 15BA:002b;then
10+
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
11+
else
12+
echo "Error. Unsuported OpenOCD USB programmer"
13+
exit 1
14+
fi
15+
16+
openocd -f $PROGRAMMER -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
17+
18+
popd > /dev/null
19+

config/host/generic/reset.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
echo "Nothing to reset: running in host mode"
2+
echo "Use 'RMW_IMPLEMENTATION=rmw_microxrcedds ros2 run micro_ros_demos_rcl int32_subscriber' to start with examples"

config/nuttx/generic/reset.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /bin/bash
2+
3+
set -e
4+
set -o nounset
5+
set -o pipefail
6+
7+
8+
pushd $FW_TARGETDIR/NuttX > /dev/null
9+
10+
if [ "$PLATFORM" = "olimex-stm32-e407" ]; then
11+
echo "Resetting firmware for $RTOS platform $PLATFORM"
12+
13+
if lsusb -d 15BA:002a; then
14+
PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
15+
elif lsusb -d 15BA:0003;then
16+
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
17+
elif lsusb -d 15BA:002b;then
18+
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
19+
elif lsusb -d 0483:3748;then
20+
PROGRAMMER=interface/stlink-v2.cfg
21+
else
22+
echo "Error. Unsuported OpenOCD USB programmer"
23+
exit 1
24+
fi
25+
26+
openocd -f $PROGRAMMER -f target/stm32f4x.cfg -c init -c "reset halt" -c "reset" -c "exit"
27+
else
28+
echo "Unrecognized board: $PLATFORM"
29+
exit 1
30+
fi
31+
32+
popd > /dev/null

config/raspbian/generic/flash.sh

100644100755
File mode changed.

config/zephyr/generic/reset.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
pushd $FW_TARGETDIR > /dev/null
2+
3+
ZEPHYR_BUILD_DIR="$FW_TARGETDIR/build/zephyr"
4+
5+
# Host platform (=native_posix) is special, as resetting is stopping and re-executing the binary
6+
if [ "$PLATFORM" = "host" ]; then
7+
8+
# TODO: stop the previous process
9+
$ZEPHYR_BUILD_DIR/zephyr.exe
10+
11+
else
12+
13+
# These boards need special openocd rules
14+
RESET_OPENOCD=false
15+
if [ "$PLATFORM" = "olimex-stm32-e407" ]; then
16+
17+
RESET_OPENOCD=true
18+
OPENOCD_TARGET="stm32f4x.cfg"
19+
if lsusb -d 15BA:002a; then
20+
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
21+
elif lsusb -d 15BA:0003;then
22+
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
23+
elif lsusb -d 15BA:002b;then
24+
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
25+
else
26+
echo "Error: Unsuported OpenOCD USB programmer"
27+
exit 1
28+
fi
29+
30+
elif [ "$PLATFORM" = "nucleo_f446re" ]; then
31+
32+
RESET_OPENOCD=true
33+
OPENOCD_TARGET="stm32f4x.cfg"
34+
35+
if lsusb -d 0483:374b;then
36+
OPENOCD_PROGRAMMER=interface/stlink-v2-1.cfg
37+
else
38+
echo "Error: Unsupported OpenOCD programmer"
39+
exit 1
40+
fi
41+
42+
elif [ "$PLATFORM" = "nucleo_h743zi" ]; then
43+
44+
RESET_OPENOCD=true
45+
OPENOCD_TARGET="stm32h7x.cfg"
46+
47+
if lsusb -d 0483:374e;then
48+
OPENOCD_PROGRAMMER=interface/stlink.cfg
49+
else
50+
echo "Error: Unsupported OpenOCD programmer"
51+
exit 1
52+
fi
53+
54+
fi
55+
56+
57+
58+
if [ "$RESET_OPENOCD" = true ]; then
59+
60+
openocd -f $OPENOCD_PROGRAMMER -f target/$OPENOCD_TARGET \
61+
-c init \
62+
-c "reset halt" \
63+
-c "reset run; exit"
64+
65+
else
66+
67+
echo "Error: Resetting device is only supported with OpenOCD"
68+
exit 1
69+
70+
fi
71+
72+
fi
73+
74+
popd > /dev/null

0 commit comments

Comments
 (0)