Skip to content

Commit ce5b68d

Browse files
committed
[STM32CubeProg] Add option to erase all sectors
For example adding a platform.local.txt with: tools.stm32CubeProg.upload.pattern="{path}/{cmd}" 1{upload.protocol} "{build.path}/{build.project_name}.bin" {upload.options} will allow to erase all sectors before download. Signed-off-by: Frederic.Pillon <[email protected]>
1 parent e167f91 commit ce5b68d

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

linux/stm32CubeProg.sh

+15-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -o nounset # Treat unset variables as an error
33
#set -x
44
STM32CP_CLI=STM32_Programmer.sh
55
ADDRESS=0x8000000
6-
FILEPATH=
6+
ERASE=
77
MODE=
88
PORT=
99
OPTS=
@@ -16,10 +16,12 @@ usage()
1616
echo "##"
1717
echo "## `basename $0` <protocol> <file_path> [OPTIONS]"
1818
echo "##"
19-
echo "## protocol: "
19+
echo "## protocol:"
2020
echo "## 0: SWD"
21-
echo "## 1: Serial "
21+
echo "## 1: Serial"
2222
echo "## 2: DFU"
23+
echo "## Note: prefix it by 1 to erase all sectors."
24+
echo "## Ex: 10 erase all sectors using SWD interface."
2325
echo "## file_path: file path name to be downloaded: (bin, hex)"
2426
echo "## Options:"
2527
echo "## For SWD and DFU: no mandatory options"
@@ -58,14 +60,20 @@ if [ $# -lt 2 ]; then
5860
usage 2
5961
fi
6062

61-
FILEPATH=$2
62-
6363
# Parse options
64+
PROTOCOL=$1
65+
FILEPATH=$2
66+
# Protocol $1
67+
# 1x: Erase all sectors
68+
if [ $1 -ge 10 ]; then
69+
ERASE='-e all'
70+
PROTOCOL=$(($1 - 10))
71+
fi
6472
# Protocol $1
6573
# 0: SWD
6674
# 1: Serial
6775
# 2: DFU
68-
case $1 in
76+
case $PROTOCOL in
6977
0)
7078
PORT='SWD'
7179
MODE='mode=UR'
@@ -89,7 +97,7 @@ if [ $# -gt 0 ]; then
8997
OPTS="$@"
9098
fi
9199

92-
${STM32CP_CLI} -c port=${PORT} ${MODE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
100+
${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
93101

94102
exit 0
95103

macosx/stm32CubeProg

+15-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -o nounset # Treat unset variables as an error
33
STM32CP_CLI=STM32_Programmer_CLI
44
ADDRESS=0x8000000
5-
FILEPATH=
5+
ERASE=
66
MODE=
77
PORT=
88
OPTS=
@@ -17,8 +17,10 @@ usage()
1717
echo "##"
1818
echo "## protocol: "
1919
echo "## 0: SWD"
20-
echo "## 1: Serial "
20+
echo "## 1: Serial"
2121
echo "## 2: DFU"
22+
echo "## Note: prefix it by 1 to erase all sectors."
23+
echo "## Ex: 10 erase all sectors using SWD interface."
2224
echo "## file_path: file path name to be downloaded: (bin, hex)"
2325
echo "## Options:"
2426
echo "## For SWD and DFU: no mandatory options"
@@ -57,14 +59,21 @@ if [ $# -lt 2 ]; then
5759
usage 2
5860
fi
5961

60-
FILEPATH=$2
61-
6262
# Parse options
63+
PROTOCOL=$1
64+
FILEPATH=$2
65+
# Protocol $1
66+
# 1x: Erase all sectors
67+
if [ $1 -ge 10 ]; then
68+
ERASE='-e all'
69+
PROTOCOL=$(($1 - 10))
70+
fi
6371
# Protocol $1
6472
# 0: SWD
6573
# 1: Serial
6674
# 2: DFU
67-
case $1 in
75+
case $PROTOCOL in
76+
6877
0)
6978
PORT='SWD'
7079
MODE='mode=UR'
@@ -88,7 +97,7 @@ if [ $# -gt 0 ]; then
8897
OPTS="$@"
8998
fi
9099

91-
${STM32CP_CLI} -c port=${PORT} ${MODE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
100+
${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
92101

93102
exit 0
94103

win/stm32CubeProg.bat

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
set ERROR=0
44
set STM32CP_CLI=STM32_Programmer_CLI.exe
55
set ADDRESS=0x8000000
6+
set ERASE=
7+
set MODE=
8+
set PORT=
9+
set OPTS=
610

711
:: Check tool
812
where /Q %STM32CP_CLI%
@@ -23,15 +27,23 @@ exit 1
2327
:: Parse options
2428
if "%~1"=="" echo Not enough arguments! & set ERROR=2 & goto :usage
2529
if "%~2"=="" echo Not enough arguments! & set ERROR=2 & goto :usage
30+
31+
set PROTOCOL=%~1
2632
set FILEPATH=%~2
2733

2834
:: Protocol
35+
:: 1x: Erase all sectors
36+
if %~1 lss 10 goto :proto
37+
set ERASE=-e all
38+
set /a PROTOCOL-=10
39+
2940
:: 0: SWD
3041
:: 1: Serial
3142
:: 2: DFU
32-
if %~1==0 goto :SWD
33-
if %~1==1 goto :SERIAL
34-
if %~1==2 goto :DFU
43+
:proto
44+
if %PROTOCOL%==0 goto :SWD
45+
if %PROTOCOL%==1 goto :SERIAL
46+
if %PROTOCOL%==2 goto :DFU
3547
echo Protocol unknown!
3648
set ERROR=4
3749
goto :usage
@@ -59,7 +71,7 @@ set OPTS=%1 %2 %3 %4 %5 %6 %7 %8 %9
5971
goto :prog
6072

6173
:prog
62-
%STM32CP_CLI% -c port=%PORT% %MODE% -q -d %FILEPATH% %ADDRESS% %OPTS%
74+
%STM32CP_CLI% -c port=%PORT% %MODE% %ERASE% -q -d %FILEPATH% %ADDRESS% %OPTS%
6375
exit 0
6476

6577
:usage
@@ -69,6 +81,8 @@ exit 0
6981
echo 0: SWD
7082
echo 1: Serial
7183
echo 2: DFU
84+
echo Note: prefix it by 1 to erase all sectors
85+
echo Ex: 10 erase all sectors using SWD interface
7286
echo file_path: file path name to be downloaded: (bin, hex)
7387
echo Options:
7488
echo For SWD and DFU: no mandatory options

0 commit comments

Comments
 (0)