Skip to content

Commit 1e68c09

Browse files
authored
Merge pull request #90 from fpistm/upload_offset
feat(stm32CubeProg): add offset option
2 parents b1c2d2c + c9b5343 commit 1e68c09

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

Diff for: stm32CubeProg.sh

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh -
22
set -o nounset # Treat unset variables as an error
3+
# set -o xtrace # Print command traces before executing command.
34

45
STM32CP_CLI=
56
ADDRESS=0x8000000
@@ -13,7 +14,7 @@ OPTS=""
1314
usage() {
1415
echo "############################################################"
1516
echo "##"
16-
echo "## $(basename "$0") <protocol> <file_path> [OPTIONS]"
17+
echo "## $(basename "$0") <protocol> <file_path> <offset> [OPTIONS]"
1718
echo "##"
1819
echo "## protocol:"
1920
echo "## 0: SWD"
@@ -22,16 +23,15 @@ usage() {
2223
echo "## Note: prefix it by 1 to erase all sectors."
2324
echo "## Ex: 10 erase all sectors using SWD interface."
2425
echo "## file_path: file path name to be downloaded: (bin, hex)"
26+
echo "## offset: offset to add to $ADDRESS"
2527
echo "## Options:"
2628
echo "## For SWD and DFU: no mandatory options"
2729
echo "## For Serial: <com_port>"
2830
echo "## com_port: serial identifier (mandatory). Ex: /dev/ttyS0 or COM1"
2931
echo "##"
3032
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"
3535
echo "############################################################"
3636
exit "$1"
3737
}
@@ -40,13 +40,13 @@ UNAME_OS="$(uname -s)"
4040
case "${UNAME_OS}" in
4141
Linux*)
4242
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
4444
export PATH="$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin":"$PATH"
4545
fi
46-
if ! command -v $STM32CP_CLI >/dev/null 2>&1; then
46+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
4747
export PATH="/opt/stm32cubeprog/bin":"$PATH"
4848
fi
49-
if ! command -v $STM32CP_CLI >/dev/null 2>&1; then
49+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
5050
echo "STM32CubeProgrammer not found ($STM32CP_CLI)."
5151
echo "Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
5252
echo "https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -56,10 +56,10 @@ case "${UNAME_OS}" in
5656
;;
5757
Darwin*)
5858
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
6060
export PATH="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin":"$PATH"
6161
fi
62-
if ! command -v $STM32CP_CLI >/dev/null 2>&1; then
62+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
6363
echo "STM32CubeProgrammer not found ($STM32CP_CLI)."
6464
echo "Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
6565
echo "https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -69,7 +69,7 @@ case "${UNAME_OS}" in
6969
;;
7070
Windows*)
7171
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
7373
if [ -n "${PROGRAMFILES+x}" ]; then
7474
STM32CP86=${PROGRAMFILES}/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
7575
export PATH="${STM32CP86}":"$PATH"
@@ -78,7 +78,7 @@ case "${UNAME_OS}" in
7878
STM32CP=${PROGRAMW6432}/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
7979
export PATH="${STM32CP}":"$PATH"
8080
fi
81-
if ! command -v $STM32CP_CLI >/dev/null 2>&1; then
81+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
8282
echo "STM32CubeProgrammer not found ($STM32CP_CLI)."
8383
echo "Please install it or add '<STM32CubeProgrammer path>\bin' to your PATH environment:"
8484
echo "https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -92,14 +92,17 @@ case "${UNAME_OS}" in
9292
;;
9393
esac
9494

95-
if [ $# -lt 2 ]; then
95+
if [ $# -lt 3 ]; then
9696
echo "Not enough arguments!"
9797
usage 2
9898
fi
9999

100100
# Parse options
101101
PROTOCOL=$1
102102
FILEPATH=$2
103+
OFFSET=$3
104+
ADDRESS=$(printf "0x%x" $((ADDRESS + OFFSET)))
105+
103106
# Protocol $1
104107
# 1x: Erase all sectors
105108
if [ "$1" -ge 10 ]; then
@@ -114,19 +117,19 @@ case $PROTOCOL in
114117
0)
115118
PORT="SWD"
116119
MODE="mode=UR"
117-
shift 2
120+
shift 3
118121
;;
119122
1)
120-
if [ $# -lt 3 ]; then
123+
if [ $# -lt 4 ]; then
121124
usage 3
122125
else
123-
PORT=$3
124-
shift 3
126+
PORT=$4
127+
shift 4
125128
fi
126129
;;
127130
2)
128131
PORT="USB1"
129-
shift 2
132+
shift 3
130133
;;
131134
*)
132135
echo "Protocol unknown!"
@@ -138,6 +141,6 @@ if [ $# -gt 0 ]; then
138141
OPTS="$*"
139142
fi
140143

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}"
142145

143146
exit $?

0 commit comments

Comments
 (0)