2
2
set -o nounset # Treat unset variables as an error
3
3
# set -o xtrace # Print command traces before executing command.
4
4
5
+ UNAME_OS=" $( uname -s) "
5
6
STM32CP_CLI=
6
7
INTERFACE=
7
8
PORT=
@@ -23,23 +24,23 @@ usage() {
23
24
echo " Usage: $( basename " $0 " ) [OPTIONS]...
24
25
25
26
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
27
+ -i <'swd'/'dfu'/'serial'> interface identifier: 'swd', 'dfu' or 'serial'
28
+ -f <path> file path to be downloaded: bin or hex
28
29
Optional options:
29
- -e, --erase erase all sectors before flashing
30
- -o, --offset <hex value> offset from flash base ($ADDRESS ) where flashing should start
30
+ -e
31
+ -o <hex value> offset from flash base ($ADDRESS ) where flashing should start
31
32
32
33
Specific options for Serial protocol:
33
34
Mandatory:
34
- -c, --com <name> serial identifier, ex: COM1 or /dev/ttyS0,...
35
+ -c <name> serial identifier, ex: COM1 or /dev/ttyS0,...
35
36
Optional:
36
- -r, --rts <low/high> polarity of RTS signal ('low' by default)
37
- -d, --dtr <low/high> polarity of DTR signal
37
+ -r <low/high> polarity of RTS signal ('low' by default)
38
+ -d <low/high> polarity of DTR signal
38
39
39
40
Specific options for DFU protocol:
40
41
Mandatory:
41
- -v, --vid <hex value> vendor id, ex: 0x0483
42
- -p, --pid <hex value> product id, ex: 0xdf11
42
+ -v <hex value> vendor id, ex: 0x0483
43
+ -p <hex value> product id, ex: 0xdf11
43
44
44
45
" >&2
45
46
exit " $1 "
@@ -55,64 +56,76 @@ aborting() {
55
56
56
57
# parse command line arguments
57
58
# 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
59
- echo " Terminating..." >&2
60
- exit 1
61
- fi
62
-
59
+ case " ${UNAME_OS} " in
60
+ Darwin* )
61
+ if ! options=$( getopt hi:ef:o:c:r:d:v:p: " $@ " ) ; then
62
+ echo " Terminating..." >&2
63
+ exit 1
64
+ fi
65
+ ;;
66
+ * )
67
+ if ! options=$( getopt -o hi:ef:o:c:r:d:v:p: -- " $@ " ) ; then
68
+ echo " Terminating..." >&2
69
+ exit 1
70
+ fi
71
+ ;;
72
+ esac
63
73
eval set -- " $options "
64
74
65
75
while true ; do
66
76
case " $1 " in
67
- -h | --help | - \? )
77
+ -h | -\? )
68
78
usage 0
69
79
;;
70
- -i | --interface )
80
+ -i)
71
81
INTERFACE=$( echo " $2 " | tr ' [:upper:]' ' [:lower:]' )
72
82
echo " Selected interface: $INTERFACE "
73
83
shift 2
74
84
;;
75
- -e | --erase )
85
+ -e)
76
86
ERASE=" --erase all"
77
87
shift 1
78
88
;;
79
- -f | --file )
89
+ -f)
80
90
FILEPATH=$2
81
91
shift 2
82
92
;;
83
- -o | --offset )
93
+ -o)
84
94
OFFSET=$2
85
95
ADDRESS=$( printf " 0x%x" $(( ADDRESS + OFFSET)) )
86
96
shift 2
87
97
;;
88
- -c | --com )
98
+ -c)
89
99
PORT=$2
90
100
shift 2
91
101
;;
92
- -r | --rts )
102
+ -r)
93
103
RTS=$( echo " rts=$2 " | tr ' [:upper:]' ' [:lower:]' )
94
104
shift 2
95
105
;;
96
- -d | --dtr )
106
+ -d)
97
107
DTR=$( echo " dtr=$2 " | tr ' [:upper:]' ' [:lower:]' )
98
108
shift 2
99
109
;;
100
- -v | --vid )
110
+ -v)
101
111
VID=$2
102
112
shift 2
103
113
;;
104
- -p | --pid )
114
+ -p)
105
115
PID=$2
106
116
shift 2
107
117
;;
108
118
--)
109
119
shift
110
120
break
111
121
;;
122
+ * )
123
+ echo " Unknown option $1 "
124
+ usage 1
125
+ ;;
112
126
esac
113
127
done
114
- # Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu
115
- UNAME_OS=" $( uname -s) "
128
+ # Check STM32CubeProgrammer cli availability
116
129
case " ${UNAME_OS} " in
117
130
Linux* )
118
131
STM32CP_CLI=STM32_Programmer.sh
0 commit comments