Skip to content

Commit 00caaeb

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 00caaeb

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

linux/stm32CubeProg.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ set -o nounset # Treat unset variables as an error
33
#set -x
44
STM32CP_CLI=STM32_Programmer.sh
55
ADDRESS=0x8000000
6-
FILEPATH=
76
MODE=
87
PORT=
98
OPTS=
@@ -16,10 +15,12 @@ usage()
1615
echo "##"
1716
echo "## `basename $0` <protocol> <file_path> [OPTIONS]"
1817
echo "##"
19-
echo "## protocol: "
18+
echo "## protocol:"
2019
echo "## 0: SWD"
21-
echo "## 1: Serial "
20+
echo "## 1: Serial"
2221
echo "## 2: DFU"
22+
echo "## Note: prefix it by 1 to erase all sectors."
23+
echo "## Ex: 10 erase all sectors using SWD interface."
2324
echo "## file_path: file path name to be downloaded: (bin, hex)"
2425
echo "## Options:"
2526
echo "## For SWD and DFU: no mandatory options"
@@ -58,14 +59,20 @@ if [ $# -lt 2 ]; then
5859
usage 2
5960
fi
6061

61-
FILEPATH=$2
62-
6362
# 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
6471
# Protocol $1
6572
# 0: SWD
6673
# 1: Serial
6774
# 2: DFU
68-
case $1 in
75+
case $PROTOCOL in
6976
0)
7077
PORT='SWD'
7178
MODE='mode=UR'
@@ -89,7 +96,7 @@ if [ $# -gt 0 ]; then
8996
OPTS="$@"
9097
fi
9198

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

94101
exit 0
95102

macosx/stm32CubeProg

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
set -o nounset # Treat unset variables as an error
33
STM32CP_CLI=STM32_Programmer_CLI
44
ADDRESS=0x8000000
5-
FILEPATH=
65
MODE=
76
PORT=
87
OPTS=
@@ -17,8 +16,10 @@ usage()
1716
echo "##"
1817
echo "## protocol: "
1918
echo "## 0: SWD"
20-
echo "## 1: Serial "
19+
echo "## 1: Serial"
2120
echo "## 2: DFU"
21+
echo "## Note: prefix it by 1 to erase all sectors."
22+
echo "## Ex: 10 erase all sectors using SWD interface."
2223
echo "## file_path: file path name to be downloaded: (bin, hex)"
2324
echo "## Options:"
2425
echo "## For SWD and DFU: no mandatory options"
@@ -57,14 +58,21 @@ if [ $# -lt 2 ]; then
5758
usage 2
5859
fi
5960

60-
FILEPATH=$2
61-
6261
# Parse options
62+
PROTOCOL=$1
63+
FILEPATH=$2
64+
# Protocol $1
65+
# 1x: Erase all sectors
66+
if [ $1 -ge 10 ]; then
67+
ERASE='-e all'
68+
PROTOCOL=$(($1 - 10))
69+
fi
6370
# Protocol $1
6471
# 0: SWD
6572
# 1: Serial
6673
# 2: DFU
67-
case $1 in
74+
case $PROTOCOL in
75+
6876
0)
6977
PORT='SWD'
7078
MODE='mode=UR'
@@ -88,7 +96,7 @@ if [ $# -gt 0 ]; then
8896
OPTS="$@"
8997
fi
9098

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

93101
exit 0
94102

win/stm32CubeProg.bat

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@ exit 1
2323
:: Parse options
2424
if "%~1"=="" echo Not enough arguments! & set ERROR=2 & goto :usage
2525
if "%~2"=="" echo Not enough arguments! & set ERROR=2 & goto :usage
26+
27+
set PROTOCOL=%~1
2628
set FILEPATH=%~2
2729

2830
:: Protocol
31+
:: 1x: Erase all sectors
32+
if %~1 lss 10 goto :proto
33+
set ERASE=-e all
34+
set /a PROTOCOL-=10
35+
2936
:: 0: SWD
3037
:: 1: Serial
3138
:: 2: DFU
32-
if %~1==0 goto :SWD
33-
if %~1==1 goto :SERIAL
34-
if %~1==2 goto :DFU
39+
:proto
40+
if %PROTOCOL%==0 goto :SWD
41+
if %PROTOCOL%==1 goto :SERIAL
42+
if %PROTOCOL%==2 goto :DFU
3543
echo Protocol unknown!
3644
set ERROR=4
3745
goto :usage
@@ -59,7 +67,7 @@ set OPTS=%1 %2 %3 %4 %5 %6 %7 %8 %9
5967
goto :prog
6068

6169
:prog
62-
%STM32CP_CLI% -c port=%PORT% %MODE% -q -d %FILEPATH% %ADDRESS% %OPTS%
70+
%STM32CP_CLI% -c port=%PORT% %MODE% %ERASE% -q -d %FILEPATH% %ADDRESS% %OPTS%
6371
exit 0
6472

6573
:usage
@@ -69,6 +77,8 @@ exit 0
6977
echo 0: SWD
7078
echo 1: Serial
7179
echo 2: DFU
80+
echo Note: prefix it by 1 to erase all sectors
81+
echo Ex: 10 erase all sectors using SWD interface
7282
echo file_path: file path name to be downloaded: (bin, hex)
7383
echo Options:
7484
echo For SWD and DFU: no mandatory options

0 commit comments

Comments
 (0)