Skip to content

Commit b33b5d7

Browse files
committed
feat(stm32cubeprog): add -f/--freq for swd protocol
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent ce48a42 commit b33b5d7

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎stm32CubeProg.sh‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ADDRESS=0x8000000
1414
START=0x8000000
1515
ERASE=
1616
# Optional for SWD
17+
FREQ=
1718
MODE=UR
1819
# Optional for Serial
1920
RTS=
@@ -39,6 +40,7 @@ usage() {
3940
4041
Specific options for SWD protocol:
4142
Optional:
43+
-f, --freq <value> SWD frequency in KHz.
4244
-m, --mode connection mode: UR (default), HOTPLUG, POWERDOWN or hwRstPulse
4345
4446
Specific options for Serial protocol:
@@ -124,12 +126,12 @@ esac
124126
# parse command line arguments
125127
# options may be followed by one colon to indicate they have a required arg
126128
if [ -n "${GNU_GETOPT}" ]; then
127-
if ! options=$(getopt hi:b:a:es:o:m:c:d:p:r:v: "$@"); then
129+
if ! options=$(getopt hi:b:a:es:o:f:m:c:d:p:r:v: "$@"); then
128130
echo "Terminating..." >&2
129131
exit 1
130132
fi
131133
else
132-
if ! options=$(getopt -a -o hi:b:a:es:o:m:c:d:p:r:v: --long help,interface:,bin:,address:,erase,start:,offset:,mode:,com:,dtr:,parity:,rts:,pid:,vid: -- "$@"); then
134+
if ! options=$(getopt -a -o hi:b:a:es:o:f:m:c:d:p:r:v: --long help,interface:,bin:,address:,erase,start:,offset:,freq:,mode:,com:,dtr:,parity:,rts:,pid:,vid: -- "$@"); then
133135
echo "Terminating..." >&2
134136
exit 1
135137
fi
@@ -167,6 +169,10 @@ while true; do
167169
OFFSET=$2
168170
shift 2
169171
;;
172+
-f | --freq)
173+
FREQ=$2
174+
shift 2
175+
;;
170176
-m | --mode)
171177
MODE=$2
172178
shift 2
@@ -221,7 +227,20 @@ fi
221227

222228
case "${INTERFACE}" in
223229
swd)
224-
${STM32CP_CLI} --connect port=SWD mode="${MODE}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
230+
PORT_PARAM="port=SWD"
231+
if [ -n "${FREQ}" ]; then
232+
case "${FREQ}" in
233+
0) ;;
234+
*[!0-9]*)
235+
echo "Invalid SWD frequency (expected integer KHz): ${FREQ}" >&2
236+
exit 1
237+
;;
238+
*)
239+
PORT_PARAM="${PORT_PARAM} freq=${FREQ}"
240+
;;
241+
esac
242+
fi
243+
${STM32CP_CLI} --connect "${PORT_PARAM}" mode="${MODE}" "${ERASE}" --quietMode --download "${FILEPATH}" "${ADDRESS}" --start "${START}"
225244
;;
226245
dfu)
227246
if [ -z "${VID}" ] || [ -z "${PID}" ]; then

0 commit comments

Comments
 (0)