-
Notifications
You must be signed in to change notification settings - Fork 5
/
arduino-build.sh
executable file
·128 lines (113 loc) · 4.23 KB
/
arduino-build.sh
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
#!/bin/bash
set -e
PROJECT=workshop-devsummit2021-portenta
BOARD=arduino:mbed_portenta:envie_m7:split=100_0
COMMAND=$1
if [ -z "$ARDUINO_CLI" ]; then
ARDUINO_CLI=$(which arduino-cli || true)
fi
DIRNAME="$(basename "$SCRIPTPATH")"
EXPECTED_CLI_MAJOR=0
EXPECTED_CLI_MINOR=13
CLI_MAJOR=$($ARDUINO_CLI version | cut -d. -f1 | rev | cut -d ' ' -f1)
CLI_MINOR=$($ARDUINO_CLI version | cut -d. -f2)
CLI_REV=$($ARDUINO_CLI version | cut -d. -f3 | cut -d ' ' -f1)
check_dependency()
{
if [ ! -x "$ARDUINO_CLI" ]; then
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/"
exit 1
fi
if (( CLI_MINOR < EXPECTED_CLI_MINOR)); then
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"
exit 1
fi
if (( CLI_MAJOR != EXPECTED_CLI_MAJOR || CLI_MINOR != EXPECTED_CLI_MINOR )); then
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)"
fi
echo "Installing dependencies..."
$ARDUINO_CLI core update-index
echo "Installing Arduino Mbed core..."
$ARDUINO_CLI core install arduino:[email protected]
echo "Installing Arduino Mbed core OK"
echo "Installing MKRWAN library..."
$ARDUINO_CLI lib install [email protected] # MKRWAN library
echo "Installing MKRWAN library OK"
}
get_data_dir() {
local OUTPUT=$($ARDUINO_CLI config dump | grep 'data: ')
local lib="${OUTPUT:8}"
echo "$lib"
}
patch-mbed-2-5-2()
{
echo "recipe.hooks.linking.prelink.1.pattern=\"{compiler.path}{compiler.c.elf.cmd}\" -E -P -x c {build.extra_ldflags} \"{build.variant.path}/{build.ldscript}\" -o {build.path}/{build.ldscript}" > ${ARDUINO_DATA_DIR}/packages/arduino/hardware/mbed_portenta/2.5.2/platform.local.txt
}
# CLI v0.14 updates the name of this to --build-property
if ((CLI_MAJOR >= 0 && CLI_MINOR >= 14)); then
BUILD_PROPERTIES_FLAG=--build-property
else
BUILD_PROPERTIES_FLAG=--build-properties
fi
ARDUINO_DATA_DIR="$(get_data_dir)"
if [ -z "$ARDUINO_DATA_DIR" ]; then
echo "Arduino data directory not found"
exit 1
fi
INCLUDE="-I./src"
INCLUDE+=" -I./src/model-parameters"
INCLUDE+=" -I./src/repl"
INCLUDE+=" -I./src/ingestion-sdk-c/"
INCLUDE+=" -I./src/ingestion-sdk-c/inc"
INCLUDE+=" -I./src/ingestion-sdk-c/inc/signing"
INCLUDE+=" -I./src/ingestion-sdk-platform/portenta-h7"
INCLUDE+=" -I./src/sensors"
INCLUDE+=" -I./src/QCBOR/inc"
INCLUDE+=" -I./src/QCBOR/src"
INCLUDE+=" -I./src/mbedtls_hmac_sha256_sw/"
INCLUDE+=" -I./src/edge-impulse-sdk/"
FLAGS="-DARDUINOSTL_M_H"
FLAGS+=" -DMBED_HEAP_STATS_ENABLED=1"
FLAGS+=" -DMBED_STACK_STATS_ENABLED=1"
FLAGS+=" -O3"
FLAGS+=" -g3"
FLAGS+=" -DEI_SENSOR_AQ_STREAM=FILE"
FLAGS+=" -DEIDSP_QUANTIZE_FILTERBANK=0"
FLAGS+=" -DEI_CLASSIFIER_SLICES_PER_MODEL_WINDOW=3"
FLAGS+=" -DEI_DSP_IMAGE_BUFFER_STATIC_SIZE=128"
FLAGS+=" -DEI_CAMERA_FRAME_BUFFER_SDRAM"
#FLAGS+=" -DEI_CAMERA_FRAME_BUFFER_HEAP"
#FLAGS+=" -mfpu=fpv4-sp-d16"
FLAGS+=" -w"
if [ "$COMMAND" = "--build" ];
then
echo "Building $PROJECT"
check_dependency
patch-mbed-2-5-2
$ARDUINO_CLI compile --fqbn $BOARD $BUILD_PROPERTIES_FLAG build.extra_flags="$INCLUDE $FLAGS" --output-dir . &
pid=$! # Process Id of the previous running command
while kill -0 $pid 2>/dev/null
do
echo "Still building..."
sleep 2
done
wait $pid
ret=$?
if [ $ret -eq 0 ]; then
echo "Building $PROJECT done"
else
exit "Building $PROJECT failed"
fi
elif [ "$COMMAND" = "--flash" ];
then
$ARDUINO_CLI upload -p $($ARDUINO_CLI board list | grep Arduino | cut -d ' ' -f1) --fqbn $BOARD --input-dir .
elif [ "$COMMAND" = "--all" ];
then
$ARDUINO_CLI compile --fqbn $BOARD $BUILD_PROPERTIES_FLAG build.extra_flags="$INCLUDE $FLAGS"
status=$?
[ $status -eq 0 ] && $ARDUINO_CLI upload -p $($ARDUINO_CLI board list | grep Arduino | cut -d ' ' -f1) --fqbn $BOARD --input-dir .
else
echo "Nothing to do for target"
fi