-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharduino-win-build.bat
161 lines (122 loc) · 5.1 KB
/
arduino-win-build.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
setlocal
REM go to the folder where this bat script is located
cd /d %~dp0
set /a EXPECTED_CLI_MAJOR=0
set /a EXPECTED_CLI_MINOR=33
set ARDUINO_CORE=arduino:mbed_portenta
set BOARD=arduino:mbed_portenta:envie_m7:split=100_0
set ARDUINO_CLI=arduino-cli
set BUILD_OPTION=--build
set FLASH_OPTION=--flash
set ALL_OPTION=--all
IF [%1]==[] (
GOTO NOPARAMETER
)
set COMMAND=%1
FOR %%I IN (.) DO SET DIRECTORY_NAME=%%~nI%%~xI
where /q arduino-cli
IF ERRORLEVEL 1 (
GOTO NOTINPATHERROR
)
REM parse arduino-cli version
FOR /F "tokens=1-3 delims==." %%I IN ('arduino-cli version') DO (
FOR /F "tokens=1-3 delims== " %%X IN ('echo %%I') DO (
set /A CLI_MAJOR=%%Z
)
SET /A CLI_MINOR=%%J
FOR /F "tokens=1-3 delims== " %%X IN ('echo %%K') DO (
set /A CLI_REV=%%X
)
)
if !CLI_MAJOR! LEQ !EXPECTED_CLI_MAJOR! if !CLI_MINOR! LSS !EXPECTED_CLI_MINOR! GOTO UPGRADECLI
if !CLI_MAJOR! NEQ !EXPECTED_CLI_MAJOR! (
echo You're using an untested version of Arduino CLI, this might cause issues (found: %CLI_MAJOR%.%CLI_MINOR%.%CLI_REV%, expected: %EXPECTED_CLI_MAJOR%.%EXPECTED_CLI_MINOR%.x )
) else (
if !CLI_MINOR! NEQ !EXPECTED_CLI_MINOR! (
echo You're using an untested version of Arduino CLI, this might cause issues (found: %CLI_MAJOR%.%CLI_MINOR%.%CLI_REV%, expected: %EXPECTED_CLI_MAJOR%.%EXPECTED_CLI_MINOR%.x )
)
)
echo Finding Arduino Mbed core...
(arduino-cli core list 2> nul) | findstr "arduino:mbed_portenta"
IF %ERRORLEVEL% NEQ 0 (
GOTO INSTALLMBEDCORE
)
:AFTERINSTALLMBEDCORE
:: define and include
set DEFINE=-DARDUINOSTL_M_H -DMBED_HEAP_STATS_ENABLED=1 -DMBED_STACK_STATS_ENABLED=1 -O3 -DEIDSP_QUANTIZE_FILTERBANK=0 -DEI_CLASSIFIER_SLICES_PER_MODEL_WINDOW=4 -DEI_DSP_IMAGE_BUFFER_STATIC_SIZE=128 -DEI_CAMERA_FRAME_BUFFER_SDRAM -DEI_CLASSIFIER_ALLOCATION_STATIC -w
set INCLUDE=-I.\\src\\ -I.\\src\\model-parameters\\ -I.\\src\\ingestion-sdk-c\\ -I.\\src\\ingestion-sdk-c\\inc\\signing\\ -I.\\src\\ingestion-sdk-platform\\portenta-h7\\ -I.\\src\\sensors\\ -I.\\src\\sensors\\ -I.\\src\\mbedtls_hmac_sha256_sw\\ -I.\\src\\edge-impulse-sdk\\ -I.\\src\\firmware-sdk\\
rem CLI v0.14 updates the name of this to --build-property
set BUILD_PROPERTIES_FLAG=--build-property
:: just build
IF %COMMAND% == %BUILD_OPTION% goto :BUILD
echo Finding Arduino Mbed core OK
echo Finding Arduino Portenta H7...
set COM_PORT=""
for /f "tokens=1" %%i in ('arduino-cli board list ^| findstr "Arduino Portenta H7"') do (
set COM_PORT=%%i
)
IF %COM_PORT% == "" (
GOTO NOTCONNECTED
)
echo Finding Arduino Portenta H7 OK at %COM_PORT%
IF %COMMAND% == %FLASH_OPTION% goto :FLASH
IF %COMMAND% == %ALL_OPTION% goto :ALL else goto :COMMON_EXIT
echo No valid command
goto :COMMON_EXIT
:BUILD
echo Building %PROJECT%
%ARDUINO_CLI% compile --fqbn %BOARD% %BUILD_PROPERTIES_FLAG% "build.extra_flags=%DEFINE% %INCLUDE%" --output-dir .
goto :COMMON_EXIT
:FLASH
echo Flashing %PROJECT%
CALL %ARDUINO_CLI% upload -p %COM_PORT% --fqbn %BOARD% --input-dir .
goto :COMMON_EXIT
:ALL
echo Building %PROJECT%
%ARDUINO_CLI% compile --fqbn %BOARD% %BUILD_PROPERTIES_FLAG% "build.extra_flags=%DEFINE% %INCLUDE%" --output-dir .
echo Flashing %PROJECT%
CALL %ARDUINO_CLI% upload -p %COM_PORT% --fqbn %BOARD% --input-dir .
goto :COMMON_EXIT
IF %ERRORLEVEL% NEQ 0 (
GOTO FLASHINGFAILEDERROR
)
echo Flashed your Arduino Portenta H7 development board
echo To set up your development with Edge Impulse, run 'edge-impulse-daemon'
echo To run your impulse on your development board, run 'edge-impulse-run-impulse'
@pause
exit /b 0
:NOTINPATHERROR
echo Cannot find 'arduino-cli' in your PATH. Install the Arduino CLI before you continue
echo Installation instructions: https://arduino.github.io/arduino-cli/latest/
@pause
exit /b 1
:INSTALLMBEDCORE
echo Installing Arduino Mbed core...
arduino-cli core update-index
arduino-cli core install arduino:mbed_portenta@2.8.0
echo Installing Arduino Mbed core OK
GOTO AFTERINSTALLMBEDCORE
:NOTCONNECTED
echo Cannot find a connected Arduino Portenta H7 development board via 'arduino-cli board list'
echo If your board is connected, double-tap on the RESET button to bring the board in recovery mode
@pause
exit /b 1
:UPGRADECLI
echo You need to upgrade your Arduino CLI version (now: %CLI_MAJOR%.%CLI_MINOR%.%CLI_REV%, but required: %EXPECTED_CLI_MAJOR%.%EXPECTED_CLI_MINOR%.x or higher)
echo See https://arduino.github.io/arduino-cli/installation/ for upgrade instructions
@pause
exit /b 1
:FLASHINGFAILEDERROR
echo Flashing failed. Here are some options:
echo If your error is 'incorrect FQBN' you'll need to upgrade the Arduino core via:
echo $ arduino-cli core update-index
echo $ arduino-cli core install arduino:mbed_portenta@2.8.0
echo Otherwise, double tap the RESET button to load the bootloader and try again
@pause
exit /b %ERRORLEVEL%
:NOPARAMETER
echo No arguments, pleaase invoke with --build or --flash or --all. See README.md for instructions
exit /b 1
:COMMON_EXIT