[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 <frederic.pillon@st.com>
This commit is contained in:
Frederic.Pillon 2019-05-24 15:24:57 +02:00
parent e167f91814
commit ce5b68d456
3 changed files with 48 additions and 17 deletions

View file

@ -3,7 +3,7 @@ set -o nounset # Treat unset variables as an error
#set -x #set -x
STM32CP_CLI=STM32_Programmer.sh STM32CP_CLI=STM32_Programmer.sh
ADDRESS=0x8000000 ADDRESS=0x8000000
FILEPATH= ERASE=
MODE= MODE=
PORT= PORT=
OPTS= OPTS=
@ -16,10 +16,12 @@ usage()
echo "##" echo "##"
echo "## `basename $0` <protocol> <file_path> [OPTIONS]" echo "## `basename $0` <protocol> <file_path> [OPTIONS]"
echo "##" echo "##"
echo "## protocol: " echo "## protocol:"
echo "## 0: SWD" echo "## 0: SWD"
echo "## 1: Serial " echo "## 1: Serial"
echo "## 2: DFU" echo "## 2: DFU"
echo "## Note: prefix it by 1 to erase all sectors."
echo "## Ex: 10 erase all sectors using SWD interface."
echo "## file_path: file path name to be downloaded: (bin, hex)" echo "## file_path: file path name to be downloaded: (bin, hex)"
echo "## Options:" echo "## Options:"
echo "## For SWD and DFU: no mandatory options" echo "## For SWD and DFU: no mandatory options"
@ -58,14 +60,20 @@ if [ $# -lt 2 ]; then
usage 2 usage 2
fi fi
FILEPATH=$2
# Parse options # Parse options
PROTOCOL=$1
FILEPATH=$2
# Protocol $1
# 1x: Erase all sectors
if [ $1 -ge 10 ]; then
ERASE='-e all'
PROTOCOL=$(($1 - 10))
fi
# Protocol $1 # Protocol $1
# 0: SWD # 0: SWD
# 1: Serial # 1: Serial
# 2: DFU # 2: DFU
case $1 in case $PROTOCOL in
0) 0)
PORT='SWD' PORT='SWD'
MODE='mode=UR' MODE='mode=UR'
@ -89,7 +97,7 @@ if [ $# -gt 0 ]; then
OPTS="$@" OPTS="$@"
fi fi
${STM32CP_CLI} -c port=${PORT} ${MODE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS} ${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
exit 0 exit 0

View file

@ -2,7 +2,7 @@
set -o nounset # Treat unset variables as an error set -o nounset # Treat unset variables as an error
STM32CP_CLI=STM32_Programmer_CLI STM32CP_CLI=STM32_Programmer_CLI
ADDRESS=0x8000000 ADDRESS=0x8000000
FILEPATH= ERASE=
MODE= MODE=
PORT= PORT=
OPTS= OPTS=
@ -17,8 +17,10 @@ usage()
echo "##" echo "##"
echo "## protocol: " echo "## protocol: "
echo "## 0: SWD" echo "## 0: SWD"
echo "## 1: Serial " echo "## 1: Serial"
echo "## 2: DFU" echo "## 2: DFU"
echo "## Note: prefix it by 1 to erase all sectors."
echo "## Ex: 10 erase all sectors using SWD interface."
echo "## file_path: file path name to be downloaded: (bin, hex)" echo "## file_path: file path name to be downloaded: (bin, hex)"
echo "## Options:" echo "## Options:"
echo "## For SWD and DFU: no mandatory options" echo "## For SWD and DFU: no mandatory options"
@ -57,14 +59,21 @@ if [ $# -lt 2 ]; then
usage 2 usage 2
fi fi
FILEPATH=$2
# Parse options # Parse options
PROTOCOL=$1
FILEPATH=$2
# Protocol $1
# 1x: Erase all sectors
if [ $1 -ge 10 ]; then
ERASE='-e all'
PROTOCOL=$(($1 - 10))
fi
# Protocol $1 # Protocol $1
# 0: SWD # 0: SWD
# 1: Serial # 1: Serial
# 2: DFU # 2: DFU
case $1 in case $PROTOCOL in
0) 0)
PORT='SWD' PORT='SWD'
MODE='mode=UR' MODE='mode=UR'
@ -88,7 +97,7 @@ if [ $# -gt 0 ]; then
OPTS="$@" OPTS="$@"
fi fi
${STM32CP_CLI} -c port=${PORT} ${MODE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS} ${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
exit 0 exit 0

View file

@ -3,6 +3,10 @@
set ERROR=0 set ERROR=0
set STM32CP_CLI=STM32_Programmer_CLI.exe set STM32CP_CLI=STM32_Programmer_CLI.exe
set ADDRESS=0x8000000 set ADDRESS=0x8000000
set ERASE=
set MODE=
set PORT=
set OPTS=
:: Check tool :: Check tool
where /Q %STM32CP_CLI% where /Q %STM32CP_CLI%
@ -23,15 +27,23 @@ exit 1
:: Parse options :: Parse options
if "%~1"=="" echo Not enough arguments! & set ERROR=2 & goto :usage if "%~1"=="" echo Not enough arguments! & set ERROR=2 & goto :usage
if "%~2"=="" echo Not enough arguments! & set ERROR=2 & goto :usage if "%~2"=="" echo Not enough arguments! & set ERROR=2 & goto :usage
set PROTOCOL=%~1
set FILEPATH=%~2 set FILEPATH=%~2
:: Protocol :: Protocol
:: 1x: Erase all sectors
if %~1 lss 10 goto :proto
set ERASE=-e all
set /a PROTOCOL-=10
:: 0: SWD :: 0: SWD
:: 1: Serial :: 1: Serial
:: 2: DFU :: 2: DFU
if %~1==0 goto :SWD :proto
if %~1==1 goto :SERIAL if %PROTOCOL%==0 goto :SWD
if %~1==2 goto :DFU if %PROTOCOL%==1 goto :SERIAL
if %PROTOCOL%==2 goto :DFU
echo Protocol unknown! echo Protocol unknown!
set ERROR=4 set ERROR=4
goto :usage goto :usage
@ -59,7 +71,7 @@ set OPTS=%1 %2 %3 %4 %5 %6 %7 %8 %9
goto :prog goto :prog
:prog :prog
%STM32CP_CLI% -c port=%PORT% %MODE% -q -d %FILEPATH% %ADDRESS% %OPTS% %STM32CP_CLI% -c port=%PORT% %MODE% %ERASE% -q -d %FILEPATH% %ADDRESS% %OPTS%
exit 0 exit 0
:usage :usage
@ -69,6 +81,8 @@ exit 0
echo 0: SWD echo 0: SWD
echo 1: Serial echo 1: Serial
echo 2: DFU echo 2: DFU
echo Note: prefix it by 1 to erase all sectors
echo Ex: 10 erase all sectors using SWD interface
echo file_path: file path name to be downloaded: (bin, hex) echo file_path: file path name to be downloaded: (bin, hex)
echo Options: echo Options:
echo For SWD and DFU: no mandatory options echo For SWD and DFU: no mandatory options