Skip to content

Commit c2b8d22

Browse files
committed
feat(stm32CubeProg): add offset option
Fixes #57 Signed-off-by: Frederic Pillon <[email protected]>
1 parent b1c2d2c commit c2b8d22

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Diff for: stm32CubeProg.sh

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh -
22
set -o nounset # Treat unset variables as an error
3+
# set -o xtrace # Print command traces before executing command.
34

45
STM32CP_CLI=
56
ADDRESS=0x8000000
@@ -13,7 +14,7 @@ OPTS=""
1314
usage() {
1415
echo "############################################################"
1516
echo "##"
16-
echo "## $(basename "$0") <protocol> <file_path> [OPTIONS]"
17+
echo "## $(basename "$0") <protocol> <file_path> <offset> [OPTIONS]"
1718
echo "##"
1819
echo "## protocol:"
1920
echo "## 0: SWD"
@@ -22,6 +23,7 @@ usage() {
2223
echo "## Note: prefix it by 1 to erase all sectors."
2324
echo "## Ex: 10 erase all sectors using SWD interface."
2425
echo "## file_path: file path name to be downloaded: (bin, hex)"
26+
echo "## offset: offset to add to $ADDRESS"
2527
echo "## Options:"
2628
echo "## For SWD and DFU: no mandatory options"
2729
echo "## For Serial: <com_port>"
@@ -92,14 +94,17 @@ case "${UNAME_OS}" in
9294
;;
9395
esac
9496

95-
if [ $# -lt 2 ]; then
97+
if [ $# -lt 3 ]; then
9698
echo "Not enough arguments!"
9799
usage 2
98100
fi
99101

100102
# Parse options
101103
PROTOCOL=$1
102104
FILEPATH=$2
105+
OFFSET=$3
106+
ADDRESS=$(printf "0x%x" $((ADDRESS + OFFSET)))
107+
103108
# Protocol $1
104109
# 1x: Erase all sectors
105110
if [ "$1" -ge 10 ]; then
@@ -114,19 +119,19 @@ case $PROTOCOL in
114119
0)
115120
PORT="SWD"
116121
MODE="mode=UR"
117-
shift 2
122+
shift 3
118123
;;
119124
1)
120-
if [ $# -lt 3 ]; then
125+
if [ $# -lt 4 ]; then
121126
usage 3
122127
else
123-
PORT=$3
124-
shift 3
128+
PORT=$4
129+
shift 4
125130
fi
126131
;;
127132
2)
128133
PORT="USB1"
129-
shift 2
134+
shift 3
130135
;;
131136
*)
132137
echo "Protocol unknown!"

0 commit comments

Comments
 (0)