@@ -23,23 +23,23 @@ usage() {
23
23
echo " Usage: $( basename " $0 " ) [OPTIONS]...
24
24
25
25
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
28
28
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
31
31
32
32
Specific options for Serial protocol:
33
33
Mandatory:
34
- -c, --com <name> serial identifier, ex: COM1 or /dev/ttyS0,...
34
+ -c <name> serial identifier, ex: COM1 or /dev/ttyS0,...
35
35
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
38
38
39
39
Specific options for DFU protocol:
40
40
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
43
43
44
44
" >&2
45
45
exit " $1 "
@@ -55,7 +55,7 @@ aborting() {
55
55
56
56
# parse command line arguments
57
57
# 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
59
59
echo " Terminating..." >&2
60
60
exit 1
61
61
fi
@@ -64,51 +64,67 @@ eval set -- "$options"
64
64
65
65
while true ; do
66
66
case " $1 " in
67
- -h | --help | - \? )
67
+ -h | -\? )
68
68
usage 0
69
69
;;
70
- -i | --interface )
70
+ -i)
71
71
INTERFACE=$( echo " $2 " | tr ' [:upper:]' ' [:lower:]' )
72
72
echo " Selected interface: $INTERFACE "
73
73
shift 2
74
74
;;
75
- -e | --erase )
75
+ -e)
76
76
ERASE=" --erase all"
77
77
shift 1
78
78
;;
79
- -f | --file )
79
+ -f)
80
80
FILEPATH=$2
81
81
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
82
94
;;
83
- -o | --offset )
95
+ -o)
84
96
OFFSET=$2
85
97
ADDRESS=$( printf " 0x%x" $(( ADDRESS + OFFSET)) )
86
98
shift 2
87
99
;;
88
- -c | --com )
100
+ -c)
89
101
PORT=$2
90
102
shift 2
91
103
;;
92
- -r | --rts )
104
+ -r)
93
105
RTS=$( echo " rts=$2 " | tr ' [:upper:]' ' [:lower:]' )
94
106
shift 2
95
107
;;
96
- -d | --dtr )
108
+ -d)
97
109
DTR=$( echo " dtr=$2 " | tr ' [:upper:]' ' [:lower:]' )
98
110
shift 2
99
111
;;
100
- -v | --vid )
112
+ -v)
101
113
VID=$2
102
114
shift 2
103
115
;;
104
- -p | --pid )
116
+ -p)
105
117
PID=$2
106
118
shift 2
107
119
;;
108
120
--)
109
121
shift
110
122
break
111
123
;;
124
+ * )
125
+ echo " Unknown option $1 "
126
+ usage 1
127
+ ;;
112
128
esac
113
129
done
114
130
# Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu
0 commit comments