File tree Expand file tree Collapse file tree 3 files changed +266
-0
lines changed Expand file tree Collapse file tree 3 files changed +266
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -o nounset # Treat unset variables as an error
3
+ # set -x
4
+ STM32CP_CLI=STM32_Programmer.sh
5
+ ADDRESS=0x8000000
6
+ FILEPATH=
7
+ MODE=
8
+ PORT=
9
+ OPTS=
10
+
11
+ # ##############################################################################
12
+ # # Help function
13
+ usage ()
14
+ {
15
+ echo " ############################################################"
16
+ echo " ##"
17
+ echo " ## ` basename $0 ` <protocol> <file_path> [OPTIONS]"
18
+ echo " ##"
19
+ echo " ## protocol: "
20
+ echo " ## 0: SWD"
21
+ echo " ## 1: Serial "
22
+ echo " ## 2: DFU"
23
+ echo " ## file_path: file path name to be downloaded: (bin, hex)"
24
+ echo " ## Options:"
25
+ echo " ## For SWD: -rst"
26
+ echo " ## -rst: Reset system (default)"
27
+ echo " ## For Serial: <com_port> -s"
28
+ echo " ## com_port: serial identifier. Ex: /dev/ttyS0"
29
+ echo " ## -s: start automatically"
30
+ echo " ## For DFU: none"
31
+ echo " ############################################################"
32
+ exit $1
33
+ }
34
+
35
+
36
+ check_tool () {
37
+ command -v $STM32CP_CLI > /dev/null 2>&1
38
+ if [ $? != 0 ]; then
39
+ export PATH=" $HOME /STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin" :$PATH
40
+ fi
41
+ command -v $STM32CP_CLI > /dev/null 2>&1
42
+ if [ $? != 0 ]; then
43
+ echo " $STM32CP_CLI not found."
44
+ echo " Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
45
+ echo " https://www.st.com/en/development-tools/stm32cubeprog.html"
46
+ echo " Aborting!"
47
+ exit 1
48
+ fi
49
+ }
50
+
51
+ check_tool
52
+
53
+ if [ $# -lt 2 ]; then
54
+ echo " Not enough arguments!"
55
+ usage 2
56
+ fi
57
+
58
+ FILEPATH=$2
59
+
60
+ # Parse options
61
+ # Protocol $1
62
+ # 0: SWD
63
+ # 1: Serial
64
+ # 2: DFU
65
+ case $1 in
66
+ 0)
67
+ PORT=' SWD'
68
+ MODE=' mode=UR'
69
+ if [ $# -lt 3 ]; then
70
+ OPTS=-rst
71
+ else
72
+ OPTS=$3
73
+ fi ;;
74
+ 1)
75
+ if [ $# -lt 3 ]; then
76
+ usage 3
77
+ else
78
+ PORT=$3
79
+ if [ $# -gt 3 ]; then
80
+ shift 3
81
+ OPTS=" $@ "
82
+ fi
83
+ fi ;;
84
+ 2)
85
+ PORT=' USB1' ;;
86
+ * )
87
+ echo " Protocol unknown!"
88
+ usage 4;;
89
+ esac
90
+
91
+ ${STM32CP_CLI} -c port=${PORT} ${MODE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
92
+
93
+ exit 0
94
+
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -o nounset # Treat unset variables as an error
3
+ STM32CP_CLI=STM32_Programmer_CLI
4
+ ADDRESS=0x8000000
5
+ FILEPATH=
6
+ MODE=
7
+ PORT=
8
+ OPTS=
9
+
10
+ # ##############################################################################
11
+ # # Help function
12
+ usage ()
13
+ {
14
+ echo " ############################################################"
15
+ echo " ##"
16
+ echo " ## ` basename $0 ` <protocol> <file_path> [OPTIONS]"
17
+ echo " ##"
18
+ echo " ## protocol: "
19
+ echo " ## 0: SWD"
20
+ echo " ## 1: Serial "
21
+ echo " ## 2: DFU"
22
+ echo " ## file_path: file path name to be downloaded: (bin, hex)"
23
+ echo " ## Options:"
24
+ echo " ## For SWD: -rst"
25
+ echo " ## -rst: Reset system (default)"
26
+ echo " ## For Serial: <com_port> -s"
27
+ echo " ## com_port: serial identifier. Ex: /dev/ttyS0"
28
+ echo " ## -s: start automatically"
29
+ echo " ## For DFU: none"
30
+ echo " ############################################################"
31
+ exit $1
32
+ }
33
+
34
+
35
+ check_tool () {
36
+ command -v $STM32CP_CLI > /dev/null 2>&1
37
+ if [ $? != 0 ]; then
38
+ export PATH=" /Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin" :$PATH
39
+ fi
40
+ command -v $STM32CP_CLI > /dev/null 2>&1
41
+ if [ $? != 0 ]; then
42
+ echo " $STM32CP_CLI not found."
43
+ echo " Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
44
+ echo " https://www.st.com/en/development-tools/stm32cubeprog.html"
45
+ echo " Aborting!"
46
+ exit 1
47
+ fi
48
+ }
49
+
50
+ check_tool
51
+
52
+ if [ $# -lt 2 ]; then
53
+ echo " Not enough arguments!"
54
+ usage 2
55
+ fi
56
+
57
+ FILEPATH=$2
58
+
59
+ # Parse options
60
+ # Protocol $1
61
+ # 0: SWD
62
+ # 1: Serial
63
+ # 2: DFU
64
+ case $1 in
65
+ 0)
66
+ PORT=' SWD'
67
+ MODE=' mode=UR'
68
+ if [ $# -lt 3 ]; then
69
+ OPTS=-rst
70
+ else
71
+ OPTS=$3
72
+ fi ;;
73
+ 1)
74
+ if [ $# -lt 3 ]; then
75
+ usage 3
76
+ else
77
+ PORT=$3
78
+ if [ $# -gt 3 ]; then
79
+ shift 3
80
+ OPTS=" $@ "
81
+ fi
82
+ fi ;;
83
+ 2)
84
+ PORT=' USB1' ;;
85
+ * )
86
+ echo " Protocol unknown!"
87
+ usage 4;;
88
+ esac
89
+
90
+ ${STM32CP_CLI} -c port=${PORT} ${MODE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
91
+
92
+ exit 0
93
+
Original file line number Diff line number Diff line change
1
+ @ echo off
2
+
3
+ set ERROR = 0
4
+ set STM32CP_CLI = STM32_Programmer_CLI.exe
5
+ set ADDRESS = 0x8000000
6
+
7
+ :: Check tool
8
+ where /Q %STM32CP_CLI%
9
+ if %errorlevel% == 0 goto :param
10
+ :: Check with default path
11
+ set STM32CP = %ProgramW6432% \STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin
12
+ set STM32CP86 = %ProgramFiles(X86)% \STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin
13
+ set PATH = %PATH% ;%STM32CP% ;%STM32CP86%
14
+ where /Q %STM32CP_CLI%
15
+ if %errorlevel% == 0 goto :param
16
+ echo %STM32CP_CLI% not found.
17
+ echo Please install it or add ^ < STM32CubeProgrammer path^ > \bin' to your PATH environment:
18
+ echo https://www.st.com/en/development-tools/stm32cubeprog.html
19
+ echo Aborting!
20
+ exit 1
21
+
22
+ :param
23
+ :: Parse options
24
+ if " %~1 " == " " echo Not enough arguments! & set ERROR = 2 & goto :usage
25
+ if " %~2 " == " " echo Not enough arguments! & set ERROR = 2 & goto :usage
26
+ set FILEPATH = %~2
27
+
28
+ :: Protocol
29
+ :: 0: SWD
30
+ :: 1: Serial
31
+ :: 2: DFU
32
+ if %~1 == 0 goto :SWD
33
+ if %~1 == 1 goto :SERIAL
34
+ if %~1 == 2 goto :DFU
35
+ echo Protocol unknown!
36
+ set ERROR = 4
37
+ goto :usage
38
+
39
+ :SWD
40
+ set PORT = SWD
41
+ set MODE = mode=UR
42
+ if " %~3 " == " " (set OPTS=-rst) else (set OPTS=%3 )
43
+ goto :prog
44
+
45
+ :SERIAL
46
+ if " %~3 " == " " set ERROR = 3 & goto :usage
47
+ set PORT = %~3
48
+
49
+ if " %~4 " == " " goto :prog
50
+ shift
51
+ shift
52
+ shift
53
+ set OPTS = %*
54
+ goto :prog
55
+
56
+ :DFU
57
+ set PORT = USB1
58
+ goto :prog
59
+
60
+ :prog
61
+ %STM32CP_CLI% -c port=%PORT% %MODE% -q -d %FILEPATH% %ADDRESS% %OPTS%
62
+ exit 0
63
+
64
+ :usage
65
+ echo %0 ^ < protocol^ > ^ < file_path^ > [OPTIONS]
66
+ echo .
67
+ echo protocol:
68
+ echo 0: SWD
69
+ echo 1: Serial
70
+ echo 2: DFU
71
+ echo file_path: file path name to be downloaded: (bin, hex)
72
+ echo Options:
73
+ echo For SWD: -rst
74
+ echo -rst: Reset system (default)
75
+ echo For Serial: ^ < com_port^ > -s
76
+ echo com_port: serial identifier. Ex: /dev/ttyS0
77
+ echo -s: start automatically
78
+ echo For DFU: none
79
+ exit %ERROR%
You can’t perform that action at this time.
0 commit comments