1
1
#! /bin/sh -
2
2
set -o nounset # Treat unset variables as an error
3
+ # set -o xtrace # Print command traces before executing command.
3
4
4
5
STM32CP_CLI=
5
6
ADDRESS=0x8000000
@@ -13,7 +14,7 @@ OPTS=""
13
14
usage () {
14
15
echo " ############################################################"
15
16
echo " ##"
16
- echo " ## $( basename " $0 " ) <protocol> <file_path> [OPTIONS]"
17
+ echo " ## $( basename " $0 " ) <protocol> <file_path> <offset> [OPTIONS]"
17
18
echo " ##"
18
19
echo " ## protocol:"
19
20
echo " ## 0: SWD"
@@ -22,16 +23,15 @@ usage() {
22
23
echo " ## Note: prefix it by 1 to erase all sectors."
23
24
echo " ## Ex: 10 erase all sectors using SWD interface."
24
25
echo " ## file_path: file path name to be downloaded: (bin, hex)"
26
+ echo " ## offset: offset to add to $ADDRESS "
25
27
echo " ## Options:"
26
28
echo " ## For SWD and DFU: no mandatory options"
27
29
echo " ## For Serial: <com_port>"
28
30
echo " ## com_port: serial identifier (mandatory). Ex: /dev/ttyS0 or COM1"
29
31
echo " ##"
30
32
echo " ## Note: all trailing arguments will be passed to the $STM32CP_CLI "
31
- echo " ## They have to be valid commands for STM32 MCU"
32
- echo " ## Ex: -g: Run the code at the specified address"
33
- echo " ## -rst: Reset system"
34
- echo " ## -s: start automatically (optional)"
33
+ echo " ## They have to be valid commands for STM32CubeProgrammer cli"
34
+ echo " ## Ex: -rst: Reset system"
35
35
echo " ############################################################"
36
36
exit " $1 "
37
37
}
@@ -40,13 +40,13 @@ UNAME_OS="$(uname -s)"
40
40
case " ${UNAME_OS} " in
41
41
Linux* )
42
42
STM32CP_CLI=STM32_Programmer.sh
43
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
43
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
44
44
export PATH=" $HOME /STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin" :" $PATH "
45
45
fi
46
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
46
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
47
47
export PATH=" /opt/stm32cubeprog/bin" :" $PATH "
48
48
fi
49
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
49
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
50
50
echo " STM32CubeProgrammer not found ($STM32CP_CLI )."
51
51
echo " Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
52
52
echo " https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -56,10 +56,10 @@ case "${UNAME_OS}" in
56
56
;;
57
57
Darwin* )
58
58
STM32CP_CLI=STM32_Programmer_CLI
59
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
59
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
60
60
export PATH=" /Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin" :" $PATH "
61
61
fi
62
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
62
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
63
63
echo " STM32CubeProgrammer not found ($STM32CP_CLI )."
64
64
echo " Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
65
65
echo " https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -69,7 +69,7 @@ case "${UNAME_OS}" in
69
69
;;
70
70
Windows* )
71
71
STM32CP_CLI=STM32_Programmer_CLI.exe
72
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
72
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
73
73
if [ -n " ${PROGRAMFILES+x} " ]; then
74
74
STM32CP86=${PROGRAMFILES} /STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
75
75
export PATH=" ${STM32CP86} " :" $PATH "
@@ -78,7 +78,7 @@ case "${UNAME_OS}" in
78
78
STM32CP=${PROGRAMW6432} /STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
79
79
export PATH=" ${STM32CP} " :" $PATH "
80
80
fi
81
- if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
81
+ if ! command -v $STM32CP_CLI > /dev/null 2>&1 ; then
82
82
echo " STM32CubeProgrammer not found ($STM32CP_CLI )."
83
83
echo " Please install it or add '<STM32CubeProgrammer path>\bin' to your PATH environment:"
84
84
echo " https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -92,14 +92,17 @@ case "${UNAME_OS}" in
92
92
;;
93
93
esac
94
94
95
- if [ $# -lt 2 ]; then
95
+ if [ $# -lt 3 ]; then
96
96
echo " Not enough arguments!"
97
97
usage 2
98
98
fi
99
99
100
100
# Parse options
101
101
PROTOCOL=$1
102
102
FILEPATH=$2
103
+ OFFSET=$3
104
+ ADDRESS=$( printf " 0x%x" $(( ADDRESS + OFFSET)) )
105
+
103
106
# Protocol $1
104
107
# 1x: Erase all sectors
105
108
if [ " $1 " -ge 10 ]; then
@@ -114,19 +117,19 @@ case $PROTOCOL in
114
117
0)
115
118
PORT=" SWD"
116
119
MODE=" mode=UR"
117
- shift 2
120
+ shift 3
118
121
;;
119
122
1)
120
- if [ $# -lt 3 ]; then
123
+ if [ $# -lt 4 ]; then
121
124
usage 3
122
125
else
123
- PORT=$3
124
- shift 3
126
+ PORT=$4
127
+ shift 4
125
128
fi
126
129
;;
127
130
2)
128
131
PORT=" USB1"
129
- shift 2
132
+ shift 3
130
133
;;
131
134
* )
132
135
echo " Protocol unknown!"
@@ -138,6 +141,6 @@ if [ $# -gt 0 ]; then
138
141
OPTS=" $* "
139
142
fi
140
143
141
- ${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE: +" -e all" } -q -d " ${FILEPATH} " ${ADDRESS} " ${OPTS} "
144
+ ${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE: +" -e all" } -q -d " ${FILEPATH} " " ${ADDRESS} " -s " ${ADDRESS} " " ${OPTS} "
142
145
143
146
exit $?
0 commit comments