forked from Infineon/TLE5012-Magnetic-Angle-Sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
362 lines (302 loc) · 14.4 KB
/
arduino_ci.yml
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
name: Arduino CI
# on which event should we start push, pull request or schedule dispatches
on:
- push
- pull_request
# This template runes multiple workflows
jobs:
#############################################################################
# This action sets common variables for the flow and
# identifies the examples to compile
setup:
# we run this on self hosted runner, use labels to be more specific
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
runs-on:
- self-hosted
- X64
- Linux
steps:
# checkout the latest github action code
- name: Checkout actions
uses: actions/checkout@v4
# checkout the latest arduino-cli compiler
- name: Setup Arduino CLI
uses: arduino/setup-arduino-cli@master
# Update the arduino code. Attention this does not setup XMC packages as this are set inside the self hosted runner
# the arduino board support packages can be updated automatically
# the XMC board support package is only linked inside the self hosted runner, which allows
# to use none official and beta versions
- name: Install/Update Arduino Platform
run: |
arduino-cli core update-index
arduino-cli core install "arduino:avr"
arduino-cli core install "infineon:xmc"
# Fetch variables and move them to the GITHUB_OUTPUT and fetch HIL information
- id: startup
run: |
# set the project name
export $(xfp-dev arduino workspace-setup project-name)
echo "project=$PROJECTNAME" >> $GITHUB_OUTPUT
# set the examples
declare -a data
cd $GITHUB_WORKSPACE/src/framework/arduino/
for x in examples/*;
do
data+=($x);
done;
export examples=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${data[@]}")
echo examples="$examples" >> $GITHUB_OUTPUT
# set the serials
cd /opt/runner_support/
REPO="$(basename "$GITHUB_REPOSITORY")"
serials=$(echo $(./py_checkusb.py --repo ${REPO} --list serial --json) | jq ".\"${REPO}\"" --compact-output )
echo "serials=${serials}" >> $GITHUB_OUTPUT
# set the xfp
xfp=$(./py_checkusb.py --readyaml $GITHUB_WORKSPACE/.github/fqbn.yml --json)
echo "xfp=${xfp}" >> $GITHUB_OUTPUT
# switch on the HIL
./py_checkusb.py --switch repo --namelist $REPO --onoff on
# Connect the GITHUB_OUTPUT to the variables and the workflow output mechanism
outputs:
project: ${{ steps.startup.outputs.project }}
serials: ${{ steps.startup.outputs.serials }}
examples: ${{ steps.startup.outputs.examples }}
xfp: ${{ steps.startup.outputs.xfp }}
#############################################################################
# The build job compiles the sample code for different boards
build-ard:
# wait on first setup run before starting main function
needs: setup
# we run this on self hosted runner, use labels to be more specific
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
runs-on:
- self-hosted
- X64
- Linux
# which combination of sample code and boards should run
# for this example of 2 sample codes and 3 boards a total of 2x3=6 runners have to work.
# if we have only 4 runner then these 4 are started and the last 2 are waiting until they can start
strategy:
matrix:
# List of all examples in the lib to compile
example: ${{ fromJson(needs.setup.outputs.examples) }}
# These are the steps which should run for each combination of fqbn and example code
steps:
# checkout the latest github action code
- name: Checkout actions
uses: actions/checkout@v4
# checkout the latest arduino-cli compiler
- name: Setup Arduino CLI
uses: arduino/setup-arduino-cli@master
# prepare the runner for the repo data
# setup links inside the self hosted runner for correct directory setup
# REPO is the base name of the library which is linked to the right directory structure
# check wether the .arduino15 packages dir is available
# ln -sf $GITHUB_WORKSPACE/$REPO/build/ $HOME/Arduino/libraries/$REPO
- name: Generate Arduino Library
run: |
ln -sfn /opt/XMC-for-Arduino $HOME/.arduino15/packages/Infineon
mkdir -p "$HOME/Arduino/libraries"
cd $GITHUB_WORKSPACE/
xfp-dev arduino workspace-setup --path $HOME/Arduino/libraries
# Compile the sample code for the selected board and board support package with the arduino compiler
# ln -sf $GITHUB_WORKSPACE/ $HOME/Arduino/libraries/$REPO
- name: Compile
run: |
echo $HOME
export TMPDIR=$HOME/tmp
mkdir -p $TMPDIR
cd $HOME/Arduino/libraries/${{ needs.setup.outputs.project }}
xfp=${{ toJson(needs.setup.outputs.xfp) }}
export fqbn=$(echo ${xfp} | jq ".\"ard\".\"fqbn\"" -r --compact-output )
arduino-cli compile \
${fqbn} \
--libraries="." \
--libraries="$HOME/Arduino/libraries/." \
--verbose \
${{ matrix.example }}
#############################################################################
# The build job compiles the sample code for different boards
build-plt:
# wait on first setup run before starting main function
needs: setup
# we run this on self hosted runner, use labels to be more specific
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
runs-on:
- self-hosted
- X64
- Linux
# which combination of sample code and boards should run
# for this example of 2 sample codes and 3 boards a total of 2x3=6 runners have to work.
# if we have only 4 runner then these 4 are started and the last 2 are waiting until they can start
strategy:
matrix:
# List of all examples in the lib to compile
example: ${{ fromJson(needs.setup.outputs.matrix_example) }}
steps:
# checkout the latest github action code
- name: Checkout actions
uses: actions/checkout@v4
# checkout the latest arduino-cli compiler
- name: Setup Arduino CLI
uses: arduino/setup-arduino-cli@master
# prepare the runner for the repo data
# setup links inside the self hosted runner for correct directory setup
# REPO is the base name of the library which is linked to the right directory structure
# check wether the .arduino15 packages dir is available
# export REPO=${{ needs.setup.outputs.repo }}
# ln -sf $GITHUB_WORKSPACE/$REPO/build/ $HOME/Arduino/libraries/$REPO
- name: Set and check environment, install repos
run: |
ln -sfn /opt/XMC-for-Arduino $HOME/.arduino15/packages/Infineon
mkdir -p "$HOME/Arduino/libraries"
cd $GITHUB_WORKSPACE/
xfp-dev arduino workspace-setup --path $HOME/Arduino/libraries
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
platformio platform install -f infineonxmc
platformio platform install -f atmelavr
# PlatformIO uses python for compiling and it does multiple board compiles
# at once. PlatformIO is used here to check compatibility, but is not needed for the the flash step
- name: Run PlatformIO
run: |
cd $HOME/Arduino/libraries/${{ needs.setup.outputs.project }}
xfp=${{ toJson(needs.setup.outputs.xfp) }}
export boards=$(echo ${xfp} | jq ".\"pio\".\"boards\"" -r --compact-output )
export options=$(echo ${xfp} | jq ".\"pio\".\"options\"" -r --compact-output )
pio \
ci \
--lib="." \
${boards} \
${options}
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
#############################################################################
# This step allows HIL (Hardware in the loop), therefore
# is searches for the given board/sensor combination and tries to find the actual port
# on the self hosted runner. (see documentation for the board2port finder)
flash:
# We need a successful build before we can run the deploy
needs: [setup, build-ard]
# we run this on self hosted runner, use labels to be more specific
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
runs-on:
- self-hosted
- X64
- Linux
# do not stop if a single job fails
continue-on-error: true
strategy:
# the code to flash
matrix:
# the serials of the hardware boards
serials: ${{ fromJson(needs.setup.outputs.serials) }}
# These are the steps which should run for each combination of fqbn and example code
steps:
- name: Environment
run: |
cd /opt/runner_support/
REPO="$(basename "$GITHUB_REPOSITORY")"
PROJECT=${{ needs.setup.outputs.project }}
SERIALID=${{ matrix.serials }}
xfp=${{ toJson(needs.setup.outputs.xfp) }}
PORT=$( echo $(./py_checkusb.py --serial ${SERIALID} --list comport --json) | jq ".\"${SERIALID}\"" -r)
TYPE=$( echo $(./py_checkusb.py --serial ${SERIALID} --list type --json) | jq ".\"${SERIALID}\"|.[0]" -r)
DEVTYPE=$( echo $(./py_checkusb.py --serial ${SERIALID} --list devtype --json) | jq ".\"${SERIALID}\"|.[0]" -r)
DEVICE=$( echo $(./py_checkusb.py --serial ${SERIALID} --list device --json) | jq ".\"${SERIALID}\"|.[0]" -r)
FQBN=`tr '.' ':' <<<"${DEVICE}"`
echo "repo=$REPO" >> $GITHUB_ENV
echo "project=$PROJECT" >> $GITHUB_ENV
echo "serials=$SERIALID" >> $GITHUB_ENV
echo "port=$PORT" >> $GITHUB_ENV
echo "type=$TYPE" >> $GITHUB_ENV
echo "devtype=$DEVTYPE" >> $GITHUB_ENV
echo "fqbn=$FQBN" >> $GITHUB_ENV
echo "device=$DEVICE" >> $GITHUB_ENV
echo "example="$(echo ${xfp} | jq ".\"hil\".\"example\"" -r --compact-output ) >> $GITHUB_ENV
echo "baud="$(echo ${xfp} | jq ".\"hil\".\"baud\"" -r --compact-output ) >> $GITHUB_ENV
echo "Repository name: " $REPO
echo "Project name: " $PROJECT
echo "Device Serial ID: " $SERIALID
echo "Port found: " $PORT
echo "Type: " $TYPE
echo "Device Type: " $DEVTYPE
echo "FQBN: " $FQBN
echo "Device: " $DEVICE
echo "Example: " $(echo ${xfp} | jq ".\"hil\".\"example\"" -r --compact-output )
echo "Baud example: " $(echo ${xfp} | jq ".\"hil\".\"baud\"" -r --compact-output )
# Compile the code which we want to flash
# REPO: the name of the repository which is also the link name
# check/set the arduino15 package library
# link the repo to the correct place for compiling under arduino-cli
# compile the code with the arduino-cli and export the binary files for flashing
# ln -sf $GITHUB_WORKSPACE/ $HOME/Arduino/libraries/$REPO
- name: Compile Sketch
run: |
export TMPDIR=$HOME/tmp
mkdir -p $TMPDIR
ln -sfn /opt/XMC-for-Arduino $HOME/.arduino15/packages/Infineon
mkdir -p "$HOME/Arduino/libraries"
cd $HOME/Arduino/libraries/${{ env.project }}
arduino-cli compile --clean --log --warnings all \
--fqbn ${{ env.fqbn }} \
--libraries="." \
--libraries="$HOME/Arduino/libraries/." \
--export-binaries \
${{ env.example }}
# Flashes the compiled HEX file onto the selected MCU
# REPO: the name of the repository which is also the link name
# HEXNAME: the board depended name of the HEX files
# SERIALID: the unique serial number of the hardware board according the board2port.yaml
# DEVICE: the flashing device according the board2port.yaml
# PORT: real PORT name of the attached hardware based on the SERIALID
# use the python based XMC flasher
- name: Flash
run: |
cd $HOME
python $HOME/.arduino15/packages/Infineon/hardware/xmc/3.2.0/tools/xmc-flasher.py \
upload \
-d ${{ env.devtype }} \
-p ${{ env.port }} \
-f $HOME/Arduino/libraries/${{ env.project }}/${{ env.example }}/build/${{ env.device }}/*.hex
# Monitoring the serial output from the attached and flashed hardware and collecting
# ERROR, Warning and statistical data for reporting
- name: Monitor
run: |
if [ "${{ env.port }}" != 'null' ]; then
echo "need to monitor"
timeout 1m /opt/runner_support/py_console.py \
--port ${{ env.port }} \
--baud ${{ env.baud }} \
--report ${HOME}/Arduino/libraries/${{ env.project }}/${{ env.example }}/build/${{ env.device }}/report.txt
else
echo "No port found"
fi
# Upload the compiled HEX files to the GitHub server
- name: Artefact
uses: actions/upload-artifact@v4
with:
name: ${{ env.type }}_${{ env.serials }}
path: $HOME/Arduino/libraries/${{ env.project }}/${{ env.example }}/build/${{ env.device }}/*
if-no-files-found: ignore
#############################################################################
# Switch off the HIL after all tests are done
post:
# we run this no matter if before fails
if: always()
# wait on first setup run before starting main function
needs: [setup, flash]
# we run this on self hosted runner, use labels to be more specific
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
runs-on:
- self-hosted
- X64
- Linux
steps:
- name: Switch off HIL
run: |
cd /opt/runner_support/
REPO="$(basename "$GITHUB_REPOSITORY")"
./py_checkusb.py --switch repo --namelist $REPO --onoff off