@@ -8,9 +8,11 @@ STM32CP_CLI=
8
8
INTERFACE=
9
9
PORT=
10
10
FILEPATH=
11
- ADDRESS=0x8000000
12
11
OFFSET=0x0
13
12
# Optional
13
+ ADDRESS=0x8000000
14
+ START=0x8000000
15
+ MODE=UR
14
16
ERASE=
15
17
# Optional for Serial
16
18
RTS=
@@ -28,7 +30,10 @@ usage() {
28
30
-i, --interface <'swd'/'dfu'/'serial'/'jlink'> interface identifier: 'swd', 'dfu', 'serial' or 'jlink'
29
31
-f, --file <path> file path to be downloaded: bin or hex
30
32
Optional options:
33
+ -a, --address <hex value> flash base address. Default: $ADDRESS
31
34
-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
32
37
-o, --offset <hex value> offset from flash base ($ADDRESS ) where flashing should start
33
38
34
39
Specific options for Serial protocol:
@@ -118,7 +123,7 @@ if [ -n "${GNU_GETOPT}" ]; then
118
123
exit 1
119
124
fi
120
125
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
122
127
echo " Terminating..." >&2
123
128
exit 1
124
129
fi
@@ -136,6 +141,18 @@ while true; do
136
141
echo " Selected interface: $INTERFACE "
137
142
shift 2
138
143
;;
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
+ ;;
139
156
-e | --erase)
140
157
ERASE=" --erase all"
141
158
shift 1
@@ -146,7 +163,6 @@ while true; do
146
163
;;
147
164
-o | --offset)
148
165
OFFSET=$2
149
- ADDRESS=$( printf " 0x%x" $(( ADDRESS + OFFSET)) )
150
166
shift 2
151
167
;;
152
168
-c | --com)
@@ -180,6 +196,8 @@ while true; do
180
196
esac
181
197
done
182
198
199
+ ADDRESS=$( printf " 0x%x" $(( ADDRESS + OFFSET)) )
200
+
183
201
# Check mandatory options
184
202
if [ -z " ${INTERFACE} " ]; then
185
203
echo " Error missing interface!" >&2
196
214
197
215
case " ${INTERFACE} " in
198
216
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 } "
200
218
;;
201
219
dfu)
202
220
if [ -z " ${VID} " ] || [ -z " ${PID} " ]; then
203
221
echo " Missing mandatory arguments for DFU mode (VID/PID)!" >&2
204
222
exit 1
205
223
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 } "
207
225
;;
208
226
serial)
209
227
if [ -z " ${PORT} " ]; then
@@ -222,10 +240,10 @@ case "${INTERFACE}" in
222
240
exit 1
223
241
fi
224
242
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 } "
226
244
;;
227
245
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 } "
229
247
;;
230
248
* )
231
249
echo " Protocol unknown!" >&2
0 commit comments