Skip to content

Commit

Permalink
[Infineon]Add All-Clusters example app for P6 platform (#11300)
Browse files Browse the repository at this point in the history
* [Infineon]Add All-Clusters example app for P6 platform

* Address code review comments on zcl callbacks
  • Loading branch information
praveenCY authored Nov 3, 2021
1 parent d920345 commit d5810e5
Show file tree
Hide file tree
Showing 45 changed files with 2,830 additions and 384 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/examples-infineon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ jobs:
timeout-minutes: 10
run: |
scripts/run_in_build_env.sh \
"scripts/build/build_examples.py --no-log-timestamps --target-glob 'infineon-*' build"
"scripts/build/build_examples.py --no-log-timestamps --target 'infineon-p6-lock' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
p6 default lock-app \
out/infineon-p6-lock/chip-p6-lock-example.out
- name: Build all-clusters-app example
timeout-minutes: 10
run: |
scripts/run_in_build_env.sh \
"scripts/build/build_examples.py --no-log-timestamps --target 'infineon-p6-all-clusters' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
p6 default all-clusters-app \
out/infineon-p6-all-clusters/chip-p6-clusters-example.out
- name: Uploading Size Reports
uses: actions/upload-artifact@v2
if: ${{ !env.ACT }}
with:
name: Size,P6-Examples,${{ env.GH_EVENT_PR }},${{ env.GH_EVENT_HASH }},${{ env.GH_EVENT_PARENT }}
path: |
out/infineon-p6-lock/p6-default-lock-app-sizes.json
out/infineon-p6-all-clusters/p6-default-all-clusters-app-sizes.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,6 @@
path = third_party/pybind11/repo
url = https://github.com/pybind/pybind11
branch = stable
[submodule "p6/lwip"]
path = third_party/p6/p6_sdk/libs/lwip
url = https://git.savannah.nongnu.org/git/lwip
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"esp32-devkitc-temperature-measurement",
"esp32-m5stack-all-clusters",
"esp32-m5stack-all-clusters-rpc",
"infineon-p6-all-clusters",
"infineon-p6-lock",
"linux-arm64-all-clusters",
"linux-arm64-all-clusters-ipv6only",
Expand Down
28 changes: 28 additions & 0 deletions examples/all-clusters-app/p6/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
target_cpu = "arm"
target_os = "freertos"

import("//args.gni")
}
109 changes: 109 additions & 0 deletions examples/all-clusters-app/p6/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/p6.gni")

import("${build_root}/config/defaults.gni")
import("${p6_sdk_build_root}/p6_executable.gni")
import("${p6_sdk_build_root}/p6_sdk.gni")

assert(current_os == "freertos")

p6_project_dir = "${chip_root}/examples/all-clusters-app/p6"
examples_plat_dir = "${chip_root}/examples/platform/p6"

declare_args() {
# Dump memory usage at link time.
chip_print_memory_usage = false

# PIN code for PASE session establishment.
setup_pin_code = 20202021

# Monitor & log memory usage at runtime.
enable_heap_monitoring = false
}

p6_sdk_sources("all_clusters_app_sdk_sources") {
include_dirs = [
"${chip_root}/src/platform/P6",
"${p6_project_dir}/include",
"${examples_plat_dir}",
]

defines = [
"BOARD_ID=${p6_board}",
"P6_LOG_ENABLED=1",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setup_pin_code}",
]

sources = [ "${p6_project_dir}/include/CHIPProjectConfig.h" ]

public_configs = [ "${chip_root}/third_party/p6:p6_sdk_config" ]
}

p6_executable("clusters_app") {
include_dirs = []
defines = []
output_name = "chip-p6-clusters-example.out"

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/init_p6Platform.cpp",
"src/AppTask.cpp",
"src/ButtonHandler.cpp",
"src/ClusterManager.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

deps = [
":all_clusters_app_sdk_sources",
"${chip_root}/examples/all-clusters-app/all-clusters-common",
"${chip_root}/examples/common/QRCode",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
]

include_dirs += [
"include",
"${examples_plat_dir}",
"${p6_project_dir}/include",
]

defines = []

if (enable_heap_monitoring) {
sources += [ "${examples_plat_dir}/MemMonitoring.cpp" ]
defines += [ "HEAP_MONITORING" ]
}

if (chip_print_memory_usage) {
ldflags += [
"-Wl,--print-memory-usage",
"-fstack-usage",
]
}

output_dir = root_out_dir
}

group("p6") {
deps = [ ":clusters_app" ]
}

