Skip to content

back to PIO problem #358

back to PIO problem

back to PIO problem #358

Workflow file for this run

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 exampls to comple
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
- id: set-matrix
run: |
REPO="$(basename "$GITHUB_REPOSITORY")"
echo "repo=$REPO" >> $GITHUB_OUTPUT
export $(xfp-dev arduino workspace-setup project-name)
echo "project=$PROJECTNAME" >> $GITHUB_OUTPUT
cd $GITHUB_WORKSPACE/src/framework/arduino
for x in examples/*;
do
data+=($x);
done;
export mvar=`jq --compact-output --null-input '$ARGS.positional' --args -- "${data[@]}"`
echo matrix="$mvar" >> $GITHUB_OUTPUT
cd $GITHUB_WORKSPACE/.github
cat ./fqbn.yml | shyaml get-values fqbn
mfqbn=""
for f in `cat ./fqbn.yml | shyaml get-values fqbn`;
do
mfqbn+=" --fqbn=${f}"
done;
echo "fqbn=$mfqbn" >> $GITHUB_OUTPUT
echo $GITHUB_ACTION
# Cache python pip downloads if we have one for faster access
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-
# Ditto, cache PlatformIO downloads for faster acces during compilation
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
# Connect the GITHUB_OUTPUT to the variables and the workflow output mechanisem
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
fqbn: ${{ steps.set-matrix.outputs.fqbn }}
repo: ${{ steps.set-matrix.outputs.repo }}
project: ${{ steps.set-matrix.outputs.project }}
#############################################################################
# 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.matrix) }}
# 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: Set and check environment, install repos
run: |
export REPO=${{ needs.setup.outputs.repo }}
ln -sfn /opt/XMC-for-Arduino ~/.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 Sketch
run: |
export TMPDIR=$HOME/tmp
mkdir -p $TMPDIR
cd $HOME/Arduino/libraries/${{ needs.setup.outputs.project }}
arduino-cli compile ${{ needs.setup.outputs.fqbn }} --libraries="." --libraries="$HOME/Arduino/libraries/." ${{ matrix.example }} --verbose
#############################################################################
# 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) }}
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: Set and check environment, install repos
run: |
export REPO=${{ needs.setup.outputs.repo }}
ln -sfn /opt/XMC-for-Arduino ~/.arduino15/packages/Infineon
mkdir -p "$HOME/Arduino/libraries"
cd $GITHUB_WORKSPACE/
xfp-dev arduino workspace-setup --path $HOME/Arduino/libraries
# 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 }}
boards="${{ needs.setup.outputs.fqbn }}"
echo "===\n $boards \n"
board = "$boards | perl -pe 'lc(s/fqbn\=\w+:\w+:/board /gx)'"
board1= "$board | perl -pw "lc()'"
echo "===\n $board1 \n"
# pio ci --lib="." ${board3} --project-option="lib_deps=Wire"
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
strategy:
# flashing only one by one
max-parallel: 1
# the code to flash
matrix:
# the code to flash
example: [
examples/readAngleTest
]
# board packages we want to run
# attention the matrix spans over the fqbn not platform so that we can choose different boards
# this example compiles each sample code for Arduino Uno, XMC2Go and XMC4700 boards
fqbn: [
"Infineon:xmc:XMC1100_XMC2GO"
]
# include additional information for each fqbn, in this case the platform name to install
# port_name: the name of the yaml structure in the board2port.yaml, there can be more than one hardware attached
# device: the device name the yaml structure in the board2port.yaml, there can be more than one hardware attached
include:
- fqbn: "Infineon:xmc:XMC1100_XMC2GO"
port_name: "port_serial.0"
device: "device.0"
# These are the steps which should run for each combination of fqbn and example code
steps:
# 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 ~/.arduino15/packages/Infineon
mkdir -p "$HOME/Arduino/libraries"
cd $HOME/Arduino/libraries/${{ needs.setup.outputs.project }}
arduino-cli compile --fqbn ${{ matrix.fqbn }} --libraries="." --libraries="$HOME/Arduino/libraries/." ${{ matrix.example }} --export-binaries
# 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
# SERIAL_NUM: 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 SERIAL_NUM
# use the python based XMC flasher
- name: Flash
run: |
cd /opt/runner_support/
export HEXNAME=`tr ':' '.' <<<"${{ matrix.fqbn }}"`
export SERIAL_NUM=`cat ./board2port.yaml | shyaml get-value $HEXNAME.${{ needs.setup.outputs.repo }}.${{ matrix.port_name}}`
export DEVICE=`cat ./board2port.yaml | shyaml get-value $HEXNAME.${{ needs.setup.outputs.repo }}.${{ matrix.device}}`
export TYPE=`cat ./board2port.yaml | shyaml get-value $HEXNAME.$REPO.type`
export PORT=`./find_usb.sh $SERIAL_NUM`
echo "Repo name extracted: " ${{ needs.setup.outputs.repo }}
echo "Real repo name: " ${{ needs.setup.outputs.project }}
echo "Build HEX name: " $HEXNAME
echo "Port Serial Num: " $SERIAL_NUM
echo "Port found: " $PORT
echo "Flash device: " $DEVICE
echo "Board type name: " $TYPE
cd $HOME
python $HOME/.arduino15/packages/Infineon/hardware/xmc/3.1.0/tools/xmc-flasher.py upload -d $DEVICE -p $PORT -f $HOME/Arduino/libraries/${{ needs.setup.outputs.project }}/${{ matrix.example }}/build/$HEXNAME/*.hex
- name: Monitor
run: |
cd /opt/runner_support/
export HEXNAME=`tr ':' '.' <<<"${{ matrix.fqbn }}"`
export SERIAL_NUM=`cat ./board2port.yaml | shyaml get-value $HEXNAME.${{ needs.setup.outputs.repo }}.${{ matrix.port_name}}`
export DEVICE=`cat ./board2port.yaml | shyaml get-value $HEXNAME.${{ needs.setup.outputs.repo }}.${{ matrix.device}}`
export PORT=`./find_usb.sh $SERIAL_NUM`
/opt/runner_support/py_console.py --port $PORT