Skip to content

Commit 0cac790

Browse files
Improve flash step for zephyr RTOS (#225)
* Clean up zephyr flash step There were some issues here: - The handling of the nucleo_h743zi platform seems to have been broken (caused by a wrong nesting in the platform selection) - Not all cases checked for the build artifact before using it - Console output differed between different platforms - Indentation was inconsistent Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de> * Unify zephyr flash openocd handling This changes the default behavior of the olimex-stm32-e407 platform, which previously didn't run directly after flashing. I could not find a reason why this should be the case and thus made it consistent with the "west flash" and nucleo_h743zi behavior. Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de> * Default to "west flash" when flashing with zephyr There is no real reason to check for platform validity there, and as we use zephyr this seems like a sane default. This also allows the usage of any zephyr-supported board (which can actually run uros) by just adding its name to the supported_platforms file (previously, a special casing in flash.sh was also needed). Signed-off-by: Robert Wilbrandt <robert@stamm-wilbrandt.de>
1 parent 12da774 commit 0cac790

1 file changed

Lines changed: 68 additions & 37 deletions

File tree

config/zephyr/generic/flash.sh

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,79 @@
11
pushd $FW_TARGETDIR > /dev/null
22

3-
if [ "$PLATFORM" = "discovery_l475_iot1" ] || [ "$PLATFORM" = "nucleo_f401re" ]; then
4-
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
5-
export ZEPHYR_SDK_INSTALL_DIR=$FW_TARGETDIR/zephyr-sdk
6-
7-
source $FW_TARGETDIR/zephyrproject/zephyr/zephyr-env.sh
8-
9-
export PATH=~/.local/bin:"$PATH"
10-
11-
west flash
12-
elif [ "$PLATFORM" = "olimex-stm32-e407" ]; then
13-
if [ -f build/zephyr/zephyr.bin ]; then
14-
echo "Flashing firmware for $RTOS platform $PLATFORM"
15-
16-
if lsusb -d 15BA:002a; then
17-
PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
18-
elif lsusb -d 15BA:0003;then
19-
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
20-
elif lsusb -d 15BA:002b;then
21-
PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
22-
else
23-
echo "Error. Unsuported OpenOCD USB programmer"
24-
exit 1
25-
fi
3+
ZEPHYR_BUILD_DIR="$FW_TARGETDIR/build/zephyr"
264

27-
openocd -f $PROGRAMMER -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase build/zephyr/zephyr.bin 0x08000000" -c "reset" -c "exit"
5+
# Host platform (=native_posix) is special, as flashing is actually just executing the binary
6+
if [ "$PLATFORM" = "host" ]; then
287

29-
elif [ "$PLATFORM" = "nucleo_h743zi" ]; then
30-
if lsusb -d 0483:374e;then
31-
PROGRAMMER=interface/stlink.cfg
32-
TARGET=stm32h7x.cfg
8+
if [ ! -f "$ZEPHYR_BUILD_DIR/zephyr.exe" ]; then
9+
echo "Error: $ZEPHYR_BUILD_DIR/zephyr.exe not found. Please compile before flashing."
10+
exit 1
3311
fi
3412

35-
openocd -f $PROGRAMMER -f target/$TARGET -c init -c "reset halt" -c "flash write_image erase build/zephyr/zephyr.bin 0x08000000" -c "reset run; exit"
13+
$ZEPHYR_BUILD_DIR/zephyr.exe
3614

37-
else
38-
echo "build/zephyr/zephyr.bin not found: please compile before flashing."
39-
fi
40-
elif [ "$PLATFORM" = "host" ]; then
41-
./build/zephyr/zephyr.exe
4215
else
43-
echo "Unrecognized board: $PLATFORM"
44-
exit 1
16+
17+
if [ ! -f "$ZEPHYR_BUILD_DIR/zephyr.bin" ]; then
18+
echo "Error: $ZEPHYR_BUILD_DIR/zephyr.bin not found. Please compile before flashing."
19+
exit 1
20+
fi
21+
22+
23+
24+
# These boards need special openocd rules
25+
FLASH_OPENOCD=false
26+
if [ "$PLATFORM" = "olimex-stm32-e407" ]; then
27+
28+
FLASH_OPENOCD=true
29+
OPENOCD_TARGET="stm32f4x.cfg"
30+
if lsusb -d 15BA:002a; then
31+
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-tiny-h.cfg
32+
elif lsusb -d 15BA:0003;then
33+
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd.cfg
34+
elif lsusb -d 15BA:002b;then
35+
OPENOCD_PROGRAMMER=interface/ftdi/olimex-arm-usb-ocd-h.cfg
36+
else
37+
echo "Error: Unsuported OpenOCD USB programmer"
38+
exit 1
39+
fi
40+
41+
elif [ "$PLATFORM" = "nucleo_h743zi" ]; then
42+
43+
FLASH_OPENOCD=true
44+
OPENOCD_TARGET="stm32h7x.cfg"
45+
46+
if lsusb -d 0483:374e;then
47+
OPENOCD_PROGRAMMER=interface/stlink.cfg
48+
else
49+
echo "Error: Unsupported OpenOCD programmer"
50+
exit 1
51+
fi
52+
53+
fi
54+
55+
56+
57+
if [ "$FLASH_OPENOCD" = true ]; then
58+
59+
openocd -f $OPENOCD_PROGRAMMER -f target/$OPENOCD_TARGET \
60+
-c init \
61+
-c "reset halt" \
62+
-c "flash write_image erase $ZEPHYR_BUILD_DIR/zephyr.bin 0x08000000" \
63+
-c "reset run; exit"
64+
65+
else
66+
67+
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
68+
export ZEPHYR_SDK_INSTALL_DIR=$FW_TARGETDIR/zephyr-sdk
69+
export PATH=~/.local/bin:"$PATH"
70+
71+
source $FW_TARGETDIR/zephyrproject/zephyr/zephyr-env.sh
72+
73+
west flash
74+
75+
fi
76+
4577
fi
4678

4779
popd > /dev/null
48-

0 commit comments

Comments
 (0)