diff --git a/linux/stm32CubeProg.sh b/linux/stm32CubeProg.sh index 885776c1..1d2adeac 100755 --- a/linux/stm32CubeProg.sh +++ b/linux/stm32CubeProg.sh @@ -3,7 +3,7 @@ set -o nounset # Treat unset variables as an error #set -x STM32CP_CLI=STM32_Programmer.sh ADDRESS=0x8000000 -FILEPATH= +ERASE= MODE= PORT= OPTS= @@ -16,10 +16,12 @@ usage() echo "##" echo "## `basename $0` [OPTIONS]" echo "##" - echo "## protocol: " + echo "## protocol:" echo "## 0: SWD" - echo "## 1: Serial " + echo "## 1: Serial" 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 "## Options:" echo "## For SWD and DFU: no mandatory options" @@ -58,14 +60,20 @@ if [ $# -lt 2 ]; then usage 2 fi -FILEPATH=$2 - # 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 # 0: SWD # 1: Serial # 2: DFU -case $1 in +case $PROTOCOL in 0) PORT='SWD' MODE='mode=UR' @@ -89,7 +97,7 @@ if [ $# -gt 0 ]; then OPTS="$@" 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 diff --git a/macosx/stm32CubeProg b/macosx/stm32CubeProg index af486f1d..4dda68c1 100755 --- a/macosx/stm32CubeProg +++ b/macosx/stm32CubeProg @@ -2,7 +2,7 @@ set -o nounset # Treat unset variables as an error STM32CP_CLI=STM32_Programmer_CLI ADDRESS=0x8000000 -FILEPATH= +ERASE= MODE= PORT= OPTS= @@ -17,8 +17,10 @@ usage() echo "##" echo "## protocol: " echo "## 0: SWD" - echo "## 1: Serial " + echo "## 1: Serial" 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 "## Options:" echo "## For SWD and DFU: no mandatory options" @@ -57,14 +59,21 @@ if [ $# -lt 2 ]; then usage 2 fi -FILEPATH=$2 - # 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 # 0: SWD # 1: Serial # 2: DFU -case $1 in +case $PROTOCOL in + 0) PORT='SWD' MODE='mode=UR' @@ -88,7 +97,7 @@ if [ $# -gt 0 ]; then OPTS="$@" 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 diff --git a/win/stm32CubeProg.bat b/win/stm32CubeProg.bat index 86bba57c..ef892ead 100644 --- a/win/stm32CubeProg.bat +++ b/win/stm32CubeProg.bat @@ -3,6 +3,10 @@ set ERROR=0 set STM32CP_CLI=STM32_Programmer_CLI.exe set ADDRESS=0x8000000 +set ERASE= +set MODE= +set PORT= +set OPTS= :: Check tool where /Q %STM32CP_CLI% @@ -23,15 +27,23 @@ exit 1 :: Parse options if "%~1"=="" 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 :: Protocol +:: 1x: Erase all sectors +if %~1 lss 10 goto :proto +set ERASE=-e all +set /a PROTOCOL-=10 + :: 0: SWD :: 1: Serial :: 2: DFU -if %~1==0 goto :SWD -if %~1==1 goto :SERIAL -if %~1==2 goto :DFU +:proto +if %PROTOCOL%==0 goto :SWD +if %PROTOCOL%==1 goto :SERIAL +if %PROTOCOL%==2 goto :DFU echo Protocol unknown! set ERROR=4 goto :usage @@ -59,7 +71,7 @@ set OPTS=%1 %2 %3 %4 %5 %6 %7 %8 %9 goto :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 :usage @@ -69,6 +81,8 @@ exit 0 echo 0: SWD echo 1: Serial 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 Options: echo For SWD and DFU: no mandatory options