group("default") {
deps = [ ":p6" ]
}
138 changes: 138 additions & 0 deletions examples/all-clusters-app/p6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#CHIP P6 All Clusters Example

An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.

<hr>

- [Matter P6 All Clusters Example](#chip-p6-clusters-example)
- [Introduction](#introduction)
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Setting up Python Controller](#setting-up-python-controller)
- [Commissioning over BLE](#commissioning-over-ble)
- [Notes](#notes)

<hr>

<a name="intro"></a>

## Introduction

The P6 clusters example provides a baseline demonstration of a Cluster control
device, built using Matter and the Infineon Modustoolbox SDK. It can be
controlled by Matter controller over Wi-Fi network.

The P6 device can be commissioned over Bluetooth Low Energy where the device and
the Matter controller will exchange security information with the Rendezvous
procedure. Wi-Fi Network credentials are then provided to the P6 device which
will then join the network.

<a name="building"></a>

## Building

- [Modustoolbox Software](https://www.cypress.com/products/modustoolbox)

Refer to `integrations/docker/images/chip-build-infineon/Dockerfile` or
`scripts/examples/gn_p6_example.sh` for downloading the Software and related
tools.

- Install some additional tools (likely already present for Matter
developers): \$ sudo apt install gcc g++ clang ninja-build python
python3-venv libssl-dev libavahi-client-dev libglib2.0-dev git cmake
python3-pip

- Supported hardware:
[CY8CKIT-062S2-43012](https://www.cypress.com/CY8CKIT-062S2-43012)

* Build the example application:

$ ./scripts/examples/gn_p6_example.sh ./examples/all-clusters-app/p6 out/clusters_app_p6

- To delete generated executable, libraries and object files use:

$ cd ~/connectedhomeip
$ rm -rf out/

<a name="flashing"></a>

## Flashing the Application

- Put CY8CKIT-062S2-43012 board on KitProg3 CMSIS-DAP Mode by pressing the
`MODE SELECT` button. `KITPROG3 STATUS` LED is ON confirms board is in
proper mode.

- On the command line:

$ cd ~/connectedhomeip
$ python3 out/clusters_app_p6/chip-p6-clusters-example.flash.py

<a name="Commissioning and cluster control"></a>

## Commissioning and cluster control

Commissioning can be carried out using BLE.

<a name="Setting up Python Controller"></a>

### Setting up Python Controller

Once P6 is up and running, we need to set up a device controller on Raspberry Pi
4 to perform commissioning and cluster control.

- Set up python controller.

$ cd {path-to-connectedhomeip}
$ ./scripts/build_python.sh -m platform

- Execute the controller.

$ source ./out/python_env/bin/activate
$ chip-device-ctrl

<a name="Commissioning over BLE"></a>

### Commissioning over BLE

- Establish the secure session over BLE.

- chip-device-ctrl > ble-scan
- chip-device-ctrl > connect -ble 3840 20202021 1234

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: Optional.
If not passed in this command, then it is auto-generated by the controller and
displayed in the output of connect.
The same value should be used in the next commands.
We have chosen a random node ID which is 1234.

- Add credentials of the Wi-Fi network you want the P6 to connect to, using
the `AddWiFiNetwork` command and then enable the P6 to connect to it using
`EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID` and
`WIFI_PASSWORD` as the SSID and passphrase respectively.

- chip-device-ctrl > zcl NetworkCommissioning AddWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0 timeoutMs=1000

- chip-device-ctrl > zcl NetworkCommissioning EnableNetwork 1234 0 0 networkID=str:WIFI_SSID breadcrumb=0 timeoutMs=1000

- Close the BLE connection to P6, as it is not required hereafter.

- chip-device-ctrl > close-ble

- Resolve DNS-SD name and update address of the node in the device controller.

- chip-device-ctrl > resolve 1234

<a name="Notes"></a>

#### Notes

Raspberry Pi 4 BLE connection issues can be avoided by running the following
commands. These power cycle the BlueTooth hardware and disable BR/EDR mode.

$ sudo btmgmt -i hci0 power off
$ sudo btmgmt -i hci0 bredr off
$ sudo btmgmt -i hci0 power on
20 changes: 20 additions & 0 deletions examples/all-clusters-app/p6/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("${chip_root}/src/platform/P6/args.gni")

p6_target_project =
get_label_info(":all_clusters_app_sdk_sources", "label_no_toolchain")
1 change: 1 addition & 0 deletions examples/all-clusters-app/p6/build_overrides
Loading

0 comments on commit d5810e5

Please sign in to comment.