Skip to content

Commit 45804f8

Browse files
committed
feat(stm32cubeprog): add address and start options
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 8be0b5d commit 45804f8

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

stm32CubeProg.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ STM32CP_CLI=
88
INTERFACE=
99
PORT=
1010
FILEPATH=
11-
ADDRESS=0x8000000
1211
OFFSET=0x0
1312
# Optional
13+
ADDRESS=0x8000000
14+
START=0x8000000
15+
MODE=UR
1416
ERASE=
1517
# Optional for Serial
1618
RTS=
@@ -28,7 +30,10 @@ usage() {
2830
-i, --interface <'swd'/'dfu'/'serial'/'jlink'> interface identifier: 'swd', 'dfu', 'serial' or 'jlink'
2931
-f, --file <path> file path to be downloaded: bin or hex
3032
Optional options:
33+
-a, --address <hex value> flash base address. Default: $ADDRESS
3134
-e, --erase erase all sectors before flashing
35+
-m, --mode connection mode: UR (default), HOTPLUG, POWERDOWN or hwRstPulse
36+
-s, --start <hex value> start address after flashing. Default: $START
3237
-o, --offset <hex value> offset from flash base ($ADDRESS) where flashing should start
3338
3439
Specific options for Serial protocol:
@@ -118,7 +123,7 @@ if [ -n "${GNU_GETOPT}" ]; then
118123
exit 1
119124
fi
120125
else
121-
if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
126+
if ! options=$(getopt -a -o a:hi:m:ef:o:c:r:s:d:v:p: --long address:,help,interface:,mode:,erase,file:,start:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
122127
echo "Terminating..." >&2
123128
exit 1
124129
fi
@@ -136,6 +141,18 @@ while true; do
136141
echo "Selected interface: $INTERFACE"
137142
shift 2
138143
;;
144+
-m | --mode)
145+
MODE=$2
146+
shift 2
147+
;;
148+
-a | --address)
149+
ADDRESS=$2
150+
shift 2
151+
;;
152+
-s | --start)
153+
START=$2
154+
shift 2
155+
;;
139156
-e | --erase)
140157
ERASE="--erase all"
141158
shift 1
@@ -146,7 +163,6 @@ while true; do
146163
;;
147164
-o | --offset)
148165
OFFSET=$2
149-
ADDRESS=$(printf "0x%x" $((ADDRESS + OFFSET)))
150166
shift 2
151167
;;
152168
-c | --com)
@@ -180,6 +196,8 @@ while true; do
180196
esac
181197
done
182198

199+
ADDRESS=$(printf "0x%x" $((ADDRESS + OFFSET)))
200+
183201
# Check mandatory options
184202
if [ -z "${INTERFACE}" ]; then
185203
echo "Error missing interface!" >&2
@@ -196,14 +214,14 @@ fi
196214

197215
case "${INTERFACE}" in
198216
swd)
199-
${STM32CP_CLI} --connect port=SWD mode=UR "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
217+
${STM32CP_CLI} --connect port=SWD mode="${MODE}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
200218
;;
201219
dfu)
202220
if [ -z "${VID}" ] || [ -z "${PID}" ]; then
203221
echo "Missing mandatory arguments for DFU mode (VID/PID)!" >&2
204222
exit 1
205223
fi
206-
${STM32CP_CLI} --connect port=usb1 VID="${VID}" PID="${PID}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
224+
${STM32CP_CLI} --connect port=usb1 VID="${VID}" PID="${PID}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
207225
;;
208226
serial)
209227
if [ -z "${PORT}" ]; then
@@ -222,10 +240,10 @@ case "${INTERFACE}" in
222240
exit 1
223241
fi
224242
fi
225-
${STM32CP_CLI} --connect port="${PORT}" "${RTS}" "${DTR}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
243+
${STM32CP_CLI} --connect port="${PORT}" "${RTS}" "${DTR}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
226244
;;
227245
jlink)
228-
${STM32CP_CLI} --connect port=JLINK ap=0 "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${ADDRESS}"
246+
${STM32CP_CLI} --connect port=JLINK ap=0 "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
229247
;;
230248
*)
231249
echo "Protocol unknown!" >&2

0 commit comments

Comments
 (0)