@@ -23,23 +23,23 @@ usage() {
2323 echo " Usage: $( basename " $0 " ) [OPTIONS]...
2424
2525 Mandatory options:
26- -i, --interface <'swd'/'dfu'/'serial'> interface identifier: 'swd', 'dfu' or 'serial'
27- -f, --file <path> file path to be downloaded: bin or hex
26+ -i <'swd'/'dfu'/'serial'> interface identifier: 'swd', 'dfu' or 'serial'
27+ -f <path> file path to be downloaded: bin or hex
2828 Optional options:
29- -e, --erase erase all sectors before flashing
30- -o, --offset <hex value> offset from flash base ($ADDRESS ) where flashing should start
29+ -e
30+ -o <hex value> offset from flash base ($ADDRESS ) where flashing should start
3131
3232 Specific options for Serial protocol:
3333 Mandatory:
34- -c, --com <name> serial identifier, ex: COM1 or /dev/ttyS0,...
34+ -c <name> serial identifier, ex: COM1 or /dev/ttyS0,...
3535 Optional:
36- -r, --rts <low/high> polarity of RTS signal ('low' by default)
37- -d, --dtr <low/high> polarity of DTR signal
36+ -r <low/high> polarity of RTS signal ('low' by default)
37+ -d <low/high> polarity of DTR signal
3838
3939 Specific options for DFU protocol:
4040 Mandatory:
41- -v, --vid <hex value> vendor id, ex: 0x0483
42- -p, --pid <hex value> product id, ex: 0xdf11
41+ -v <hex value> vendor id, ex: 0x0483
42+ -p <hex value> product id, ex: 0xdf11
4343
4444" >&2
4545 exit " $1 "
@@ -55,7 +55,7 @@ aborting() {
5555
5656# parse command line arguments
5757# options may be followed by one colon to indicate they have a required arg
58- 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
58+ if ! options=$( getopt hi:ef:o:c:r:d:v:p: " $@ " ) ; then
5959 echo " Terminating..." >&2
6060 exit 1
6161fi
@@ -64,51 +64,67 @@ eval set -- "$options"
6464
6565while true ; do
6666 case " $1 " in
67- -h | --help | - \? )
67+ -h | -\? )
6868 usage 0
6969 ;;
70- -i | --interface )
70+ -i)
7171 INTERFACE=$( echo " $2 " | tr ' [:upper:]' ' [:lower:]' )
7272 echo " Selected interface: $INTERFACE "
7373 shift 2
7474 ;;
75- -e | --erase )
75+ -e)
7676 ERASE=" --erase all"
7777 shift 1
7878 ;;
79- -f | --file )
79+ -f)
8080 FILEPATH=$2
8181 shift 2
82+ # Need to check if next arg start with '-' else
83+ # it is probably a path including one or more space
84+ # Since getopt is used space is not protected
85+ while true ; do
86+ case $1 in
87+ -* )
88+ break
89+ ;;
90+ esac
91+ FILEPATH=" $FILEPATH $1 "
92+ shift 1
93+ done
8294 ;;
83- -o | --offset )
95+ -o)
8496 OFFSET=$2
8597 ADDRESS=$( printf " 0x%x" $(( ADDRESS + OFFSET)) )
8698 shift 2
8799 ;;
88- -c | --com )
100+ -c)
89101 PORT=$2
90102 shift 2
91103 ;;
92- -r | --rts )
104+ -r)
93105 RTS=$( echo " rts=$2 " | tr ' [:upper:]' ' [:lower:]' )
94106 shift 2
95107 ;;
96- -d | --dtr )
108+ -d)
97109 DTR=$( echo " dtr=$2 " | tr ' [:upper:]' ' [:lower:]' )
98110 shift 2
99111 ;;
100- -v | --vid )
112+ -v)
101113 VID=$2
102114 shift 2
103115 ;;
104- -p | --pid )
116+ -p)
105117 PID=$2
106118 shift 2
107119 ;;
108120 --)
109121 shift
110122 break
111123 ;;
124+ * )
125+ echo " Unknown option $1 "
126+ usage 1
127+ ;;
112128 esac
113129done
114130# Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu
0 commit comments