@@ -12,8 +12,11 @@ OFFSET=0x0
1212# Optional
1313ADDRESS=0x8000000
1414START=0x8000000
15- MODE=UR
1615ERASE=
16+ # Optional for SWD
17+ FREQ=
18+ MODE=UR
19+ SERIAL_NUMBER=
1720# Optional for Serial
1821RTS=
1922DTR=
@@ -29,23 +32,27 @@ usage() {
2932
3033 Mandatory options:
3134 -i, --interface <'swd'/'dfu'/'serial'/'jlink'> interface identifier: 'swd', 'dfu', 'serial' or 'jlink'
32- -f , --file <path > file path to be downloaded: bin or hex
35+ -b , --bin <file_path > binary file path to be downloaded: bin or hex
3336 Optional options:
3437 -a, --address <hex value> flash base address. Default: $ADDRESS
3538 -e, --erase erase all sectors before flashing
36- -m, --mode connection mode: UR (default), HOTPLUG, POWERDOWN or hwRstPulse
3739 -s, --start <hex value> start address after flashing. Default: $START
3840 -o, --offset <hex value> offset from flash base ($ADDRESS ) where flashing should start
3941
42+ Specific options for SWD protocol:
43+ Optional:
44+ -f, --freq <value> SWD frequency in KHz.
45+ -m, --mode connection mode: UR (default), HOTPLUG, POWERDOWN or hwRstPulse
46+ -n, --snum <serial number> serial number of the ST-Link device (if multiple ST-Link devices are connected)
4047 Specific options for Serial protocol:
4148 Mandatory:
42- -c, --com <name> serial identifier, ex: COM1 or /dev/ttyS0,...
49+ -c, --com <name> serial identifier, ex: COM1 or /dev/ttyS0,...
4350 Optional:
44- -r, --rts <low/high> polarity of RTS signal ('low' by default)
4551 -d, --dtr <low/high> polarity of DTR signal
4652 -p, --parity <none/even/odd> parity bit configuration ('even' by default)
53+ -r, --rts <low/high> polarity of RTS signal ('low' by default)
4754
48- Specific options for DFU protocol:
55+ Specific options for DFU protocol:
4956 Mandatory:
5057 -v, --vid <hex value> vendor id, ex: 0x0483
5158 -p, --pid <hex value> product id, ex: 0xdf11
@@ -120,12 +127,12 @@ esac
120127# parse command line arguments
121128# options may be followed by one colon to indicate they have a required arg
122129if [ -n " ${GNU_GETOPT} " ]; then
123- if ! options=$( getopt a: hi:m:ef:o:c:r:s:d:v:p : " $@ " ) ; then
130+ if ! options=$( getopt hi:b:a:es:o:f:m:n:c:d:p:r:v : " $@ " ) ; then
124131 echo " Terminating..." >&2
125132 exit 1
126133 fi
127134else
128- 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:,parity : -- " $@ " ) ; then
135+ if ! options=$( getopt -a -o hi:b:a:es:o:f:m:n:c:d:p:r:v: --long help,interface:,bin:,address:,erase, start:,offset:,freq:,mode:,snum:,com:, dtr:,parity:,rts:, pid:,vid : -- " $@ " ) ; then
129136 echo " Terminating..." >&2
130137 exit 1
131138 fi
@@ -143,51 +150,59 @@ while true; do
143150 echo " Selected interface: $INTERFACE "
144151 shift 2
145152 ;;
146- -m | --mode )
147- MODE =$2
153+ -b | --bin )
154+ FILEPATH =$2
148155 shift 2
149156 ;;
150157 -a | --address)
151158 ADDRESS=$2
152159 shift 2
153160 ;;
154- -s | --start)
155- START=$2
156- shift 2
157- ;;
158161 -e | --erase)
159162 ERASE=" --erase all"
160163 shift 1
161164 ;;
162- -f | --file )
163- FILEPATH =$2
165+ -s | --start )
166+ START =$2
164167 shift 2
165168 ;;
166169 -o | --offset)
167170 OFFSET=$2
168171 shift 2
169172 ;;
170- -c | --com )
171- PORT =$2
173+ -f | --freq )
174+ FREQ =$2
172175 shift 2
173176 ;;
174- -r | --rts )
175- RTS= $( echo " rts= $2 " | tr ' [:upper:] ' ' [:lower:] ' )
177+ -m | --mode )
178+ MODE= $2
176179 shift 2
177180 ;;
178- -d | --dtr )
179- DTR= $( echo " dtr= $2 " | tr ' [:upper:] ' ' [:lower:] ' )
181+ -n | --snum )
182+ SERIAL_NUMBER= " $2 "
180183 shift 2
181184 ;;
182- -v | --vid)
183- VID=$2
185+ -c | --com)
186+ PORT=$2
187+ shift 2
188+ ;;
189+ -d | --dtr)
190+ DTR=$( echo " dtr=$2 " | tr ' [:upper:]' ' [:lower:]' )
184191 shift 2
185192 ;;
186193 -p | --pid | --parity)
187194 PID=$2
188195 PARITY=$( echo " $2 " | tr ' [:lower:]' ' [:upper:]' )
189196 shift 2
190197 ;;
198+ -r | --rts)
199+ RTS=$( echo " rts=$2 " | tr ' [:upper:]' ' [:lower:]' )
200+ shift 2
201+ ;;
202+ -v | --vid)
203+ VID=$2
204+ shift 2
205+ ;;
191206 --)
192207 shift
193208 break
@@ -207,7 +222,7 @@ if [ -z "${INTERFACE}" ]; then
207222 usage 1
208223fi
209224if [ -z " ${FILEPATH} " ]; then
210- echo " Error missing file argmument !" >&2
225+ echo " Error missing binary file argument !" >&2
211226 usage 1
212227fi
213228if [ ! -r " ${FILEPATH} " ]; then
217232
218233case " ${INTERFACE} " in
219234 swd)
220- ${STM32CP_CLI} --connect port=SWD mode=" ${MODE} " " ${ERASE} " --quietMode --download " ${FILEPATH} " " ${ADDRESS} " --start " ${START} "
235+ PORT_PARAM=" port=SWD"
236+ if [ -n " ${FREQ} " ]; then
237+ case " ${FREQ} " in
238+ 0) ;;
239+ * [!0-9]* )
240+ echo " Invalid SWD frequency (expected integer KHz): ${FREQ} " >&2
241+ exit 1
242+ ;;
243+ * )
244+ PORT_PARAM=" ${PORT_PARAM} freq=${FREQ} "
245+ ;;
246+ esac
247+ fi
248+ if [ -n " ${SERIAL_NUMBER} " ] && [ " ${SERIAL_NUMBER} " != " 0" ]; then
249+ PORT_PARAM=" ${PORT_PARAM} sn=${SERIAL_NUMBER} "
250+ fi
251+ ${STM32CP_CLI} --connect " ${PORT_PARAM} " mode=" ${MODE} " " ${ERASE} " --quietMode --download " ${FILEPATH} " " ${ADDRESS} " --start " ${START} "
221252 ;;
222253 dfu)
223254 if [ -z " ${VID} " ] || [ -z " ${PID} " ]; then
0 commit comments