Skip to content

Commit

Permalink
Feature/add arduino-core-tests submodule for test reuse (#313)
Browse files Browse the repository at this point in the history
* refact: change the unity test to submodule and clean up workflow & make test command

* build: change unit test submodule dependencies to new url

* core: update unit test setup

* fix: add time out to spin lock in hardware serial

* test: add small changes to I2C change, add it to HIL

* fix: pull submodules when checkout repo

* fix: pull private submodule with GITHUB_TOKEN?

* Update hil-unity-checks.yml

fix: use PAT

* fix: using ssh key to unit test repo

* Change sender/reciever order for CAN

* Use access token for submodule

* Use access token for submodule

* Use access token for submodule

* Use access token for submodule

* Use access token for submodule

* Use access token

* Use access token

* Use access token

* Use access token

* Small change to trigger new checkout

* Small change to trigger new checkout

* to latest

* Add badge for HIL testing

* Move Unity path to system wide path

* test: update test submodule and according files. update the README

* fix: small change of test target name

* There is still a problem in the make file setting

* We must be sure that the submodule is clone on all runner

* fix: change some naming lowercase in unity test

* test: remove test_wire_connected1_pingpong for not supported board (xmc1400 2go and xmc1100 2go)

* fix: update makefile target

* fix: update unity because of some typo

* fix: copie only required test source in build folder

* fix: typo in makefile

* feature: update unity test and reference command

* doc: update documentation of test and formatting

* chore: add .gitsttribute to avoit eol problem in future

* chore: reset HardwareSerial.cpp for eol problem

* chore: reset hil-unity-checks for eol problem

* chore: remove old submodule

* chore: add arduino-core-tests submodule

* ci: change the tests path

---------

Co-authored-by: Filies Olaf (IFAG DES TOC PSA) <[email protected]>
  • Loading branch information
2 people authored and ederjc committed Dec 19, 2024
1 parent fe63ee1 commit ab26621
Show file tree
Hide file tree
Showing 30 changed files with 235 additions and 1,657 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Configuration to handle line endings for working with Windows and Unix
# Reference:
# https://help.github.com/articles/dealing-with-line-endings/
# https://git-scm.com/docs/gitattributes#_checking_out_and_checking_in

* text=auto

*.c text
*.cpp text
*.h text
*.hpp text
*.ino text
*.py text


*.sh text eol=lf
*.bat text eol=crlf
17 changes: 13 additions & 4 deletions .github/workflows/hil-unity-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
env:
TEST_VERSION: 1.0.0

permissions:
contents: write

# This template runes multiple workflows
jobs:

Expand All @@ -27,6 +30,9 @@ jobs:
# checkout the latest github action code
- name: Checkout actions
uses: actions/checkout@v4
with:
token: ${{ secrets.UNITY_TOKEN }}
submodules: recursive

# checkout the latest arduino-cli compiler
- name: Setup Arduino CLI
Expand All @@ -51,7 +57,7 @@ jobs:
./py_checkusb.py --switch repo --namelist $REPO --onoff on
# set the hil-unity-checks
hil=$(./py_checkusb.py --readyaml $GITHUB_WORKSPACE/tests/unity/hil-unity-checklist.yaml --json)
hil=$(./py_checkusb.py --readyaml $GITHUB_WORKSPACE/tests/hil-unity-checklist.yaml --json)
echo "hil=${hil}" >> $GITHUB_OUTPUT
# fetch unity libraries
Expand Down Expand Up @@ -97,6 +103,9 @@ jobs:
# checkout the latest github action code
- name: Checkout actions
uses: actions/checkout@v4
with:
token: ${{ secrets.UNITY_TOKEN }}
submodules: recursive

# setup environment
- name: Environment
Expand Down Expand Up @@ -168,11 +177,11 @@ jobs:
# loop over all tests for one example and compile7flash the devices
readarray -t TESTS < <(echo $lib | jq ".\"${LIB}\".\"${EXAMPLE}\"[]" -r --compact-output)
for ((idx=0; idx<${#TESTS[@]}; ++idx)); do
cd $GITHUB_WORKSPACE/tests/unity/
cd $GITHUB_WORKSPACE/tests/arduino-core-tests/
echo "=============================================================================================================="
echo "Run on index $idx for TEST: ${TESTS[idx]} under EXAMPLE: ${EXAMPLE} and LIB: ${LIB}"
echo "Run on index $idx for TEST: ${TESTS[idx]} under EXAMPLE: ${EXAMPLE} and LIB: ${LIB} on port: ${PORTS[idx]}"
echo "=============================================================================================================="
make FQBN=${{ env.fqbn }} PORT=${PORTS[idx]} UNITY_PATH=/opt/runner_support/Unity_github ${TESTS[idx]}
make FQBN=${{ env.fqbn }} PORT=${PORTS[idx]} UNITY_PATH=/opt/Unity ${TESTS[idx]}
mkdir -p ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/
mv ./build/build/* ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/.
echo "=============================================================================================================="
Expand Down
40 changes: 21 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
.history
.vscode

# build folder
pkg_build
build

# python
**/__pycache__/
venv/

# code-check reports
clang-tidy-report.txt

scan-build-reports/

cppcheck_reports/
cppcheck.checkers
err.xml
# vscode
.history
.vscode
.editorconfig

# build folder
pkg_build
build

# python
**/__pycache__/
venv/

# code-check reports
clang-tidy-report.txt

scan-build-reports/

cppcheck_reports/
cppcheck.checkers
err.xml
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "arduino-core-tests"]
path = tests/arduino-core-tests
url = https://github.com/Infineon/arduino-core-tests.git
102 changes: 55 additions & 47 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
# Contributing to XMC for Arduino
First important point: **All Contributions** are welcomed :open_hands:.

Please contribute and raise issues via the [github repository](https://github.com/Infineon/XMC-for-Arduino/tree/master)

### Overview for Contributors

- Start your contribution by creating a [fork](https://github.com/Infineon/XMC-for-Arduino/fork) of this repository
- It's recommended to create a separate branch for your contribution in your fork
- Once your contribution is ready & tested, please create a [Pull Request](https://github.com/Infineon/XMC-for-Arduino/compare) to the master branch
- Once we merged your changes to the master branch, they are automatically included in the next release

### Testing in Arduino IDE (on Windows)
Clone the repository in Arduino folder:
- Open Arduino and install any version of this project as described [here](https://xmc-arduino.readthedocs.io/en/latest/installation-instructions.html).
- Open the installation location in your Arduino program folder, e.g.
`C:\Users\<username>\AppData\Local\Arduino15\packages\Infineon\hardware\xmc`
- Open git bash, type command:
`git clone <your-xmc-for-arduino-fork> <version>`

This allows quick testing of local changes during development.

[!TIP]
If you encounter strange behavior with Arduino IDE during development, try cleaning up the cache:
* Windows: `C:\User\"username"\AppData\Roaming\arduino-ide`
* Linux: `~/.config/arduino-ide`
* macOS: `~/Library/Application Support/arduino-ide/`

### Automated Build Checks

Currently a Github workflow is used for automatic compilation checking and releasing. Workflows are defined [here](https://github.com/Infineon/XMC-for-Arduino/tree/master/.github/workflows).
Before opening a Pull Request for your contribution, please add a git tag in the format `Vx.y.z` (e.g. V3.3.0) to trigger the release process in your fork and pass the compilation tests.

### Creating and Maintaining Third Party Libraries
#### Basics
The Arduino IDE allows for external libraries to be added to support specific devices and functions which are not part of the core setup. For details on creating libraries see the
[Arduino library specifications](https://arduino.github.io/arduino-cli/library-specification/). If you add additional libraries to this project, make sure to [document them](https://xmc-arduino.readthedocs.io/en/latest/builtin-libraries.html) accordingly.

#### XMC-for-Arduino Configuration
To ensure that a library specific to one architecture or board type is only compiled when a supporting board is set up, this specification includes a setting for *architecture* in the *library.properties* file.

When creating or maintaining third party or external libraries for XMC-for-Arduino please use this setting:
~~~
architecture=xmc
~~~

If your library also supports other boards and architectures, add those in as well.
# Contributing to XMC for Arduino
First important point: **All Contributions** are welcomed :open_hands:.

Please contribute and raise issues via the [github repository](https://github.com/Infineon/XMC-for-Arduino/tree/master)

## Overview for Contributors

- Start your contribution by creating a [fork](https://github.com/Infineon/XMC-for-Arduino/fork) of this repository
- It's recommended to create a separate branch for your contribution in your fork
- Once your contribution is ready & tested, please create a [Pull Request](https://github.com/Infineon/XMC-for-Arduino/compare) to the master branch
- Once we merged your changes to the master branch, they are automatically included in the next release

## Install the BSP under development (on Windows)
Clone the repository in Arduino folder:
- Open Arduino and install any version of this project as described [here](https://xmc-arduino.readthedocs.io/en/latest/installation-instructions.html).
- Open the installation location in your Arduino program folder, e.g.
`C:\Users\<username>\AppData\Local\Arduino15\packages\Infineon\hardware\xmc`
- Open git bash, type command:
`git clone <your-xmc-for-arduino-fork> <version>`

This allows quick testing of local changes during development.

[!TIP]
If you encounter strange behavior with Arduino IDE during development, try cleaning up the cache:
* Windows: `C:\User\"username"\AppData\Roaming\arduino-ide`
* Linux: `~/.config/arduino-ide`
* macOS: `~/Library/Application Support/arduino-ide/`

## Automated Build Checks

Currently a Github workflow is used for automatic compilation checking and releasing. Workflows are defined [here](https://github.com/Infineon/XMC-for-Arduino/tree/master/.github/workflows).
Before opening a Pull Request for your contribution, please add a git tag in the format `Vx.y.z` (e.g. V3.3.0) to trigger the release process in your fork and pass the compilation tests.

## Creating and Maintaining Third Party Libraries
### Basics
The Arduino IDE allows for external libraries to be added to support specific devices and functions which are not part of the core setup. For details on creating libraries see the
[Arduino library specifications](https://arduino.github.io/arduino-cli/library-specification/). If you add additional libraries to this project, make sure to [document them](https://xmc-arduino.readthedocs.io/en/latest/builtin-libraries.html) accordingly.

### XMC-for-Arduino Configuration
To ensure that a library specific to one architecture or board type is only compiled when a supporting board is set up, this specification includes a setting for *architecture* in the *library.properties* file.

When creating or maintaining third party or external libraries for XMC-for-Arduino please use this setting:
~~~
architecture=xmc
~~~

If your library also supports other boards and architectures, add those in as well.

## Validation test
To test the XMC4arduino, we used unity to test some of the features of the arduino core/builtin library.
Tests are located in tests\unity and included as submodule in this project. Run `git submodule update --init --recursive` to update them. If you are nor familiar with submodules, check out: https://git-scm.com/book/en/v2/Git-Tools-Submodules

## Code checks (WIP)
Refer to libraries\CAN\Makefile.codecheck
* Regarding formatting, we currently use [pre-commit](https://pre-commit.com/) to automatically run clang-formatting to format all c/c++ code. Please install this python package, and follow the quick start (the pre-commit configuration file is already there). You should be able to format your code automatically on git commit!
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

![Compilation Status](https://github.com/Infineon/XMC-for-Arduino/actions/workflows/compile-platform-examples.yml/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/xmc-arduino/badge/?version=latest)](https://xmc-arduino.readthedocs.io/en/latest/?badge=latest)
[![Hil unity library checks](https://github.com/Infineon/XMC-for-Arduino/actions/workflows/hil-unity-checks.yml/badge.svg)](https://github.com/Infineon/XMC-for-Arduino/actions/workflows/hil-unity-checks.yml)

This project integrates Infineon's 32-bit XMC™ Industrial Arm® Cortex®-M Microcontroller into the [Arduino](https://www.arduino.cc/en/Guide/Introduction) ecosystem.

Expand Down
68 changes: 38 additions & 30 deletions cores/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,33 @@ size_t HardwareSerial::write(const uint8_t uc_data) {
XMC_USIC_CH_TBUF_STATUS_BUSY) ||
(_tx_buffer->_iTail != _tx_buffer->_iHead))
#endif
{
// If busy we buffer
int nextWrite = _tx_buffer->_iHead + 1;
if( nextWrite >= SERIAL_BUFFER_SIZE )
nextWrite = 0;

//This should always be false but in case transmission is completed before buffer, we need to reenable IRQ
if( XMC_USIC_CH_GetTransmitBufferStatus( _XMC_UART_config->channel ) != XMC_USIC_CH_TBUF_STATUS_BUSY ) {
XMC_UART_CH_EnableEvent( _XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER );
XMC_UART_CH_Transmit( _XMC_UART_config->channel, _tx_buffer->_aucBuffer[ _tx_buffer->_iTail ] );
_tx_buffer->_iTail++;
if(_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
_tx_buffer->_iTail = _tx_buffer->_iTail - SERIAL_BUFFER_SIZE; // If iTail is larger than Serial Buffer Size calculate the correct index value
}

while( _tx_buffer->_iTail == nextWrite )
; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent
{
// If busy we buffer
int nextWrite = _tx_buffer->_iHead + 1;
if (nextWrite >= SERIAL_BUFFER_SIZE)
nextWrite = 0;

// This should always be false but in case transmission is completed before buffer, we need
// to reenable IRQ
if (XMC_USIC_CH_GetTransmitBufferStatus(_XMC_UART_config->channel) !=
XMC_USIC_CH_TBUF_STATUS_BUSY) {
XMC_UART_CH_EnableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
XMC_UART_CH_Transmit(_XMC_UART_config->channel,
_tx_buffer->_aucBuffer[_tx_buffer->_iTail]);
_tx_buffer->_iTail++;
if (_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
_tx_buffer->_iTail %= SERIAL_BUFFER_SIZE; // If iTail is larger than Serial Buffer
// Size calculate the correct index value
}

unsigned long startTime = millis();
while (_tx_buffer->_iTail == nextWrite) {
if (millis() - startTime > 1000) {
return 0; // Spin locks if we're about to overwrite the buffer. This continues once
// the data is
// sent
}
}

_tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
_tx_buffer->_iHead = nextWrite;
Expand Down Expand Up @@ -210,22 +220,20 @@ void HardwareSerial::IrqHandler(void) {
XMC_UART_CH_ClearStatusFlag(_XMC_UART_config->channel,
XMC_UART_CH_STATUS_FLAG_TRANSMIT_BUFFER_INDICATION);

if( _tx_buffer->_iTail != _tx_buffer->_iHead )
{
XMC_UART_CH_Transmit( _XMC_UART_config->channel,
_tx_buffer->_aucBuffer[ _tx_buffer->_iTail ] );
_tx_buffer->_iTail++;
if( _tx_buffer->_iTail >= SERIAL_BUFFER_SIZE )
_tx_buffer->_iTail = 0;
if (_tx_buffer->_iTail != _tx_buffer->_iHead) {
XMC_UART_CH_Transmit(_XMC_UART_config->channel,
_tx_buffer->_aucBuffer[_tx_buffer->_iTail]);
_tx_buffer->_iTail++;
if (_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
_tx_buffer->_iTail %= SERIAL_BUFFER_SIZE; // If iTail is larger than Serial Buffer
// Size calculate the correct index value
} else {
// Mask off transmit interrupt so we don't get it any more
XMC_UART_CH_DisableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
}
else {
// Mask off transmit interrupt so we don't get it any more
XMC_UART_CH_DisableEvent( _XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER );
}
}
}

//****************************************************************************
// END OF FILE
//****************************************************************************

//****************************************************************************
23 changes: 23 additions & 0 deletions tests/Makefile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Build commands
### ! Please note that you need to change the port and path of Unity as appropriate !

### Unit tests

##CAN

# 1 board, no wire
make FQBN=Infineon:xmc:XMC1400_XMC2GO PORT=COM42 UNITY_PATH=\Unity test_can_single monitor

# 2 boards
make FQBN=Infineon:xmc:XMC1400_XMC2GO PORT=COM42 UNITY_PATH=\Unity test_can_connected2_node2 monitor
make FQBN=Infineon:xmc:XMC1400_XMC2GO PORT=COM41 UNITY_PATH=\Unity test_can_connected2_node1 monitor


## IIC

# 1 board "talking to itself", wire needed
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM28 UNITY_PATH=\Unity test_wire_connected1_pingpong monitor

# 2 boards
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM85 test_wire_connected2_masterpingpong monitor
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM28 UNITY_
Loading

0 comments on commit ab26621

Please sign in to comment.