diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index c84d4038352101..f317901e450aa6 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -572,6 +572,7 @@ fsync ftd fullclean fuzzer +fuzzers fuzztest FW gbl diff --git a/.github/workflows/darwin.yaml b/.github/workflows/darwin.yaml index 360c5bb6963217..9eeac9118ef9d3 100644 --- a/.github/workflows/darwin.yaml +++ b/.github/workflows/darwin.yaml @@ -105,10 +105,9 @@ jobs: run: | scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux out/debug/ota-requestor-app chip_config_network_layer_ble=false non_spec_compliant_ota_action_delay_floor=0 - name: Run Framework Tests - # For now disable unguarded-availability-new warnings because we - # internally use APIs that we are annotating as only available on - # new enough versions. Maybe we should change out deployment - # target versions instead? + # We want to ensure that our log upload runs on timeout, so use a timeout here shorter + # than the 6-hour overall job timeout. 4.5 hours should be plenty. + timeout-minutes: 270 working-directory: src/darwin/Framework run: | mkdir -p /tmp/darwin/framework-tests diff --git a/.github/workflows/examples-nxp.yaml b/.github/workflows/examples-nxp.yaml index 050751457645d4..d09e893f2909dd 100644 --- a/.github/workflows/examples-nxp.yaml +++ b/.github/workflows/examples-nxp.yaml @@ -140,6 +140,60 @@ jobs: if: ${{ !env.ACT }} with: platform-name: K32W1 + mcxw71: + name: MCXW71 + + env: + BUILD_TYPE: gn_k32w + + runs-on: ubuntu-latest + if: github.actor != 'restyled-io[bot]' + + container: + image: ghcr.io/project-chip/chip-build-nxp:71 + volumes: + - "/tmp/bloat_reports:/tmp/bloat_reports" + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Checkout submodules & Bootstrap + uses: ./.github/actions/checkout-submodules-and-bootstrap + with: + platform: nxp + extra-submodule-parameters: --recursive + + - name: Set up environment for size reports + uses: ./.github/actions/setup-size-reports + if: ${{ !env.ACT }} + with: + gh-context: ${{ toJson(github) }} + + - name: Build examples + run: | + scripts/run_in_build_env.sh "\ + ./scripts/build/build_examples.py \ + --target nxp-mcxw71-freertos-lighting \ + --target nxp-mcxw71-freertos-contact-sensor-low-power \ + build \ + --copy-artifacts-to out/artifacts \ + " + - name: Get lighting app size stats + run: | + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + nxp mcxw71+release light \ + out/artifacts/nxp-mcxw71-freertos-lighting/chip-mcxw71-light-example.elf \ + /tmp/bloat_reports/ + - name: Get contact sensor size stats + run: | + .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ + nxp mcxw71+release contact \ + out/artifacts/nxp-mcxw71-freertos-contact-sensor-low-power/chip-mcxw71-contact-example.elf \ + /tmp/bloat_reports/ + - name: Uploading Size Reports + uses: ./.github/actions/upload-size-reports + if: ${{ !env.ACT }} + with: + platform-name: MCXW71 rw61x: name: RW61X diff --git a/docs/guides/nxp/nxp_manufacturing_flow.md b/docs/guides/nxp/nxp_manufacturing_flow.md index cb8431cc3b3083..0551d43966f08e 100644 --- a/docs/guides/nxp/nxp_manufacturing_flow.md +++ b/docs/guides/nxp/nxp_manufacturing_flow.md @@ -132,6 +132,7 @@ Here is the interpretation of the **optional** parameters: --unique_id -> Unique id used for rotating device id generation --product_finish -> Visible finish of the product --product_primary_color -> Representative color of the visible parts of the product +--hw_params -> Use application factory data from Hardware Parameters component ``` ## 3. Write provisioning data @@ -144,15 +145,12 @@ DK6Programmer.exe -Y -V2 -s -P 1000000 -Y -p FLASH@0x9D600="factory_d ``` For **K32W1** platform, the binary needs to be written in the internal flash at -location given by `__MATTER_FACTORY_DATA_START`, using `JLink`: +location given by **0xFE080**, using `JLink`: ``` -loadfile factory_data.bin 0xf4000 +loadfile factory_data.bin 0xFE080 ``` -where `0xf4000` is the value of `__MATTER_FACTORY_DATA_START` in the -corresponding .map file (can be different if using a custom linker script). - For **RW61X** platform, the binary needs to be written in the internal flash at location given by `__MATTER_FACTORY_DATA_START`, using `JLink`: @@ -208,7 +206,7 @@ Also, demo **DAC**, **PAI** and **PAA** certificates needed in case Supported platforms: -- K32W1 - `src/plaftorm/nxp/k32w/k32w1/FactoryDataProviderImpl.h` +- K32W1 - `src/plaftorm/nxp/k32w1/FactoryDataProviderImpl.h` For platforms that have a secure subsystem (`SSS`), the DAC private key can be converted to an encrypted blob. This blob will overwrite the DAC private key in @@ -219,6 +217,12 @@ The application will check at initialization whether the DAC private key has been converted or not and convert it if needed. However, the conversion process should be done at manufacturing time for security reasons. +Reference factory data generation command: + +```shell +python3 ./scripts/tools/nxp/factory_data_generator/generate.py -i 10000 -s UXKLzwHdN3DZZLBaL2iVGhQi/OoQwIwJRQV4rpEalbA= -p 14014 -d 1000 --vid "0x1037" --pid "0xA221" --vendor_name "NXP Semiconductors" --product_name "Lighting app" --serial_num "12345678" --date "2023-01-01" --hw_version 1 --hw_version_str "1.0" --cert_declaration ./Chip-Test-CD-1037-A221.der --dac_cert ./Chip-DAC-NXP-1037-A221-Cert.der --dac_key ./Chip-DAC-NXP-1037-A221-Key.der --pai_cert ./Chip-PAI-NXP-1037-A221-Cert.der --spake2p_path ./out/spake2p --unique_id "00112233445566778899aabbccddeeff" --hw_params --out ./factory_data.bin +``` + There is no need for an extra binary. - Write factory data binary. diff --git a/docs/testing/fuzz_testing.md b/docs/testing/fuzz_testing.md index b7faeae463a10e..7660e18032ef9a 100644 --- a/docs/testing/fuzz_testing.md +++ b/docs/testing/fuzz_testing.md @@ -7,13 +7,119 @@ thousands of different inputs. - Fuzz testing is often done with sanitizers enabled; to catch memory errors and undefined behavior. -- The most commonly used fuzz testing frameworks for C/C++ are LibFuzzer and +- The most commonly used fuzz testing frameworks for C/C++ are libFuzzer and AFL. - [Google's FuzzTest](https://github.com/google/fuzztest) is a newer framework that simplifies writing fuzz tests with user-friendly APIs and offers more control over input generation. It also integrates seamlessly with Google Test (GTest). +## Fuzz testing with libFuzzer + +The following example demonstrates how to use libFuzzer to write a simple fuzz +test. Each fuzzer function is defined using +`LLVMFuzzerTestOneInput(const uint8_t * data, size_t len)`. + +The Fuzzer must be located in a Test Folder : `src/some_directory/tests/` + +``` +#include +#include + +/** + * @file + * This file describes a Fuzzer for ... + */ + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t len) +{ + + // Instantiate values as needed + // Call target function for the fuzzer with the fuzzing input (data and len) + + return 0; +} + +``` + +See +[FuzzBase38Decode.cpp](https://github.com/project-chip/connectedhomeip/blob/master/src/setup_payload/tests/FuzzBase38Decode.cpp) +for an example of a simple fuzz test. + +### Compiling and running + +- Add to `src/some_directory/tests/BUILD.gn` + + - Example + + ``` + import("${chip_root}/build/chip/fuzz_test.gni") + + if (enable_fuzz_test_targets) { + chip_fuzz_target("FuzzTargetName1") { + sources = [ "Fuzzer1.cpp" ] + public_deps = [ + // Dependencies go here. + ] + } + chip_fuzz_target("FuzzTargetName2") { + sources = [ "Fuzzer2.cpp" ] + public_deps = [ + // Dependencies go here. + ] + } + } + ``` + + - CHIP_FUZZ_TARGET : the name of the fuzz target + - SOURCES : file in the test folder containing the fuzzer + implementation + - PUBLIC_DEPS : Code Dependencies needed to build fuzzer + + - Another example: + [src/setup_payload/tests/BUILD.gn](https://github.com/project-chip/connectedhomeip/blob/b367512f519e5e109346e81a0d84fd85cd9192f7/src/setup_payload/tests/BUILD.gn#L43) + +- Add to `src/BUILD.gn` + + - Add the Fuzzing Target in this part of the code : + [src/BUILD.gn](https://github.com/project-chip/connectedhomeip/blob/b367512f519e5e109346e81a0d84fd85cd9192f7/BUILD.gn#L52) + + - Add Fuzzing Target like that + + ``` + if (enable_fuzz_test_targets) { + group("fuzz_tests") { + deps = [ + "${chip_root}/src/credentials/tests:fuzz-chip-cert", + "${chip_root}/src/lib/core/tests:fuzz-tlv-reader", + "${chip_root}/src/lib/dnssd/minimal_mdns/tests:fuzz-minmdns-packet-parsing", + "${chip_root}/src/lib/format/tests:fuzz-payload-decoder", + "${chip_root}/src/setup_payload/tests:fuzz-setup-payload-base38", + "${chip_root}/src/setup_payload/tests:fuzz-setup-payload-base38-decode", + // ADD HERE YOUR FUZZING TARGET + "${chip_root}/some_directory/tests:FuzzTargetName" + ] + } + } + ``` + +- Build all fuzzers + ``` + ./scripts/build/build_examples.py --target --tests-asan-libfuzzer-clang build + ``` + e.g. + ``` + ./scripts/build/build_examples.py --target darwin-arm64-tests-asan-libfuzzer-clang build + ``` + \*\* Make sure to put the right host and compiler +- Fuzzers binaries are compiled into: + + - `out/--tests-asan-libfuzzer-clang/tests` + - e.g. `darwin-arm64-tests-asan-libfuzzer-clang` + +- Running the fuzzer with a corpus + - `path_to_fuzzer_in_test_folder path_to_corpus` + ## `Google's FuzzTest` - Google FuzzTest is integrated through Pigweed diff --git a/examples/chef/common/chef-operational-state-delegate-impl.cpp b/examples/chef/common/chef-operational-state-delegate-impl.cpp index 2692417915d785..eedd141dc3b2e4 100644 --- a/examples/chef/common/chef-operational-state-delegate-impl.cpp +++ b/examples/chef/common/chef-operational-state-delegate-impl.cpp @@ -58,6 +58,7 @@ void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperat auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)); if (error == CHIP_NO_ERROR) { + GetInstance()->UpdateCountdownTimeFromDelegate(); err.Set(to_underlying(ErrorStateEnum::kNoError)); } else @@ -72,6 +73,7 @@ void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOpera auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); if (error == CHIP_NO_ERROR) { + GetInstance()->UpdateCountdownTimeFromDelegate(); err.Set(to_underlying(ErrorStateEnum::kNoError)); } else @@ -95,6 +97,7 @@ void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperat auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); if (error == CHIP_NO_ERROR) { + GetInstance()->UpdateCountdownTimeFromDelegate(); (void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, this); err.Set(to_underlying(ErrorStateEnum::kNoError)); } @@ -112,6 +115,8 @@ void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperati { (void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, this); + GetInstance()->UpdateCountdownTimeFromDelegate(); + OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError)); GetInstance()->GetCurrentOperationalError(current_err); @@ -151,6 +156,11 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data delegate->mPausedTime++; } } + else if (!countdown_time.IsNull() && countdown_time.Value() <= 0) + { + OperationalState::GenericOperationalError noError(to_underlying(OperationalState::ErrorStateEnum::kNoError)); + delegate->HandleStopStateCallback(noError); + } if (state == OperationalState::OperationalStateEnum::kRunning || state == OperationalState::OperationalStateEnum::kPaused) { @@ -172,6 +182,11 @@ OperationalState::Instance * OperationalState::GetOperationalStateInstance() return gOperationalStateInstance; } +OperationalStateDelegate * OperationalState::GetOperationalStateDelegate() +{ + return gOperationalStateDelegate; +} + void OperationalState::Shutdown() { if (gOperationalStateInstance != nullptr) diff --git a/examples/chef/common/chef-operational-state-delegate-impl.h b/examples/chef/common/chef-operational-state-delegate-impl.h index 60b6b09e9b6511..badadd68cd30a9 100644 --- a/examples/chef/common/chef-operational-state-delegate-impl.h +++ b/examples/chef/common/chef-operational-state-delegate-impl.h @@ -138,6 +138,7 @@ class OperationalStateDelegate : public GenericOperationalStateDelegateImpl }; Instance * GetOperationalStateInstance(); +OperationalStateDelegate * GetOperationalStateDelegate(); void Shutdown(); diff --git a/examples/contact-sensor-app/nxp/README.md b/examples/contact-sensor-app/nxp/README.md index 473afb793f9700..133539e44ce3ec 100644 --- a/examples/contact-sensor-app/nxp/README.md +++ b/examples/contact-sensor-app/nxp/README.md @@ -24,6 +24,7 @@ The example is based on: ## Supported devices - [k32w1](k32w1/README.md) +- [mcxw71](mcxw71/README.md) ## Introduction diff --git a/examples/contact-sensor-app/nxp/mcxw71/.gn b/examples/contact-sensor-app/nxp/mcxw71/.gn new file mode 100644 index 00000000000000..146e2b9c27ec06 --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2020-2024 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") + + # Import default platform configs + import("${chip_root}/src/platform/nxp/mcxw71_k32w1/args.gni") +} diff --git a/examples/contact-sensor-app/nxp/mcxw71/BUILD.gn b/examples/contact-sensor-app/nxp/mcxw71/BUILD.gn new file mode 100644 index 00000000000000..02a0d7a78768dc --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/BUILD.gn @@ -0,0 +1,260 @@ +# Copyright (c) 2021-2024 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/nxp_sdk.gni") +import("//build_overrides/openthread.gni") + +import("${nxp_sdk_build_root}/nxp_sdk.gni") + +import("${nxp_sdk_build_root}/${nxp_sdk_name}/nxp_executable.gni") + +import("${nxp_sdk_build_root}/${nxp_sdk_name}/${nxp_sdk_name}.gni") + +import("${chip_root}/src/app/icd/icd.gni") +import("${chip_root}/src/crypto/crypto.gni") +import("${chip_root}/src/platform/device.gni") +import("${chip_root}/src/platform/nxp/${nxp_platform}/args.gni") + +declare_args() { + # Setup discriminator as argument + setup_discriminator = 3840 + chip_with_diag_logs_demo = true +} + +assert(current_os == "freertos") +assert(target_os == "freertos") + +example_platform_dir = "${chip_root}/examples/platform/nxp/${nxp_platform}" +common_example_dir = "${chip_root}/examples/platform/nxp/common" + +mcxw71_k32w1_sdk("sdk") { + defines = [] + include_dirs = [] + sources = [] + + # Indicate the path to CHIPProjectConfig.h + include_dirs += [ "include/config" ] + + # Indicate the default path to FreeRTOSConfig.h + include_dirs += [ "${example_platform_dir}/app/project_include/freeRTOS" ] + + # Indicate the default path to OpenThreadConfig.h + include_dirs += [ "${example_platform_dir}/app/project_include/openthread" ] + + include_dirs += [ + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/MCXW716C", + ] + + sources += [ + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/MCXW716C/clock_config.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/MCXW716C/pin_mux.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/app_services_init.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_comp.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_dcdc.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_extflash.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_lp.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/hardware_init.c", + ] + + if (is_debug) { + defines += [ "BUILD_RELEASE=0" ] + } else { + defines += [ "BUILD_RELEASE=1" ] + } + + defines += [ + "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setup_discriminator}", + ] + + if (chip_key_storage == "littlefs") { + include_dirs += [ "${example_platform_dir}/board" ] + sources += [ + "${example_platform_dir}/board/peripherals.c", + "${example_platform_dir}/board/peripherals.h", + ] + } +} + +mcxw71_k32w1_executable("contact_sensor_app") { + output_name = "chip-mcxw71-contact-example" + + defines = [] + deps = [] + include_dirs = [] + sources = [] + + # Defines used by common code + defines += [ + "CONFIG_NET_L2_OPENTHREAD=1", + "CONFIG_NETWORK_LAYER_BLE=1", + "CONFIG_THREAD_DEVICE_TYPE=kThreadDeviceType_SleepyEndDevice", + "CONFIG_OPERATIONAL_KEYSTORE=1", + "EXTERNAL_FACTORY_DATA_PROVIDER_HEADER=\"platform/nxp/common/legacy/FactoryDataProvider.h\"", + ] + + if (chip_with_diag_logs_demo) { + defines += [ "CONFIG_DIAG_LOGS_DEMO=1" ] + } + + if (chip_with_low_power == 1) { + defines += [ "CONFIG_LOW_POWER=1" ] + } else { + defines += [ + "CONFIG_ENABLE_FEEDBACK=1", + "APP_QUEUE_TICKS_TO_WAIT=pdMS_TO_TICKS(10)", + ] + } + + # App common files + include_dirs += [ + "${common_example_dir}/app_task/include", + "${common_example_dir}/matter_button/include", + "${common_example_dir}/clusters/include", + "${common_example_dir}/device_callbacks/include", + "${common_example_dir}/device_manager/include", + "${common_example_dir}/diagnostic_logs/include", + "${common_example_dir}/factory_data/include", + "${common_example_dir}/led_widget/include", + "${common_example_dir}/low_power/include", + "${common_example_dir}/operational_keystore/include", + "${common_example_dir}/ui_feedback/include", + ] + + sources += [ + "${common_example_dir}/app_task/source/AppTaskBase.cpp", + "${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp", + "${common_example_dir}/clusters/source/ZclCallbacks.cpp", + "${common_example_dir}/device_callbacks/source/CommonDeviceCallbacks.cpp", + "${common_example_dir}/device_manager/source/CHIPDeviceManager.cpp", + "${example_platform_dir}/factory_data/source/AppFactoryDataExample.cpp", + ] + + if (chip_with_low_power == 1) { + sources += [ "${common_example_dir}/low_power/source/LowPower.cpp" ] + } + + if (chip_with_factory_data == 1) { + include_dirs += [ "${chip_root}/src/platform/nxp/common/legacy" ] + deps += [ "${chip_root}/src/platform/nxp:nxp_factory_data" ] + } + + if (chip_enable_ota_requestor) { + defines += [ + "CONFIG_CHIP_OTA_IMAGE_PROCESSOR_HEADER=\"platform/nxp/common/legacy/OTAImageProcessorImpl.h\"", + + # The status LED and the external flash CS pin are wired together. The OTA image writing may fail if used together. + "LED_MANAGER_ENABLE_STATUS_LED=0", + ] + + include_dirs += [ "${common_example_dir}/ota_requestor/include" ] + sources += [ "${common_example_dir}/ota_requestor/source/OTARequestorInitiatorMultiImage.cpp" ] + deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ] + } + + if (chip_with_diag_logs_demo) { + sources += [ + "${common_example_dir}/diagnostic_logs/source/DiagnosticLogsDemo.cpp", + "${common_example_dir}/diagnostic_logs/source/DiagnosticLogsProviderDelegateImpl.cpp", + ] + } + + # Platform specific files + include_dirs += [ + "${example_platform_dir}/util", + "${example_platform_dir}/app/support", + "${example_platform_dir}/button", + ] + + sources += [ + "${example_platform_dir}/button/ButtonManager.cpp", + "${example_platform_dir}/clusters/Identify.cpp", + "${example_platform_dir}/operational_keystore/OperationalKeystore.cpp", + ] + + if (chip_enable_ota_requestor) { + sources += [ "${example_platform_dir}/ota/OtaUtils.cpp" ] + } + + include_dirs += [ + "include/config", + "../common/include", + ] + + sources += [ + "../common/AppTask.cpp", + "../common/DeviceCallbacks.cpp", + "../common/ZclCallbacks.cpp", + "../common/main.cpp", + ] + + if (chip_with_low_power == 0) { + sources += [ + "${common_example_dir}/ui_feedback/source/LedManager.cpp", + "${example_platform_dir}/util/LedOnOff.cpp", + ] + } + + deps += [ + "${chip_root}/examples/providers:device_info_provider", + "${chip_root}/src/platform/logging:default", + ] + + #lit and sit are using different zap files + if (chip_enable_icd_lit) { + deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-lit/" ] + } else { + deps += [ "${chip_root}/examples/contact-sensor-app/nxp/zap-sit/" ] + } + + if (chip_openthread_ftd) { + deps += [ + "${openthread_root}:libopenthread-cli-ftd", + "${openthread_root}:libopenthread-ftd", + ] + } else { + deps += [ + "${openthread_root}:libopenthread-cli-mtd", + "${openthread_root}:libopenthread-mtd", + ] + } + + cflags = [ "-Wconversion" ] + + ldscript = "${nxp_sdk_root}/middleware/wireless/framework/Common/devices/kw45_k32w1/gcc/connectivity.ld" + + inputs = [ ldscript ] + + ldflags = [ + "-Wl,--defsym=__heap_size__=0", + "-Wl,--defsym=__stack_size__=0x480", + "-Wl,--defsym=lp_ram_lower_limit=0x04000000", + "-Wl,--defsym=lp_ram_upper_limit=0x2001C000", + "-Wl,-print-memory-usage", + "-Wl,--no-warn-rwx-segments", + "-T" + rebase_path(ldscript, root_build_dir), + ] + + if (chip_with_factory_data == 1) { + ldflags += [ "-Wl,--defsym=gUseFactoryData_d=1" ] + } + + output_dir = root_out_dir +} + +group("default") { + deps = [ ":contact_sensor_app" ] +} diff --git a/examples/contact-sensor-app/nxp/mcxw71/README.md b/examples/contact-sensor-app/nxp/mcxw71/README.md new file mode 100644 index 00000000000000..50d33e10e1b841 --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/README.md @@ -0,0 +1,194 @@ +# Matter `MCXW71` Contact Sensor Example Application + +For generic information related to contact sensor application, please see the +[common README](../README.md). + +- [Matter `MCXW71` Contact Sensor Example Application](#matter-mcxw71-contact-sensor-example-application) + - [Introduction](#introduction) + - [Device UI](#device-ui) + - [Building](#building) + - [Flashing](#flashing) + - [Flashing the `NBU` image](#flashing-the-nbu-image) + - [Flashing the host image](#flashing-the-host-image) + - [Debugging](#debugging) + - [OTA](#ota) + +## Introduction + +This is a contact sensor application implemented for an `mcxw71` device. + +The following board was used when testing this Matter reference app for an +`mcxw71` device: +![FRDM-MCXW71](../../../platform/nxp/mcxw71_k32w1/doc/images/frdm-mcxw71.jpg) + +## Device UI + +The state feedback is provided through LED effects: + +| widget | effect | description | +| ------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------- | +| LED2 | short flash on (50ms on/950ms off) | The device is in an unprovisioned (unpaired) state and is waiting for a commissioner to connect. | +| LED2 | rapid even flashing (100ms period) | The device is in an unprovisioned state and a commissioner is connected via BLE. | +| LED2 | short flash off (950ms on/50ms off) | The device is fully provisioned, but does not yet have full network (Thread) or service connectivity. | +| LED2 | solid on | The device is fully provisioned and has full network and service connectivity. | +| RGB LED | on | The `StateValue` attribute of the `BooleanState` cluster is `true` (simulating detection). | +| RGB LED | off | The `StateValue` attribute of the `BooleanState` cluster is `false` (simulating no detection). | + +NOTE: `LED2` will be disabled when OTA is used. On `FRDM-MCXW71` board, `PTB0` +is wired to both `LED2` and CS (Chip Select) of the External Flash Memory. Since +the OTA image is stored in external memory, `LED2` operations will affect OTA +operation by corrupting packages and OTA will not work. + +The user actions are summarized below: + +| button | action | state | output | +| ------ | ----------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| SW2 | short press | not commissioned | Enable BLE advertising | +| SW2 | short press | commissioned + device is LIT | Enable Active Mode | +| SW2 | long press | NA | Initiate a factory reset (can be cancelled by pressing the button again within the factory reset timeout limit - 6 seconds by default) | +| SW3 | short press | NA | Toggle attribute `StateValue` value | +| SW3 | long press | NA | Clean soft reset of the device (takes into account proper Matter shutdown procedure) | + +## Building + +Manually building requires running the following commands: + +``` +user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/contact-sensor-app/nxp/mcxw71 +user@ubuntu:~/Desktop/git/connectedhomeip/examples/contact-sensor-app/nxp/mcxw71$ gn gen out/debug +user@ubuntu:~/Desktop/git/connectedhomeip/examples/contact-sensor-app/nxp/mcxw71$ ninja -C out/debug +``` + +Please note that running `gn gen out/debug` without `--args` option will use the +default gn args values found in `args.gni`. + +After a successful build, the `elf` and `srec` files are found in `out/debug/`. +See the files prefixed with `chip-mcxw71-contact-example`. + +## Flashing + +Two images must be written to the board: one for the host (CM33) and one for the +`NBU` (CM3). + +### Flashing the `NBU` image + +`NBU` image should be written only when a new NXP SDK is released. + +1. Install + [Secure Provisioning SDK tool](https://www.nxp.com/design/design-center/software/development-software/secure-provisioning-sdk-spsdk:SPSDK) + using Python: + + ``` + pip install spsdk + ``` + + Note: There might be some dependencies that cause conflicts with already + installed Python modules. However, `blhost` tool is still installed and can + be used. + +2. Updating `NBU` for Wireless examples + + It is necessary to work with the matching `NBU` image for the SDK version of + the application you are working with. This means that when you download your + SDK, prior to loading any wireless SDK example, update your `NBU` image with + the SDK provided binaries. For `FRDM` users, please write the following + binary: + + `middleware\wireless\ieee-802.15.4\bin\mcxw71\mcxw71_nbu_ble_15_4_dyn_matter_.sb3` + + Please note that `` may vary depending on the SDK version. + + 1. Place your device in `ISP` mode. + + - Make sure a jumper is placed on `JP25` + - Press and hold `SW4`, press and release Reset, then release `SW4` + + 2. Once the device is connected, you may find the assigned port by running: + + ``` + nxpdevscan + ``` + + 3. Run the `blhost` command to write the `sb3` file: + + ``` + blhost -p receive-sb-file \middleware\wireless\ieee-802.15.4\bin\mcxw71\mcxw71_nbu_ble_15_4_dyn_matter_.sb3 + ``` + +### Flashing the host image + +Host image is the one found under `out/debug/`. It should be written after each +build process. + +If debugging is needed then jump directly to the [Debugging](#debugging) +section. Otherwise, if only flashing is needed then +[JLink](https://www.segger.com/downloads/jlink/) can be used: + +- Plug `MCXW71` to the USB port (no need to keep the `SW4` button pressed + while doing this, e.g. ISP mode is not needed for host flashing) + +- Connect JLink to the device: + + ```bash + JLinkExe -device MCXW71 -if SWD -speed 4000 -autoconnect 1 + ``` + +- Run the following commands: + ```bash + reset + halt + loadfile chip-mcxw71-contact-example.srec + reset + go + quit + ``` + +## Debugging + +One option for debugging would be to use MCUXpresso IDE. + +- Drag-and-drop the zip file containing the NXP SDK in the "Installed SDKs" + tab: + +![Installed SDKs](../../../platform/nxp/mcxw71_k32w1/doc/images/mcxw71_installed_sdks.jpg) + +- Import any demo application from the installed SDK: + +``` +Import SDK example(s).. -> choose a demo app (demo_apps -> hello_world) -> Finish +``` + +![Import demo](../../../platform/nxp/mcxw71_k32w1/doc/images/import_demo.jpg) + +- Flash the previously imported demo application on the board: + +``` +Right click on the application (from Project Explorer) -> Debug as -> JLink/CMSIS-DAP +``` + +After this step, a debug configuration specific for the `MCXW71` board was +created. This debug configuration will be used later on for debugging the +application resulted after ot-nxp compilation. + +- Import Matter repo in MCUXpresso IDE as Makefile Project. Use _none_ as + _Toolchain for Indexer Settings_: + +``` +File -> Import -> C/C++ -> Existing Code as Makefile Project +``` + +![New Project](../../../platform/nxp/mcxw71_k32w1/doc/images/new_project.jpg) + +- Replace the path of the existing demo application with the path of the + `MCXW71` application: + +``` +Run -> Debug Configurations... -> C/C++ Application +``` + +![](../../../platform/nxp/mcxw71_k32w1/doc/images/mcxw71_debug.jpg) + +## OTA + +Please see +[mcxw71 OTA guide](../../../../docs/guides/nxp/nxp_mcxw71_ota_guide.md). diff --git a/examples/contact-sensor-app/nxp/mcxw71/args.gni b/examples/contact-sensor-app/nxp/mcxw71/args.gni new file mode 100644 index 00000000000000..72634a2308d04b --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/args.gni @@ -0,0 +1,43 @@ +# Copyright (c) 2020-2024 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("${chip_root}/config/standalone/args.gni") + +# SDK target. This is overridden to add our SDK app_config.h & defines. +nxp_sdk_target = get_label_info(":sdk", "label_no_toolchain") +nxp_device = "MCXW716C" + +chip_enable_ota_requestor = true +chip_stack_lock_tracking = "fatal" +chip_enable_ble = true +chip_generate_link_map_file = true + +chip_system_config_provide_statistics = false +chip_system_config_use_open_thread_inet_endpoints = true +chip_with_lwip = false + +chip_enable_icd_server = true +chip_enable_icd_lit = false +icd_enforce_sit_slow_poll_limit = true +chip_persist_subscriptions = true +chip_subscription_timeout_resumption = true + +is_debug = false + +chip_crypto = "platform" +chip_openthread_ftd = false +chip_with_ot_cli = 0 + +chip_with_diag_logs_demo = true diff --git a/examples/contact-sensor-app/nxp/mcxw71/build_overrides b/examples/contact-sensor-app/nxp/mcxw71/build_overrides new file mode 120000 index 00000000000000..ee19c065d619a2 --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/build_overrides @@ -0,0 +1 @@ +../../../build_overrides/ \ No newline at end of file diff --git a/examples/contact-sensor-app/nxp/mcxw71/include/config/AppConfig.h b/examples/contact-sensor-app/nxp/mcxw71/include/config/AppConfig.h new file mode 100644 index 00000000000000..0c8019d8e7e33c --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/include/config/AppConfig.h @@ -0,0 +1,29 @@ +/* + * Copyright 2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#pragma once + +/* ---- App Config ---- */ +#define APP_DEVICE_TYPE_ENDPOINT 1 +#define APP_CLUSTER_ATTRIBUTE chip::app::Clusters::BooleanState::Attributes::StateValue + +/* ---- Button Manager Config ---- */ +#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000 + +/* ---- LED Manager Config ---- */ +#define LED_MANAGER_STATUS_LED_INDEX 0 +#define LED_MANAGER_LIGHT_LED_INDEX 1 diff --git a/examples/contact-sensor-app/nxp/mcxw71/include/config/CHIPProjectConfig.h b/examples/contact-sensor-app/nxp/mcxw71/include/config/CHIPProjectConfig.h new file mode 100644 index 00000000000000..9e5cee6eb7b695 --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/include/config/CHIPProjectConfig.h @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2020-2023 Project CHIP Authors + * Copyright (c) 2020 Google LLC. + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#pragma once + +// Use hard-coded test certificates already embedded in generic chip code => set it to 0 +// Use real/development certificates => set it to 1 + file the provisioning section from +// the internal flash +#ifndef CONFIG_CHIP_LOAD_REAL_FACTORY_DATA +#define CONFIG_CHIP_LOAD_REAL_FACTORY_DATA 0 +#endif + +#if CONFIG_CHIP_LOAD_REAL_FACTORY_DATA + +// VID/PID for product => will be used by Basic Information Cluster +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x1037 +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0xA401 + +// Set the following define to use the Certification Declaration from below and not use it stored in factory data section +#ifndef CHIP_USE_DEVICE_CONFIG_CERTIFICATION_DECLARATION +#define CHIP_USE_DEVICE_CONFIG_CERTIFICATION_DECLARATION 0 +#endif + +#ifndef CHIP_DEVICE_CONFIG_CERTIFICATION_DECLARATION +//-> format_version = 1 +//-> vendor_id = 0x1037 +//-> product_id_array = [ 0xA401 ] +//-> device_type_id = 0x0015 +//-> certificate_id = "ZIG20142ZB330003-24" +//-> security_level = 0 +//-> security_information = 0 +//-> version_number = 0x2694 +//-> certification_type = 1 +//-> dac_origin_vendor_id is not present +//-> dac_origin_product_id is not present +#define CHIP_DEVICE_CONFIG_CERTIFICATION_DECLARATION \ + { \ + 0x30, 0x81, 0xe7, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x81, 0xd9, 0x30, 0x81, 0xd6, \ + 0x02, 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, \ + 0x44, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x37, 0x04, 0x35, 0x15, 0x24, 0x00, \ + 0x01, 0x25, 0x01, 0x37, 0x10, 0x36, 0x02, 0x05, 0x01, 0xa4, 0x18, 0x24, 0x03, 0x15, 0x2c, 0x04, 0x13, 0x5a, 0x49, \ + 0x47, 0x32, 0x30, 0x31, 0x34, 0x32, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, 0x33, 0x2d, 0x32, 0x34, 0x24, 0x05, \ + 0x00, 0x24, 0x06, 0x00, 0x25, 0x07, 0x76, 0x98, 0x24, 0x08, 0x01, 0x18, 0x31, 0x7c, 0x30, 0x7a, 0x02, 0x01, 0x03, \ + 0x80, 0x14, 0x62, 0xfa, 0x82, 0x33, 0x59, 0xac, 0xfa, 0xa9, 0x96, 0x3e, 0x1c, 0xfa, 0x14, 0x0a, 0xdd, 0xf5, 0x04, \ + 0xf3, 0x71, 0x60, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x0a, 0x06, \ + 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x04, 0x46, 0x30, 0x44, 0x02, 0x20, 0x12, 0xec, 0x79, 0xdc, \ + 0x03, 0xd3, 0x4f, 0xf9, 0x79, 0xef, 0x56, 0x4e, 0x5b, 0x4f, 0xfc, 0xf5, 0xb1, 0x5a, 0xdb, 0xdf, 0xd9, 0xf8, 0x47, \ + 0xff, 0x81, 0xc3, 0x82, 0x2f, 0xa3, 0x2b, 0xb8, 0x3f, 0x02, 0x20, 0x53, 0x0d, 0x5d, 0xbd, 0xc6, 0xa4, 0x80, 0x67, \ + 0x1f, 0x10, 0xfb, 0xab, 0x00, 0x08, 0xee, 0x15, 0xa0, 0x6c, 0x40, 0x97, 0x55, 0x80, 0x28, 0x3e, 0xf3, 0xd9, 0x61, \ + 0x1f, 0x5b, 0x1d, 0x51, 0x02 \ + } + +// All remaining data will be pulled from the provisioning region of flash. +#endif + +#else + +/** + * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID + * + * 0xFFF1: Test vendor. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID + * + */ +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8006 + +// Use a default setup PIN code if one hasn't been provisioned in flash. +#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 +#endif + +#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 +#endif + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" + +/** + * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER + * + * Enables the use of a hard-coded default serial number if none + * is found in CHIP NV storage. + */ +#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" + +#endif // CONFIG_CHIP_LOAD_REAL_FACTORY_DATA + +/** + * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION + * + * The hardware version number assigned to device or product by the device vendor. This + * number is scoped to the device product id, and typically corresponds to a revision of the + * physical device, a change to its packaging, and/or a change to its marketing presentation. + * This value is generally *not* incremented for device software versions. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 100 + +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING +#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING "v0.1.0" +#endif + +/** + * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING + * + * A string identifying the software version running on the device. + * CHIP currently expects the software version to be in the format + * {MAJOR_VERSION}.0d{MINOR_VERSION} + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING NXP_CONFIG_DEVICE_SOFTWARE_VERSION_STRING +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION NXP_CONFIG_DEVICE_SOFTWARE_VERSION +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME "NXP Semiconductors" +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App" +#endif + +/** + * CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_TIMEOUT + * + * The amount of time in miliseconds after which BLE should change his advertisements + * from fast interval to slow interval. + * + * 30000 (30 secondes). + */ +#define CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_TIMEOUT (30 * 1000) + +/** + * CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT + * + * The amount of time in miliseconds after which BLE advertisement should be disabled, counting + * from the moment of slow advertisement commencement. + * + * Defaults to 9000000 (15 minutes). + */ +#define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000) + +/** + * CONFIG_CHIP_NFC_COMMISSIONING, CHIP_DEVICE_CONFIG_ENABLE_NFC + * + * NFC commissioning is not supported on K32W1 + */ +#define CONFIG_CHIP_NFC_COMMISSIONING 0 +#define CHIP_DEVICE_CONFIG_ENABLE_NFC 0 + +/** + * @def CHIP_CONFIG_MAX_FABRICS + * + * @brief + * Maximum number of fabrics the device can participate in. Each fabric can + * provision the device with its unique operational credentials and manage + * its own access control lists. + */ +#define CHIP_CONFIG_MAX_FABRICS 5 // 5 is the minimum number of supported fabrics + +#define CHIP_DEVICE_CONFIG_ENABLE_SED 1 + +/** + * @def CHIP_DEVICE_CONFIG_KVS_WEAR_STATS + * + * @brief Toggle support for key value store wear stats on or off. + */ +#define CHIP_DEVICE_CONFIG_KVS_WEAR_STATS 0 + +/** + * @def CHIP_IM_MAX_NUM_COMMAND_HANDLER + * + * @brief Defines the maximum number of CommandHandler, limits the number of active commands transactions on server. + */ +#define CHIP_IM_MAX_NUM_COMMAND_HANDLER 2 + +/** + * @def CHIP_IM_MAX_NUM_WRITE_HANDLER + * + * @brief Defines the maximum number of WriteHandler, limits the number of active write transactions on server. + */ +#define CHIP_IM_MAX_NUM_WRITE_HANDLER 2 + +/** + * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE + * + * For a development build, set the default importance of events to be logged as Debug. + * Since debug is the lowest importance level, this means all standard, critical, info and + * debug importance level vi events get logged. + */ +#if BUILD_RELEASE +#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Production +#else +#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Debug +#endif // BUILD_RELEASE + +#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 + +#if CONFIG_DIAG_LOGS_DEMO +#define CHIP_CONFIG_ENABLE_BDX_LOG_TRANSFER 1 +#define CHIP_DEVICE_CONFIG_MAX_DIAG_LOG_SIZE 1024 +#endif diff --git a/examples/contact-sensor-app/nxp/mcxw71/third_party/connectedhomeip b/examples/contact-sensor-app/nxp/mcxw71/third_party/connectedhomeip new file mode 120000 index 00000000000000..59307833b4fee9 --- /dev/null +++ b/examples/contact-sensor-app/nxp/mcxw71/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../.. \ No newline at end of file diff --git a/examples/lighting-app/nxp/README.md b/examples/lighting-app/nxp/README.md index 74d0f9dc294813..67444a99e1bf8d 100644 --- a/examples/lighting-app/nxp/README.md +++ b/examples/lighting-app/nxp/README.md @@ -22,6 +22,7 @@ The example is based on: ## Supported devices - [k32w1](k32w1/README.md) +- [mcxw71](mcxw71/README.md) ## Introduction diff --git a/examples/lighting-app/nxp/k32w1/BUILD.gn b/examples/lighting-app/nxp/k32w1/BUILD.gn index 9544ca8486a2ff..541c288dd1eb5c 100644 --- a/examples/lighting-app/nxp/k32w1/BUILD.gn +++ b/examples/lighting-app/nxp/k32w1/BUILD.gn @@ -236,7 +236,7 @@ mcxw71_k32w1_executable("light_app") { } if (use_smu2_static) { - ldscript = "${example_platform_dir}/app/ldscripts/k32w1_app.ld" + ldscript = "${example_platform_dir}/app/ldscripts/app.ld" base_ldscript_dir = "${nxp_sdk_root}/middleware/wireless/framework/Common/devices/kw45_k32w1/gcc" } else { ldscript = "${nxp_sdk_root}/middleware/wireless/framework/Common/devices/kw45_k32w1/gcc/connectivity.ld" diff --git a/examples/lighting-app/nxp/k32w1/README.md b/examples/lighting-app/nxp/k32w1/README.md index ab54aab153e272..c47449bf249490 100644 --- a/examples/lighting-app/nxp/k32w1/README.md +++ b/examples/lighting-app/nxp/k32w1/README.md @@ -78,9 +78,9 @@ and global variables in the shared memory area from `NBU` domain. Note: These instances and global variables are placed in `SMU2` memory through name matching in the application linker script. They should not be changed or, -if changed, the names must be updated in `k32w1_app.ld`. See -[k32w1_app.ld](../../../platform/nxp/k32w1/app/ldscripts/k32w1_app.ld) for names -and `SMU2` memory range size. +if changed, the names must be updated in `app.ld`. See +[app.ld](../../../platform/nxp/mcxw71_k32w1/app/ldscripts/app.ld) for names and +`SMU2` memory range size. When compiling the application as an OT Full Thread Device (`chip_openthread_ftd=true`), using `use_smu2_static=true` gn arg will cause the diff --git a/examples/lighting-app/nxp/mcxw71/.gn b/examples/lighting-app/nxp/mcxw71/.gn new file mode 100644 index 00000000000000..146e2b9c27ec06 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2020-2024 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") + + # Import default platform configs + import("${chip_root}/src/platform/nxp/mcxw71_k32w1/args.gni") +} diff --git a/examples/lighting-app/nxp/mcxw71/BUILD.gn b/examples/lighting-app/nxp/mcxw71/BUILD.gn new file mode 100644 index 00000000000000..34733584a80cd9 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/BUILD.gn @@ -0,0 +1,268 @@ +# Copyright (c) 2024 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/nxp_sdk.gni") +import("//build_overrides/openthread.gni") + +import("${nxp_sdk_build_root}/nxp_sdk.gni") + +import("${nxp_sdk_build_root}/${nxp_sdk_name}/nxp_executable.gni") + +import("${nxp_sdk_build_root}/${nxp_sdk_name}/${nxp_sdk_name}.gni") + +import("${chip_root}/src/crypto/crypto.gni") +import("${chip_root}/src/platform/device.gni") +import("${chip_root}/src/platform/nxp/${nxp_platform}/args.gni") + +import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") + +if (chip_enable_pw_rpc) { + import("//build_overrides/pigweed.gni") + import("$dir_pw_build/target_types.gni") + import("${chip_root}/examples/platform/nxp/pw_rpc_server.gni") +} + +declare_args() { + # Setup discriminator as argument + setup_discriminator = 3840 +} + +assert(current_os == "freertos") +assert(target_os == "freertos") + +example_platform_dir = "${chip_root}/examples/platform/nxp/${nxp_platform}" +common_example_dir = "${chip_root}/examples/platform/nxp/common" + +mcxw71_k32w1_sdk("sdk") { + defines = [] + include_dirs = [] + sources = [] + + # Indicate the path to CHIPProjectConfig.h + include_dirs += [ "include/config" ] + + # Indicate the default path to FreeRTOSConfig.h + include_dirs += [ "${example_platform_dir}/app/project_include/freeRTOS" ] + + # Indicate the default path to OpenThreadConfig.h + include_dirs += [ "${example_platform_dir}/app/project_include/openthread" ] + + include_dirs += [ + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/MCXW716C", + ] + + sources += [ + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/MCXW716C/clock_config.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/MCXW716C/pin_mux.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/app_services_init.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_comp.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_dcdc.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_extflash.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/board_lp.c", + "${nxp_sdk_root}/middleware/wireless/framework/boards/kw45_k32w1/hardware_init.c", + ] + + if (is_debug) { + defines += [ "BUILD_RELEASE=0" ] + } else { + defines += [ "BUILD_RELEASE=1" ] + } + + if (chip_enable_pw_rpc) { + defines += [ + "CONFIG_ENABLE_PW_RPC", + "STREAMER_UART_FLUSH_DELAY_MS=0", + "STREAMER_UART_SERIAL_MANAGER_RING_BUFFER_SIZE=512", + "BOARD_APP_UART_CLK_FREQ=96000000", + ] + } + + defines += [ + "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setup_discriminator}", + ] + + if (chip_key_storage == "littlefs") { + include_dirs += [ "${example_platform_dir}/board" ] + sources += [ + "${example_platform_dir}/board/peripherals.c", + "${example_platform_dir}/board/peripherals.h", + ] + } +} + +mcxw71_k32w1_executable("light_app") { + output_name = "chip-mcxw71-light-example" + + defines = [] + deps = [] + sources = [] + + if (chip_enable_pw_rpc) { + forward_variables_from(pw_rpc_server, "*") + } else { + include_dirs = [] + cflags = [ "-Wconversion" ] + } + + # Defines used by common code + defines += [ + "CONFIG_NET_L2_OPENTHREAD=1", + "CONFIG_NETWORK_LAYER_BLE=1", + "CONFIG_OPERATIONAL_KEYSTORE=1", + "CONFIG_ENABLE_FEEDBACK=1", + "APP_QUEUE_TICKS_TO_WAIT=pdMS_TO_TICKS(10)", + "EXTERNAL_FACTORY_DATA_PROVIDER_HEADER=\"platform/nxp/common/legacy/FactoryDataProvider.h\"", + ] + + # App common files + include_dirs += [ + "${common_example_dir}/app_task/include", + "${common_example_dir}/matter_button/include", + "${common_example_dir}/clusters/include", + "${common_example_dir}/device_callbacks/include", + "${common_example_dir}/device_manager/include", + "${common_example_dir}/factory_data/include", + "${common_example_dir}/led_widget/include", + "${common_example_dir}/operational_keystore/include", + "${common_example_dir}/rpc/include", + "${common_example_dir}/ui_feedback/include", + ] + + sources += [ + "${common_example_dir}/app_task/source/AppTaskBase.cpp", + "${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp", + "${common_example_dir}/clusters/source/ZclCallbacks.cpp", + "${common_example_dir}/device_callbacks/source/CommonDeviceCallbacks.cpp", + "${common_example_dir}/device_manager/source/CHIPDeviceManager.cpp", + "${example_platform_dir}/factory_data/source/AppFactoryDataExample.cpp", + ] + + if (chip_enable_ota_requestor) { + defines += [ + "CONFIG_CHIP_OTA_IMAGE_PROCESSOR_HEADER=\"platform/nxp/common/legacy/OTAImageProcessorImpl.h\"", + + # The status LED and the external flash CS pin are wired together. The OTA image writing may fail if used together. + "LED_MANAGER_ENABLE_STATUS_LED=0", + ] + + include_dirs += [ "${common_example_dir}/ota_requestor/include" ] + sources += [ "${common_example_dir}/ota_requestor/source/OTARequestorInitiatorMultiImage.cpp" ] + deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ] + } + + # Platform specific files + include_dirs += [ + "${example_platform_dir}/util", + "${example_platform_dir}/app/support", + "${example_platform_dir}/button", + ] + + sources += [ + "${example_platform_dir}/button/ButtonManager.cpp", + "${example_platform_dir}/clusters/Identify.cpp", + "${example_platform_dir}/operational_keystore/OperationalKeystore.cpp", + ] + + if (chip_enable_ota_requestor) { + sources += [ "${example_platform_dir}/ota/OtaUtils.cpp" ] + } + + if (chip_enable_pw_rpc) { + sources += [ "${example_platform_dir}/rpc/AppRpc.cpp" ] + } + + if (chip_with_factory_data == 1) { + include_dirs += [ "${chip_root}/src/platform/nxp/common/legacy" ] + deps += [ "${chip_root}/src/platform/nxp:nxp_factory_data" ] + } + + sources += [ + "../common/AppTask.cpp", + "../common/DeviceCallbacks.cpp", + "../common/main.cpp", + ] + + include_dirs += [ + "../common", + "../common/include", + "include/config", + ] + + deps += [ + "${chip_root}/examples/providers:device_info_provider", + "${chip_root}/src/platform/logging:default", + ] + + if (chip_config_dimmable_led) { + defines += [ "LIGHTING_MANAGER_ENABLE_DIMMABLE_LED=1" ] + sources += [ + "${common_example_dir}/led_widget/include/LedDimmer.h", + "${example_platform_dir}/util/LedDimmer.cpp", + "${example_platform_dir}/util/LightingManagerDimmable.cpp", + ] + deps += [ "${chip_root}/examples/lighting-app/lighting-common/" ] + } else { + sources += [ + "${common_example_dir}/ui_feedback/source/LedManager.cpp", + "${example_platform_dir}/util/LedOnOff.cpp", + ] + deps += [ "${chip_root}/examples/lighting-app/nxp/zap/" ] + } + + if (chip_openthread_ftd) { + deps += [ + "${openthread_root}:libopenthread-cli-ftd", + "${openthread_root}:libopenthread-ftd", + ] + } else { + deps += [ + "${openthread_root}:libopenthread-cli-mtd", + "${openthread_root}:libopenthread-mtd", + ] + } + + if (use_smu2_static) { + ldscript = "${example_platform_dir}/app/ldscripts/app.ld" + base_ldscript_dir = "${nxp_sdk_root}/middleware/wireless/framework/Common/devices/kw45_k32w1/gcc" + } else { + ldscript = "${nxp_sdk_root}/middleware/wireless/framework/Common/devices/kw45_k32w1/gcc/connectivity.ld" + } + + inputs = [ ldscript ] + + ldflags = [ + "-Wl,--defsym=__heap_size__=0", + "-Wl,--defsym=__stack_size__=0x480", + "-Wl,-print-memory-usage", + "-Wl,--no-warn-rwx-segments", + "-T" + rebase_path(ldscript, root_build_dir), + ] + + if (chip_with_factory_data == 1) { + ldflags += [ "-Wl,--defsym=gUseFactoryData_d=1" ] + } + + if (use_smu2_static) { + ldflags += [ "-L" + rebase_path(base_ldscript_dir, root_build_dir) ] + } + + output_dir = root_out_dir +} + +group("default") { + deps = [ ":light_app" ] +} diff --git a/examples/lighting-app/nxp/mcxw71/README.md b/examples/lighting-app/nxp/mcxw71/README.md new file mode 100644 index 00000000000000..116fd6183e197d --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/README.md @@ -0,0 +1,270 @@ +# Matter `MCXW71` Lighting Example Application + +For generic information related to on/off light application, please see the +[common README](../README.md). + +- [Matter `MCXW71` Lighting Example Application](#matter-mcxw71-lighting-example-application) + - [Introduction](#introduction) + - [Device UI](#device-ui) + - [Building](#building) + - [`SMU2` Memory](#smu2-memory) + - [LED PWM](#led-pwm) + - [Flashing](#flashing) + - [Flashing the `NBU` image](#flashing-the-nbu-image) + - [Flashing the host image](#flashing-the-host-image) + - [Debugging](#debugging) + - [Running RPC console](#running-rpc-console) + - [OTA](#ota) + +## Introduction + +This is an on/off lighting application implemented for an `mcxw71` device. + +The following board was used when testing this Matter reference app for a +`mcxw71` device: +![FRDM-MCXW71](../../../platform/nxp/mcxw71_k32w1/doc/images/frdm-mcxw71.jpg) + +## Device UI + +The state feedback is provided through LED effects: + +| widget | effect | description | +| ------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------- | +| LED2 | short flash on (50ms on/950ms off) | The device is in an unprovisioned (unpaired) state and is waiting for a commissioner to connect. | +| LED2 | rapid even flashing (100ms period) | The device is in an unprovisioned state and a commissioner is connected via BLE. | +| LED2 | short flash off (950ms on/50ms off) | The device is fully provisioned, but does not yet have full network (Thread) or service connectivity. | +| LED2 | solid on | The device is fully provisioned and has full network and service connectivity. | +| RGB LED | on | The `OnOff` attribute of the `On/Off` cluster is `true` (simulating device turned on). | +| RGB LED | off | The `OnOff` attribute of the `On/Off` cluster is `false` (simulating device turned off). | + +NOTE: `LED2` will be disabled when OTA is used. On `FRDM-MCXW71` board, `PTB0` +is wired to both `LED2` and CS (Chip Select) of the External Flash Memory. Since +the OTA image is stored in external memory, `LED2` operations will affect OTA +operation by corrupting packages and OTA will not work. + +The user actions are summarized below: + +| button | action | output | +| ------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| SW2 | short press | Enable BLE advertising | +| SW2 | long press | Initiate a factory reset (can be cancelled by pressing the button again within the factory reset timeout limit - 6 seconds by default) | +| SW3 | short press | Toggle attribute `OnOff` value | +| SW3 | long press | Clean soft reset of the device (takes into account proper Matter shutdown procedure) | + +The example application provides a simple UI that depicts the state of the +device and offers basic user control. This UI is implemented via the +general-purpose LEDs and buttons built in the `MCXW71` board. + +## Building + +Manually building requires running the following commands: + +``` +user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/lighting-app/nxp/mcxw71 +user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/mcxw71$ gn gen out/debug +user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/mcxw71$ ninja -C out/debug +``` + +Please note that running `gn gen out/debug` without `--args` option will use the +default gn args values found in `args.gni`. + +After a successful build, the `elf` and `srec` files are found in `out/debug/`. +See the files prefixed with `chip-mcxw71-light-example`. + +### `SMU2` Memory + +Additional memory is provided to the application by moving some Matter instances +and global variables in the shared memory area from `NBU` domain. + +Note: These instances and global variables are placed in `SMU2` memory through +name matching in the application linker script. They should not be changed or, +if changed, the names must be updated in `app.ld`. See +[app.ld](../../../platform/nxp/mcxw71_k32w1/app/ldscripts/app.ld) for names and +`SMU2` memory range size. + +When compiling the application as an OT Full Thread Device +(`chip_openthread_ftd=true`), using `use_smu2_static=true` gn arg will cause the +following symbols to be moved to `SMU2` area: + +| symbol name | file | +| ----------------------------------- | ---------------------------- | +| `gImageProcessor` | `OTAImageProcessorImpl.cpp` | +| `gApplicationProcessor` | `OTAHooks.cpp` | +| `Server::sServer` | `Server.cpp` | +| `ThreadStackManagerImpl::sInstance` | `ThreadStackManagerImpl.cpp` | + +Additionally, using `use_smu2_dynamic=true` will cause the OpenThread buffers to +be dynamically allocated from a 13KB `SMU2` range after a successful +commissioning process. + +`use_smu2_static` and `use_smu2_dynamic` are set to `true` in the default +example. + +### LED PWM + +In the default configuration, the onboard RGB LED pins are configured as GPIO +pins. In order to enable the dimming feature, the pins need to be configured in +PWM mode and synced with channels of the `TPM` (Timer PWM Module). To enable +this feature, compile the application with: `chip_config_dimmable_led=true` + +If the feature is enabled, the LED brightness can be controlled using +`LevelControl` cluster +[commands](../../../../docs/guides/chip_tool_guide.md#step-7-control-application-data-model-clusters). + +## Flashing + +Two images must be written to the board: one for the host (CM33) and one for the +`NBU` (CM3). + +The image needed on the host side is the one generated in `out/debug/` while the +one needed on the `NBU` side can be found in the downloaded NXP-SDK package at +path - +`middleware\wireless\ieee-802.15.4\bin\k32w1\k32w1_nbu_ble_15_4_dyn_matter.sb3`. + +### Flashing the `NBU` image + +`NBU` image should be written only when a new NXP SDK is released. + +1. Install + [Secure Provisioning SDK tool](https://www.nxp.com/design/design-center/software/development-software/secure-provisioning-sdk-spsdk:SPSDK) + using Python: + + ``` + pip install spsdk + ``` + + Note: There might be some dependencies that cause conflicts with already + installed Python modules. However, `blhost` tool is still installed and can + be used. + +2. Updating `NBU` for Wireless examples + + It is necessary to work with the matching `NBU` image for the SDK version of + the application you are working with. This means that when you download your + SDK, prior to loading any wireless SDK example, update your `NBU` image with + the SDK provided binaries. For `FRDM` users, please write the following + binary: + + `middleware\wireless\ieee-802.15.4\bin\mcxw71\mcxw71_nbu_ble_15_4_dyn_matter_.sb3` + + Please note that `` may vary depending on the SDK version. + + 1. Place your device in `ISP` mode. + + - Make sure a jumper is placed on `JP25` + - Press and hold `SW4`, press and release Reset, then release `SW4` + + 2. Once the device is connected, you may find the assigned port by running: + + ``` + nxpdevscan + ``` + + 3. Run the `blhost` command to write the `sb3` file: + + ``` + blhost -p receive-sb-file \middleware\wireless\ieee-802.15.4\bin\mcxw71\mcxw71_nbu_ble_15_4_dyn_matter_.sb3 + ``` + +### Flashing the host image + +Host image is the one found under `out/debug/`. It should be written after each +build process. + +If debugging is needed then jump directly to the [Debugging](#debugging) +section. Otherwise, if only flashing is needed then +[JLink](https://www.segger.com/downloads/jlink/) can be used: + +- Plug `MCXW71` to the USB port (no need to keep the `SW4` button pressed + while doing this, e.g. ISP mode is not needed for host flashing) + +- Connect JLink to the device: + + ```bash + JLinkExe -device MCXW71 -if SWD -speed 4000 -autoconnect 1 + ``` + +- Run the following commands: + ```bash + reset + halt + loadfile chip-mcxw71-light-example.srec + reset + go + quit + ``` + +## Debugging + +One option for debugging would be to use MCUXpresso IDE. + +- Drag-and-drop the zip file containing the NXP SDK in the "Installed SDKs" + tab: + +![Installed SDKs](../../../platform/nxp/mcxw71_k32w1/doc/images/mcxw71_installed_sdks.jpg) + +- Import any demo application from the installed SDK: + +``` +Import SDK example(s).. -> choose a demo app (demo_apps -> hello_world) -> Finish +``` + +![Import demo](../../../platform/nxp/mcxw71_k32w1/doc/images/import_demo.jpg) + +- Flash the previously imported demo application on the board: + +``` +Right click on the application (from Project Explorer) -> Debug as -> JLink/CMSIS-DAP +``` + +After this step, a debug configuration specific for the `MCXW71` board was +created. This debug configuration will be used later on for debugging the +application resulted after ot-nxp compilation. + +- Import Matter repo in MCUXpresso IDE as Makefile Project. Use _none_ as + _Toolchain for Indexer Settings_: + +``` +File -> Import -> C/C++ -> Existing Code as Makefile Project +``` + +![New Project](../../../platform/nxp/mcxw71_k32w1/doc/images/new_project.jpg) + +- Replace the path of the existing demo application with the path of the + `MCXW71` application: + +``` +Run -> Debug Configurations... -> C/C++ Application +``` + +![Debug MCXW71](../../../platform/nxp/mcxw71_k32w1/doc/images/mcxw71_debug.jpg) + +## Running RPC console + +To build example with RPC enabled, use the following gn command: +`gn gen out/debug --args='import("//with_pw_rpc.gni") treat_warnings_as_errors=false'` + +The application runs an RPC server and processes events coming from an RPC +client. An example of an RPC client is the `chip-console`, which can be accessed +by running: +`chip-console --device /dev/tty. -b 115200 -o pw_log.out` + +The console should have already been installed in the virtual environment. From +the `chip-console`, a user can send specific commands to the device. + +For button commands, please run `rpcs.chip.rpc.Button.Event(index)` based on the +table below: + +| index | action | +| ----- | --------------------------------------------- | +| 0 | Start/stop BLE advertising | +| 1 | Factory reset the device | +| 2 | Application specific action (e.g. toggle LED) | +| 3 | Soft reset the device | + +To reboot the device, please run `rpcs.chip.rpc.Device.Reboot()`. + +## OTA + +Please see +[mcxw71 OTA guide](../../../../docs/guides/nxp/nxp_mcxw71_ota_guide.md). diff --git a/examples/lighting-app/nxp/mcxw71/args.gni b/examples/lighting-app/nxp/mcxw71/args.gni new file mode 100644 index 00000000000000..6a27d6605ea2b8 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/args.gni @@ -0,0 +1,39 @@ +# Copyright (c) 2020-2024 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("${chip_root}/config/standalone/args.gni") + +# SDK target. This is overridden to add our SDK app_config.h & defines. +nxp_sdk_target = get_label_info(":sdk", "label_no_toolchain") +nxp_device = "MCXW716C" + +chip_config_dimmable_led = false +chip_enable_ota_requestor = true +chip_stack_lock_tracking = "fatal" +chip_enable_ble = true +chip_generate_link_map_file = true + +is_debug = false + +chip_crypto = "platform" +chip_openthread_ftd = true +chip_with_ot_cli = 0 + +chip_system_config_provide_statistics = false +chip_system_config_use_open_thread_inet_endpoints = true +chip_with_lwip = false + +use_smu2_static = true +use_smu2_dynamic = true diff --git a/examples/lighting-app/nxp/mcxw71/build_overrides b/examples/lighting-app/nxp/mcxw71/build_overrides new file mode 120000 index 00000000000000..ee19c065d619a2 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/build_overrides @@ -0,0 +1 @@ +../../../build_overrides/ \ No newline at end of file diff --git a/examples/lighting-app/nxp/mcxw71/include/config/AppConfig.h b/examples/lighting-app/nxp/mcxw71/include/config/AppConfig.h new file mode 100644 index 00000000000000..6dcccf749bbebe --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/include/config/AppConfig.h @@ -0,0 +1,29 @@ +/* + * Copyright 2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#pragma once + +/* ---- App Config ---- */ +#define APP_DEVICE_TYPE_ENDPOINT 1 +#define APP_CLUSTER_ATTRIBUTE chip::app::Clusters::OnOff::Attributes::OnOff + +/* ---- Button Manager Config ---- */ +#define BUTTON_MANAGER_FACTORY_RESET_TIMEOUT_MS 6000 + +/* ---- LED Manager Config ---- */ +#define LED_MANAGER_STATUS_LED_INDEX 0 +#define LED_MANAGER_LIGHT_LED_INDEX 1 diff --git a/examples/lighting-app/nxp/mcxw71/include/config/CHIPProjectConfig.h b/examples/lighting-app/nxp/mcxw71/include/config/CHIPProjectConfig.h new file mode 100644 index 00000000000000..20f126aa23a0d5 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/include/config/CHIPProjectConfig.h @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2020 Google LLC. + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#pragma once + +// Security and Authentication disabled for development build. +// For convenience, enable CHIP Security Test Mode and disable the requirement for +// authentication in various protocols. +// WARNING: These options make it possible to circumvent basic CHIP security functionality, +// including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. +#define CHIP_CONFIG_SECURITY_TEST_MODE 0 + +// Use hard-coded test certificates already embedded in generic chip code => set it to 0 +// Use real/development certificates => set it to 1 + file the provisioning section from +// the internal flash +#ifndef CONFIG_CHIP_LOAD_REAL_FACTORY_DATA +#define CONFIG_CHIP_LOAD_REAL_FACTORY_DATA 0 +#endif + +#if CONFIG_CHIP_LOAD_REAL_FACTORY_DATA + +// VID/PID for product => will be used by Basic Information Cluster +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x1037 +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0xA401 + +// Set the following define to use the Certification Declaration from below and not use it stored in factory data section +#ifndef CHIP_USE_DEVICE_CONFIG_CERTIFICATION_DECLARATION +#define CHIP_USE_DEVICE_CONFIG_CERTIFICATION_DECLARATION 0 +#endif + +#ifndef CHIP_DEVICE_CONFIG_CERTIFICATION_DECLARATION +//-> format_version = 1 +//-> vendor_id = 0x1037 +//-> product_id_array = [ 0xA401 ] +//-> device_type_id = 0x0100 +//-> certificate_id = "ZIG20142ZB330003-24" +//-> security_level = 0 +//-> security_information = 0 +//-> version_number = 0x2694 +//-> certification_type = 1 +//-> dac_origin_vendor_id is not present +//-> dac_origin_product_id is not present +#define CHIP_DEVICE_CONFIG_CERTIFICATION_DECLARATION \ + { \ + 0x30, 0x81, 0xe8, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x81, 0xda, 0x30, 0x81, 0xd7, \ + 0x02, 0x01, 0x03, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, \ + 0x45, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x38, 0x04, 0x36, 0x15, 0x24, 0x00, \ + 0x01, 0x25, 0x01, 0x37, 0x10, 0x36, 0x02, 0x05, 0x01, 0xa4, 0x18, 0x25, 0x03, 0x00, 0x01, 0x2c, 0x04, 0x13, 0x5a, \ + 0x49, 0x47, 0x32, 0x30, 0x31, 0x34, 0x32, 0x5a, 0x42, 0x33, 0x33, 0x30, 0x30, 0x30, 0x33, 0x2d, 0x32, 0x34, 0x24, \ + 0x05, 0x00, 0x24, 0x06, 0x00, 0x25, 0x07, 0x76, 0x98, 0x24, 0x08, 0x01, 0x18, 0x31, 0x7c, 0x30, 0x7a, 0x02, 0x01, \ + 0x03, 0x80, 0x14, 0x62, 0xfa, 0x82, 0x33, 0x59, 0xac, 0xfa, 0xa9, 0x96, 0x3e, 0x1c, 0xfa, 0x14, 0x0a, 0xdd, 0xf5, \ + 0x04, 0xf3, 0x71, 0x60, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x30, 0x0a, \ + 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x04, 0x46, 0x30, 0x44, 0x02, 0x20, 0x11, 0xc4, 0xe4, \ + 0x54, 0xcc, 0xdb, 0x09, 0xa9, 0x31, 0xd7, 0xbd, 0x6e, 0x28, 0x95, 0x9b, 0xab, 0x3e, 0xec, 0x76, 0x09, 0x8c, 0x39, \ + 0x93, 0x43, 0x6e, 0x89, 0x07, 0x7d, 0x8b, 0xe9, 0x3a, 0x0a, 0x02, 0x20, 0x71, 0xc6, 0xac, 0x09, 0x11, 0x7b, 0x1a, \ + 0x61, 0x5e, 0x3a, 0xc6, 0x4a, 0x4f, 0xf3, 0xd4, 0x3b, 0x62, 0x54, 0x3a, 0xf3, 0x60, 0xeb, 0x47, 0xd4, 0x8f, 0x18, \ + 0x0d, 0xa3, 0xd1, 0xef, 0xd0, 0x70 \ + } + +// All remaining data will be pulled from the provisioning region of flash. +#endif + +#else + +/** + * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID + * + * 0xFFF1: Test vendor. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID + * + * 0x8005: example lighting-app + */ +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8005 + +// Use a default setup PIN code if one hasn't been provisioned in flash. +#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 +#endif + +#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 +#endif + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" + +/** + * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER + * + * Enables the use of a hard-coded default serial number if none + * is found in CHIP NV storage. + */ +#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" + +#endif // CONFIG_CHIP_LOAD_REAL_FACTORY_DATA + +/** + * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION + * + * The hardware version number assigned to device or product by the device vendor. This + * number is scoped to the device product id, and typically corresponds to a revision of the + * physical device, a change to its packaging, and/or a change to its marketing presentation. + * This value is generally *not* incremented for device software versions. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 100 + +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING +#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING "v0.1.0" +#endif + +/** + * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING + * + * A string identifying the software version running on the device. + * CHIP currently expects the software version to be in the format + * {MAJOR_VERSION}.0d{MINOR_VERSION} + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING NXP_CONFIG_DEVICE_SOFTWARE_VERSION_STRING +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION NXP_CONFIG_DEVICE_SOFTWARE_VERSION +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME "NXP Semiconductors" +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App" +#endif + +/** + * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC + * + * Enables synchronizing the device's real time clock with a remote CHIP Time service + * using the CHIP Time Sync protocol. + */ +// #define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 1 + +/** + * CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_TIMEOUT + * + * The amount of time in miliseconds after which BLE should change his advertisements + * from fast interval to slow interval. + * + * 30000 (30 secondes). + */ +#define CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_TIMEOUT (30 * 1000) + +/** + * CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT + * + * The amount of time in miliseconds after which BLE advertisement should be disabled, counting + * from the moment of slow advertisement commencement. + * + * Defaults to 9000000 (15 minutes). + */ +#define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000) + +/** + * CONFIG_CHIP_NFC_COMMISSIONING, CHIP_DEVICE_CONFIG_ENABLE_NFC + * + * NFC commissioning is not supported on K32W1 + */ +#define CONFIG_CHIP_NFC_COMMISSIONING 0 +#define CHIP_DEVICE_CONFIG_ENABLE_NFC 0 + +/** + * @def CHIP_CONFIG_MAX_FABRICS + * + * @brief + * Maximum number of fabrics the device can participate in. Each fabric can + * provision the device with its unique operational credentials and manage + * its own access control lists. + */ +#define CHIP_CONFIG_MAX_FABRICS 5 // 5 is the minimum number of supported fabrics + +/** + * @def CHIP_IM_MAX_NUM_COMMAND_HANDLER + * + * @brief Defines the maximum number of CommandHandler, limits the number of active commands transactions on server. + */ +#define CHIP_IM_MAX_NUM_COMMAND_HANDLER 2 + +/** + * @def CHIP_IM_MAX_NUM_WRITE_HANDLER + * + * @brief Defines the maximum number of WriteHandler, limits the number of active write transactions on server. + */ +#define CHIP_IM_MAX_NUM_WRITE_HANDLER 2 + +/** + * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE + * + * For a development build, set the default importance of events to be logged as Debug. + * Since debug is the lowest importance level, this means all standard, critical, info and + * debug importance level vi events get logged. + */ +#if BUILD_RELEASE +#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Production +#else +#define CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE chip::Profiles::DataManagement::Debug +#endif // BUILD_RELEASE + +#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/lighting-app/nxp/mcxw71/third_party/connectedhomeip b/examples/lighting-app/nxp/mcxw71/third_party/connectedhomeip new file mode 120000 index 00000000000000..59307833b4fee9 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../.. \ No newline at end of file diff --git a/examples/lighting-app/nxp/mcxw71/with_pw_rpc.gni b/examples/lighting-app/nxp/mcxw71/with_pw_rpc.gni new file mode 100644 index 00000000000000..c2dc1950544640 --- /dev/null +++ b/examples/lighting-app/nxp/mcxw71/with_pw_rpc.gni @@ -0,0 +1,37 @@ +# Copyright (c) 2023 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. + +# add this gni as import in your build args to use pigweed in the example +# 'import("//with_pw_rpc.gni")' + +import("//build_overrides/chip.gni") +import("${chip_root}/config/nxp/lib/pw_rpc/pw_rpc.gni") + +nxp_sdk_target = get_label_info(":sdk", "label_no_toolchain") + +chip_crypto = "platform" +chip_enable_ble = true +chip_enable_ota_requestor = true +chip_enable_pw_rpc = true +chip_openthread_ftd = true +chip_stack_lock_tracking = "fatal" + +chip_system_config_provide_statistics = false +chip_system_config_use_open_thread_inet_endpoints = true + +chip_with_lwip = false +chip_with_ot_cli = 0 + +cpp_standard = "gnu++17" +is_debug = false diff --git a/examples/platform/nxp/mcxw71_k32w1/app/ldscripts/k32w1_app.ld b/examples/platform/nxp/mcxw71_k32w1/app/ldscripts/app.ld similarity index 100% rename from examples/platform/nxp/mcxw71_k32w1/app/ldscripts/k32w1_app.ld rename to examples/platform/nxp/mcxw71_k32w1/app/ldscripts/app.ld diff --git a/examples/platform/nxp/mcxw71_k32w1/doc/images/frdm-mcxw71.jpg b/examples/platform/nxp/mcxw71_k32w1/doc/images/frdm-mcxw71.jpg new file mode 100755 index 00000000000000..a54f70f062c6a0 Binary files /dev/null and b/examples/platform/nxp/mcxw71_k32w1/doc/images/frdm-mcxw71.jpg differ diff --git a/examples/platform/nxp/mcxw71_k32w1/doc/images/mcxw71_debug.jpg b/examples/platform/nxp/mcxw71_k32w1/doc/images/mcxw71_debug.jpg new file mode 100755 index 00000000000000..21bd041ebd3f14 Binary files /dev/null and b/examples/platform/nxp/mcxw71_k32w1/doc/images/mcxw71_debug.jpg differ diff --git a/examples/platform/nxp/mcxw71_k32w1/doc/images/mcxw71_installed_sdks.jpg b/examples/platform/nxp/mcxw71_k32w1/doc/images/mcxw71_installed_sdks.jpg new file mode 100755 index 00000000000000..22ce6ccbdbb878 Binary files /dev/null and b/examples/platform/nxp/mcxw71_k32w1/doc/images/mcxw71_installed_sdks.jpg differ diff --git a/examples/rvc-app/rvc-common/src/rvc-device.cpp b/examples/rvc-app/rvc-common/src/rvc-device.cpp index 88b8095ddf8bdd..02a75c51f56074 100644 --- a/examples/rvc-app/rvc-common/src/rvc-device.cpp +++ b/examples/rvc-app/rvc-common/src/rvc-device.cpp @@ -168,7 +168,7 @@ bool RvcDevice::SaIsSetSelectedAreasAllowed(MutableCharSpan & statusText) { if (mOperationalStateInstance.GetCurrentOperationalState() == to_underlying(OperationalState::OperationalStateEnum::kRunning)) { - CopyCharSpanToMutableCharSpan("cannot set the Selected Areas while the device is running"_span, statusText); + CopyCharSpanToMutableCharSpanWithTruncation("cannot set the Selected Areas while the device is running"_span, statusText); return false; } return true; @@ -179,14 +179,14 @@ bool RvcDevice::SaHandleSkipArea(uint32_t skippedArea, MutableCharSpan & skipSta if (mServiceAreaInstance.GetCurrentArea() != skippedArea) { // This device only supports skipping the current location. - CopyCharSpanToMutableCharSpan("the skipped area does not match the current area"_span, skipStatusText); + CopyCharSpanToMutableCharSpanWithTruncation("the skipped area does not match the current area"_span, skipStatusText); return false; } if (mOperationalStateInstance.GetCurrentOperationalState() != to_underlying(OperationalState::OperationalStateEnum::kRunning)) { // This device only accepts the skip are command while in the running state - CopyCharSpanToMutableCharSpan("skip area is only accepted when the device is running"_span, skipStatusText); + CopyCharSpanToMutableCharSpanWithTruncation("skip area is only accepted when the device is running"_span, skipStatusText); return false; } diff --git a/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp b/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp index b46206ec50ee75..1a6ba6d8c95999 100644 --- a/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp +++ b/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp @@ -134,7 +134,7 @@ bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Span & if (!GetInstance()->GetSupportedAreaById(selectedAreas[0], ignoredIndex, tempArea)) { areaStatus = SelectAreasStatus::kUnsupportedArea; - CopyCharSpanToMutableCharSpan("unable to find selected area in supported areas"_span, statusText); + CopyCharSpanToMutableCharSpanWithTruncation("unable to find selected area in supported areas"_span, statusText); return false; } @@ -145,14 +145,14 @@ bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Span & if (!GetInstance()->GetSupportedAreaById(areaId, ignoredIndex, tempArea)) { areaStatus = SelectAreasStatus::kUnsupportedArea; - CopyCharSpanToMutableCharSpan("unable to find selected area in supported areas"_span, statusText); + CopyCharSpanToMutableCharSpanWithTruncation("unable to find selected area in supported areas"_span, statusText); return false; } if (tempArea.mapID.Value() != mapId) { areaStatus = SelectAreasStatus::kInvalidSet; - CopyCharSpanToMutableCharSpan("all selected areas must be in the same map"_span, statusText); + CopyCharSpanToMutableCharSpanWithTruncation("all selected areas must be in the same map"_span, statusText); return false; } } diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 7cd7c157a54403..4c90164b2d1c12 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -507,7 +507,8 @@ def BuildNxpTarget(): target.AppendFixedTargets([ TargetPart('k32w0', board=NxpBoard.K32W0), TargetPart('k32w1', board=NxpBoard.K32W1), - TargetPart('rw61x', board=NxpBoard.RW61X) + TargetPart('rw61x', board=NxpBoard.RW61X), + TargetPart('mcxw71', board=NxpBoard.MCXW71) ]) # OS @@ -518,8 +519,8 @@ def BuildNxpTarget(): # apps target.AppendFixedTargets([ - TargetPart('lighting', app=NxpApp.LIGHTING).OnlyIfRe('(k32w0|k32w1)'), - TargetPart('contact-sensor', app=NxpApp.CONTACT).OnlyIfRe('(k32w0|k32w1)'), + TargetPart('lighting', app=NxpApp.LIGHTING).OnlyIfRe('(k32w0|k32w1|mcxw71)'), + TargetPart('contact-sensor', app=NxpApp.CONTACT).OnlyIfRe('(k32w0|k32w1|mcxw71)'), TargetPart('all-clusters', app=NxpApp.ALLCLUSTERS).OnlyIfRe('rw61x'), TargetPart('laundry-washer', app=NxpApp.LAUNDRYWASHER).OnlyIfRe('rw61x'), TargetPart('thermostat', app=NxpApp.THERMOSTAT).OnlyIfRe('rw61x') @@ -529,7 +530,7 @@ def BuildNxpTarget(): target.AppendModifier(name="low-power", low_power=True).OnlyIfRe('contact-sensor') target.AppendModifier(name="lit", enable_lit=True).OnlyIfRe('contact-sensor') target.AppendModifier(name="fro32k", use_fro32k=True).OnlyIfRe('k32w0') - target.AppendModifier(name="smu2", smu2=True).OnlyIfRe('k32w1-freertos-lighting') + target.AppendModifier(name="smu2", smu2=True).OnlyIfRe('(k32w1|mcxw71)-freertos-lighting') target.AppendModifier(name="dac-conversion", convert_dac_pk=True).OnlyIfRe('factory').ExceptIfRe('(k32w0|rw61x)') target.AppendModifier(name="rotating-id", enable_rotating_id=True).ExceptIfRe('rw61x') target.AppendModifier(name="sw-v2", has_sw_version_2=True) diff --git a/scripts/build/builders/nxp.py b/scripts/build/builders/nxp.py index 3592400fc0c631..1124a03142472c 100644 --- a/scripts/build/builders/nxp.py +++ b/scripts/build/builders/nxp.py @@ -38,6 +38,7 @@ class NxpBoard(Enum): K32W0 = auto() K32W1 = auto() RW61X = auto() + MCXW71 = auto() def Name(self, os_env): if self == NxpBoard.K32W0: @@ -49,6 +50,8 @@ def Name(self, os_env): return 'rd_rw612_bga' else: return 'rw61x' + elif self == NxpBoard.MCXW71: + return 'mcxw71' else: raise Exception('Unknown board type: %r' % self) @@ -62,6 +65,8 @@ def FolderName(self, os_env): return 'zephyr' else: return 'rt/rw61x' + elif self == NxpBoard.MCXW71: + return 'mcxw71' else: raise Exception('Unknown board type: %r' % self) diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 6639429b31bb75..df54baa2ffec81 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -13,7 +13,7 @@ linux-{x64,arm64}-{rpc-console,all-clusters,all-clusters-minimal,chip-tool,therm linux-x64-efr32-test-runner[-clang] imx-{chip-tool,lighting-app,thermostat,all-clusters-app,all-clusters-minimal-app,ota-provider-app}[-release] infineon-psoc6-{lock,light,all-clusters,all-clusters-minimal}[-ota][-updateimage][-trustm] -nxp-{k32w0,k32w1,rw61x}-{zephyr,freertos}-{lighting,contact-sensor,all-clusters,laundry-washer,thermostat}[-factory][-low-power][-lit][-fro32k][-smu2][-dac-conversion][-rotating-id][-sw-v2][-ota][-wifi][-thread][-matter-shell] +nxp-{k32w0,k32w1,rw61x,mcxw71}-{zephyr,freertos}-{lighting,contact-sensor,all-clusters,laundry-washer,thermostat}[-factory][-low-power][-lit][-fro32k][-smu2][-dac-conversion][-rotating-id][-sw-v2][-ota][-wifi][-thread][-matter-shell] mbed-cy8cproto_062_4343w-{lock,light,all-clusters,all-clusters-minimal,pigweed,ota-requestor,shell}[-release][-develop][-debug] mw320-all-clusters-app nrf-{nrf5340dk,nrf52840dk,nrf52840dongle}-{all-clusters,all-clusters-minimal,lock,light,light-switch,shell,pump,pump-controller,window-covering}[-rpc] diff --git a/src/app/clusters/service-area-server/service-area-delegate.h b/src/app/clusters/service-area-server/service-area-delegate.h index 3983e8d6ed7c25..f82f71fea31d13 100644 --- a/src/app/clusters/service-area-server/service-area-delegate.h +++ b/src/app/clusters/service-area-server/service-area-delegate.h @@ -55,9 +55,10 @@ class Delegate * @brief Can the selected locations be set by the client in the current operating mode? * @param[out] statusText text describing why the selected locations cannot be set (if return is false). * Max size kMaxSizeStatusText. - * Note: If the return is false and statusText is not successfully set, for example due to a string that can be longer than - * kMaxSizeStatusText, the size of this value should be set to 0 with .reduce_size(0) to avoid callers using un-initialized - * memory. + * Note: statusText must be successfully set if the return is false. Use CopyCharSpanToMutableCharSpanWithTruncation to + * ensure that a message is copied successfully. Otherwise, ensure that if setting the statusText can fail (e.g., due + * to exceeding kMaxSizeStatusText) the size of this value is set to 0 with .reduce_size(0) to avoid callers using + * un-initialized memory. * @return true if the current device state allows selected locations to be set by user. * * @note The statusText field SHOULD indicate why the request is not allowed, given the current mode @@ -77,9 +78,10 @@ class Delegate * @param[in] selectedAreas List of new selected locations. * @param[out] locationStatus Success if all checks pass, error code if failure. * @param[out] statusText text describing failure (see description above). Max size kMaxSizeStatusText. - * Note: If the return is false and statusText is not successfully set, for example due to a string that can be longer than - * kMaxSizeStatusText, the size of this value should be set to 0 with .reduce_size(0) to avoid callers using un-initialized - * memory. + * Note: statusText must be successfully set if the return is false. Use CopyCharSpanToMutableCharSpanWithTruncation to + * ensure that a message is copied successfully. Otherwise, ensure that if setting the statusText can fail (e.g., due + * to exceeding kMaxSizeStatusText) the size of this value is set to 0 with .reduce_size(0) to avoid callers using + * un-initialized memory. * @return true if success. * * @note If the SelectAreas command is allowed when the device is operating and the selected locations change to none, the @@ -93,9 +95,10 @@ class Delegate * calling this method. * @param[in] skippedArea the area ID to skip. * @param[out] skipStatusText text describing why the current location cannot be skipped. Max size kMaxSizeStatusText. - * Note: If the return is false and skipStatusText is not successfully set, for example due to a string that can be longer than - * kMaxSizeStatusText, the size of this value should be set to 0 with .reduce_size(0) to avoid callers using un-initialized - * memory. + * Note: skipStatusText must be successfully set if the return is false. Use CopyCharSpanToMutableCharSpanWithTruncation to + * ensure that a message is copied successfully. Otherwise, ensure that if setting the skipStatusText can fail (e.g., due + * to exceeding kMaxSizeStatusText) the size of this value is set to 0 with .reduce_size(0) to avoid callers using + * un-initialized memory. * @return true if command is successful, false if the received skip request cannot be handled due to the current mode of the * device. * @@ -120,7 +123,7 @@ class Delegate virtual bool HandleSkipArea(uint32_t skippedArea, MutableCharSpan & skipStatusText) { // device support of this command is optional - CopyCharSpanToMutableCharSpan("Skip Current Area command not supported by device"_span, skipStatusText); + CopyCharSpanToMutableCharSpanWithTruncation("Skip Current Area command not supported by device"_span, skipStatusText); return false; } diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index ddc47965f9c8b1..f323c220ae118e 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -306,7 +306,6 @@ - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDe _delegates = [NSMutableSet set]; _deviceController = controller; _nodeID = nodeID; - _accessedViaPublicAPI = NO; _state = MTRDeviceStateUnknown; } @@ -322,7 +321,6 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle _nodeID = [nodeID copy]; _fabricIndex = controller.fabricIndex; _deviceController = controller; - _accessedViaPublicAPI = NO; _queue = dispatch_queue_create("org.csa-iot.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); _asyncWorkQueue = [[MTRAsyncWorkQueue alloc] initWithContext:self]; @@ -362,19 +360,9 @@ - (void)dealloc MTR_LOG("MTRDevice dealloc: %p", self); } -+ (MTRDevice *)_deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller -{ - return [controller deviceForNodeID:nodeID]; -} - + (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller { - auto * device = [self _deviceWithNodeID:nodeID controller:controller]; - if (device) { - std::lock_guard lock(device->_lock); - device->_accessedViaPublicAPI = YES; - } - return device; + return [controller deviceForNodeID:nodeID]; } #pragma mark - Time Synchronization diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 69bb02d5f1f03d..dc36aeb694d1e7 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -154,7 +154,11 @@ @implementation MTRDeviceController { MTRP256KeypairBridge _signingKeypairBridge; MTRP256KeypairBridge _operationalKeypairBridge; - BOOL _suspended; + // For now, we just ensure that access to _suspended is atomic, but don't + // guarantee atomicity of the the entire suspend/resume operation. The + // expectation is that suspend/resume on a given controller happen on some + // specific queue, so can't race against each other. + std::atomic _suspended; // Counters to track assertion status and access controlled by the _assertionLock NSUInteger _keepRunningAssertionCounter; @@ -378,9 +382,7 @@ - (BOOL)isRunning - (BOOL)isSuspended { - @synchronized(self) { - return _suspended; - } + return _suspended; } - (void)_notifyDelegatesOfSuspendState @@ -397,48 +399,51 @@ - (void)suspend { MTR_LOG("%@ suspending", self); - @synchronized(self) { + NSArray * devicesToSuspend; + { + std::lock_guard lock(*self.deviceMapLock); + // Set _suspended under the device map lock. This guarantees that + // for any given device exactly one of two things is true: + // * It is in the snapshot we are creating + // * It is created after we have changed our _suspended state. _suspended = YES; + devicesToSuspend = [self.nodeIDToDeviceMap objectEnumerator].allObjects; + } - NSArray * devicesToSuspend; - { - std::lock_guard lock(*self.deviceMapLock); - devicesToSuspend = [self.nodeIDToDeviceMap objectEnumerator].allObjects; - } - - for (MTRDevice * device in devicesToSuspend) { - [device controllerSuspended]; - } - - // TODO: In the concrete class, consider what should happen with: - // - // * Active commissioning sessions (presumably close them?) - // * CASE sessions in general. - // * Possibly try to see whether we can change our fabric entry to not advertise and restart advertising. - - [self _notifyDelegatesOfSuspendState]; + MTR_LOG("%@ found %lu devices to suspend", self, static_cast(devicesToSuspend.count)); + for (MTRDevice * device in devicesToSuspend) { + [device controllerSuspended]; } + + // TODO: In the concrete class, consider what should happen with: + // + // * Active commissioning sessions (presumably close them?) + // * CASE sessions in general. + // * Possibly try to see whether we can change our fabric entry to not advertise and restart advertising. + [self _notifyDelegatesOfSuspendState]; } - (void)resume { MTR_LOG("%@ resuming", self); - @synchronized(self) { + NSArray * devicesToResume; + { + std::lock_guard lock(*self.deviceMapLock); + // Set _suspended under the device map lock. This guarantees that + // for any given device exactly one of two things is true: + // * It is in the snapshot we are creating + // * It is created after we have changed our _suspended state. _suspended = NO; + devicesToResume = [self.nodeIDToDeviceMap objectEnumerator].allObjects; + } - NSArray * devicesToResume; - { - std::lock_guard lock(*self.deviceMapLock); - devicesToResume = [self.nodeIDToDeviceMap objectEnumerator].allObjects; - } - - for (MTRDevice * device in devicesToResume) { - [device controllerResumed]; - } - - [self _notifyDelegatesOfSuspendState]; + MTR_LOG("%@ found %lu devices to resume", self, static_cast(devicesToResume.count)); + for (MTRDevice * device in devicesToResume) { + [device controllerResumed]; } + + [self _notifyDelegatesOfSuspendState]; } - (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate @@ -859,7 +864,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams // // Note that this is just an optimization to avoid throwing the information away and immediately // re-reading it from storage. - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (kSecondsToWaitBeforeAPIClientRetainsMTRDevice * NSEC_PER_SEC)), self.chipWorkQueue, ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (kSecondsToWaitBeforeAPIClientRetainsMTRDevice * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ MTR_LOG("%@ un-retain devices loaded at startup %lu", self, static_cast(deviceList.count)); }); }]; diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm index c8f8950579b350..bdcbafae1b6c9d 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm @@ -761,7 +761,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams // // Note that this is just an optimization to avoid throwing the information away and immediately // re-reading it from storage. - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (kSecondsToWaitBeforeAPIClientRetainsMTRDevice * NSEC_PER_SEC)), self.chipWorkQueue, ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (kSecondsToWaitBeforeAPIClientRetainsMTRDevice * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ MTR_LOG("%@ un-retain devices loaded at startup %lu", self, static_cast(deviceList.count)); }); }]; diff --git a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm index 055c8a31ac45c5..9beacdfd046bbc 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm @@ -62,6 +62,7 @@ @interface MTRDevice_Concrete () @property (nonatomic, readwrite) MTRDeviceState state; @property (nonatomic, readwrite, nullable) NSDate * estimatedStartTime; @property (nonatomic, readwrite, nullable, copy) NSNumber * estimatedSubscriptionLatency; +@property (nonatomic, readwrite, assign) BOOL suspended; @end @@ -395,6 +396,8 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle }]; } + self.suspended = controller.suspended; + MTR_LOG_DEBUG("%@ init with hex nodeID 0x%016llX", self, _nodeID.unsignedLongLongValue); } return self; @@ -719,8 +722,8 @@ - (BOOL)_subscriptionsAllowed { os_unfair_lock_assert_owner(&self->_lock); - // We should not allow a subscription for suspended controllers or device controllers over XPC. - return _deviceController.isSuspended == NO && ![_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class]; + // We should not allow a subscription when we are suspended or for device controllers over XPC. + return self.suspended == NO && ![_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class]; } - (void)_delegateAdded @@ -1290,7 +1293,7 @@ - (void)_doHandleSubscriptionReset:(NSNumber * _Nullable)retryDelay os_unfair_lock_assert_owner(&_lock); - if (_deviceController.isSuspended) { + if (self.suspended) { MTR_LOG("%@ ignoring expected subscription reset on controller suspend", self); return; } @@ -1378,7 +1381,6 @@ - (void)_reattemptSubscriptionNowIfNeededWithReason:(NSString *)reason } MTR_LOG("%@ reattempting subscription with reason %@", self, reason); - self.reattemptingSubscription = NO; [self _setupSubscriptionWithReason:reason]; } @@ -2302,6 +2304,10 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason os_unfair_lock_assert_owner(&self->_lock); + // If we have a pending subscription reattempt, make sure it does not + // actually happen, since we are trying to do a subscription now. + self.reattemptingSubscription = NO; + if (![self _subscriptionsAllowed]) { MTR_LOG("%@ _setupSubscription: Subscriptions not allowed. Do not set up subscription (reason: %@)", self, reason); return; @@ -2694,12 +2700,12 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath) // 3. The attribute is not in the spec, and the read params asks to assume // an unknown attribute has the Changes Omitted quality. // - // But all this only happens if this device has been accessed via the public - // API. If it's a device we just created internally, don't do read-throughs. + // But all this only happens if this device is not suspended. If it's suspended, read-throughs will fail + // anyway, so we should not bother trying. BOOL readThroughsAllowed; { std::lock_guard lock(_lock); - readThroughsAllowed = _accessedViaPublicAPI; + readThroughsAllowed = !self.suspended; } if (readThroughsAllowed && (![self _subscriptionAbleToReport] || hasChangesOmittedQuality)) { // Read requests container will be a mutable array of items, each being an array containing: @@ -3991,6 +3997,7 @@ - (void)controllerSuspended [super controllerSuspended]; std::lock_guard lock(self->_lock); + self.suspended = YES; [self _resetSubscriptionWithReasonString:@"Controller suspended"]; // Ensure that any pre-existing resubscribe attempts we control don't try to @@ -4003,6 +4010,7 @@ - (void)controllerResumed [super controllerResumed]; std::lock_guard lock(self->_lock); + self.suspended = NO; if (![self _delegateExists]) { MTR_LOG("%@ ignoring controller resume: no delegates", self); diff --git a/src/darwin/Framework/CHIP/MTRDevice_Internal.h b/src/darwin/Framework/CHIP/MTRDevice_Internal.h index 7a91b926560f30..d0661b2590e9cd 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDevice_Internal.h @@ -120,19 +120,8 @@ MTR_DIRECT_MEMBERS // Our controller. Declared nullable because our property is, though in // practice it does not look like we ever set it to nil. MTRDeviceController * _Nullable _deviceController; - - // Whether this device has been accessed via the public deviceWithNodeID API - // (as opposed to just via the internal _deviceWithNodeID). - BOOL _accessedViaPublicAPI; } -/** - * Internal way of creating an MTRDevice that does not flag the device as being - * visible to external API consumers. - */ -+ (MTRDevice *)_deviceWithNodeID:(NSNumber *)nodeID - controller:(MTRDeviceController *)controller; - - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller; - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller; diff --git a/src/platform/nxp/BUILD.gn b/src/platform/nxp/BUILD.gn index 0865a1d36dacb6..b2043caac1f0bf 100644 --- a/src/platform/nxp/BUILD.gn +++ b/src/platform/nxp/BUILD.gn @@ -26,7 +26,7 @@ source_set("logging") { "${chip_root}/src/platform/logging:headers", ] - if (nxp_platform == "k32w/k32w0" || nxp_platform == "k32w1") { + if (nxp_platform == "k32w0" || nxp_platform == "mcxw71_k32w1") { sources = [ "${chip_root}/src/platform/nxp/${nxp_platform}/Logging.cpp" ] } else { sources = [ "${chip_root}/src/platform/nxp/common/Logging.cpp" ] diff --git a/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h b/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h index ba2321c9a26566..e8d392fb793604 100644 --- a/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h +++ b/src/platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h @@ -102,6 +102,10 @@ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD +#ifndef CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY +#define CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY "nxp/diag/usr" +#endif // CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY + #if CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1 #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/src/platform/nxp/common/KeyValueStoreManagerImpl.cpp b/src/platform/nxp/common/KeyValueStoreManagerImpl.cpp index af2598ca2be188..737007a46dce68 100644 --- a/src/platform/nxp/common/KeyValueStoreManagerImpl.cpp +++ b/src/platform/nxp/common/KeyValueStoreManagerImpl.cpp @@ -55,7 +55,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t ChipLogError(DeviceLayer, "KVS, failed to read key!"); } - *read_bytes_size = read_bytes; + if (read_bytes_size) + { + *read_bytes_size = read_bytes; + } exit: ConvertError(err); diff --git a/src/platform/nxp/common/NXPConfig.h b/src/platform/nxp/common/NXPConfig.h index 03d6174763fb69..7de3beab2b37ed 100644 --- a/src/platform/nxp/common/NXPConfig.h +++ b/src/platform/nxp/common/NXPConfig.h @@ -40,14 +40,12 @@ #if (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_NVM_FWK) #include "NVM_Interface.h" +#include "ram_storage.h" #elif (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_LITTLEFS) #include "fwk_filesystem.h" -#endif - -#if (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_KEY_STORAGE) -#include "fwk_key_storage.h" -#else #include "ram_storage.h" +#elif (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_KEY_STORAGE) +#include "fwk_key_storage.h" #endif namespace chip { @@ -188,11 +186,14 @@ class NXPConfig private: #if (CHIP_PLAT_NVM_SUPPORT == CHIP_PLAT_KEY_STORAGE) static CHIP_ERROR MapKeyStorageStatus(ks_error_t ksStatus); -#else +#elif (CHIP_PLAT_NVM_SUPPORT != CHIP_PLAT_NO_NVM) static CHIP_ERROR MapRamStorageStatus(rsError rsStatus); #endif static int SaveIntKeysToFS(void); static int SaveStringKeysToFS(void); +#if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1) + static CHIP_ERROR InitStorageWearStats(void); +#endif }; } // namespace Internal diff --git a/src/platform/nxp/common/NXPConfigKS.cpp b/src/platform/nxp/common/NXPConfigKS.cpp index 1940a8081cbf7c..930f07fe3540d4 100644 --- a/src/platform/nxp/common/NXPConfigKS.cpp +++ b/src/platform/nxp/common/NXPConfigKS.cpp @@ -31,6 +31,7 @@ #include #include "fwk_file_cache.h" +#include "fwk_fs_abstraction.h" #include "fwk_key_storage.h" #include "fwk_lfs_mflash.h" @@ -419,26 +420,26 @@ bool NXPConfig::ConfigValueExists(Key key) found = false; readValue_p = NULL; outLen = 0; - /* Max number of bytes read when getting a value */ - bufSize = 256; + bufSize = 0; if (ValidConfigKey(key)) { /* Get the first occurence */ status = KS_GetKeyInt(ks_handle_p, (int) key, (char *) NS_INT, readValue_p, bufSize, &outLen); - found = (status == KS_ERROR_NONE && outLen != 0); + found = (status != KS_ERROR_KEY_NOT_FOUND); } return found; } CHIP_ERROR NXPConfig::FactoryResetConfig(void) { - /*for (Key key = kMinConfigKey_ChipConfig; key <= kMaxConfigKey_ChipConfig; key++) - { - ClearConfigValue(key); - }*/ - - KS_Reset(ks_handle_p); + /* + * When a factory reset is required, shut down the KeyStorage (which + * also flushes the FileCache) and then execute a simple format of the + * the file system partition. + */ + KS_DeInit(ks_handle_p); + FSA_Format(); DBG_PRINTF("FactoryResetConfig done\r\n"); diff --git a/src/platform/nxp/common/NXPConfigNVS.cpp b/src/platform/nxp/common/NXPConfigNVS.cpp index 34d98a36d25002..4cd997b218d473 100644 --- a/src/platform/nxp/common/NXPConfigNVS.cpp +++ b/src/platform/nxp/common/NXPConfigNVS.cpp @@ -20,10 +20,14 @@ #include #include #include +#include #include /* Only for flash init, to be move to sdk framework */ #include "port/nvs_port.h" +#if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1) +#include "fwk_nvs_stats.h" +#endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */ // These can be overridden by the application as needed. #ifndef CHIP_DEVICE_INTEGER_SETTINGS_KEY @@ -137,6 +141,17 @@ int DeleteSubtreeCallback(const char * name, size_t /* entrySize */, settings_re return 0; } + +#if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1) +void OnFlashSectorWearCountUpdate(uint16_t sector_idx, const nvs_storage_wear_profile_t * flash_wear_profile) +{ + char keyUser[] = CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY; + const size_t flash_wear_profile_size = NVS_STORAGE_WEAR_PROFILE_SIZE(flash_wear_profile->sector_count); + + /* Update the NVS stats key in storage */ + NXPConfig::WriteConfigValueBin((const char *) keyUser, (uint8_t *) flash_wear_profile, flash_wear_profile_size); +} +#endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */ } // namespace CHIP_ERROR NXPConfig::Init() @@ -151,8 +166,50 @@ CHIP_ERROR NXPConfig::Init() ReturnErrorCodeIf(settings_subsys_init(), CHIP_ERROR_PERSISTED_STORAGE_FAILED); +#if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1) + ReturnErrorOnFailure(InitStorageWearStats()); +#endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */ + + return CHIP_NO_ERROR; +} + +#if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1) +CHIP_ERROR NXPConfig::InitStorageWearStats(void) +{ + nvs_storage_wear_profile_t * flash_wear_profile = NULL; + const size_t flash_wear_profile_size = NVS_STORAGE_WEAR_PROFILE_SIZE((uint32_t) NV_STORAGE_MAX_SECTORS); + size_t size; + char keyUser[] = CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY; + + /* Create an empty flash wear profile */ + flash_wear_profile = (nvs_storage_wear_profile_t *) calloc(1, flash_wear_profile_size); + ReturnErrorCodeIf(flash_wear_profile == NULL, CHIP_ERROR_NO_MEMORY); + + /* Try to read the flash wear profile from the User Support diagnostic log key */ + CHIP_ERROR err = ReadConfigValueBin((const char *) keyUser, (uint8_t *) flash_wear_profile, flash_wear_profile_size, size); + if ((err != CHIP_NO_ERROR) || (size != flash_wear_profile_size) || + (flash_wear_profile->sector_count != (uint32_t) NV_STORAGE_MAX_SECTORS)) + { + /* Either the flash wear stats are not available in the persistent + * storage or the flash wear statistics that we have read are not + * compatible with the current persistent storage configuration. In + * this case - just reset and save the flash wear statistics. */ + flash_wear_profile->sector_count = (uint32_t) NV_STORAGE_MAX_SECTORS; + memset(flash_wear_profile->erase_count, 0, (uint32_t) NV_STORAGE_MAX_SECTORS * sizeof(uint16_t)); + WriteConfigValueBin((const char *) keyUser, (uint8_t *) flash_wear_profile, flash_wear_profile_size); + } + else + { + /* Load the flash wear profile into the NVS statistics */ + nvs_stats_load_profile(flash_wear_profile); + } + free(flash_wear_profile); + + nvs_stats_config_event_handler(OnFlashSectorWearCountUpdate); + return CHIP_NO_ERROR; } +#endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */ CHIP_ERROR NXPConfig::ReadConfigValue(Key key, bool & val) { diff --git a/src/platform/nxp/common/legacy/gatt_db.h b/src/platform/nxp/common/legacy/gatt_db.h new file mode 100644 index 00000000000000..604fcfb61a7ba1 --- /dev/null +++ b/src/platform/nxp/common/legacy/gatt_db.h @@ -0,0 +1,30 @@ +PRIMARY_SERVICE(service_gatt, gBleSig_GenericAttributeProfile_d) +CHARACTERISTIC(char_service_changed, gBleSig_GattServiceChanged_d, (gGattCharPropRead_c | gGattCharPropNotify_c)) +VALUE(value_service_changed, gBleSig_GattServiceChanged_d, (gPermissionNone_c), 4, 0x00, 0x00, 0x00, 0x00) +CCCD(cccd_service_changed) + +PRIMARY_SERVICE(service_gap, gBleSig_GenericAccessProfile_d) +CHARACTERISTIC(char_device_name, gBleSig_GapDeviceName_d, (gGattCharPropRead_c)) +VALUE(value_device_name, gBleSig_GapDeviceName_d, (gPermissionFlagReadable_c), 16, "NXP_ELOCK_DEMO") +CHARACTERISTIC(char_appearance, gBleSig_GapAppearance_d, (gGattCharPropRead_c)) +VALUE(value_appearance, gBleSig_GapAppearance_d, (gPermissionFlagReadable_c), 2, 0x00, 0x00) + +PRIMARY_SERVICE(service_chipoble, gChipoBleService_d) +CHARACTERISTIC_UUID128(chipoble_rx, uuid_chipoble_rx, (gGattCharPropWrite_c)) +VALUE_UUID128_VARLEN(value_chipoble_rx, uuid_chipoble_rx, (gPermissionFlagWritable_c), gAttMaxMtu_c - 3, gAttMaxMtu_c - 3, 0x00) +CHARACTERISTIC_UUID128(chipoble_tx, uuid_chipoble_tx, (gGattCharPropIndicate_c | gGattCharPropRead_c)) +VALUE_UUID128_VARLEN(value_chipoble_tx, uuid_chipoble_tx, (gPermissionFlagReadable_c), gAttMaxMtu_c - 3, gAttMaxMtu_c - 3, 0x00) +CCCD(cccd_chipoble_tx) +CHARACTERISTIC_UUID128(chipoble_c3, uuid_chipoble_c3, (gGattCharPropRead_c)) +VALUE_UUID128_VARLEN(value_chipoble_c3, uuid_chipoble_c3, (gPermissionFlagReadable_c), gAttMaxReadDataSize_d(gAttMaxValueLength_c), + gAttMaxReadDataSize_d(gAttMaxValueLength_c), 0x00) + +PRIMARY_SERVICE(service_device_info, gBleSig_DeviceInformationService_d) +CHARACTERISTIC(char_model_no, gBleSig_ModelNumberString_d, (gGattCharPropRead_c)) +VALUE(value_model_no, gBleSig_ModelNumberString_d, (gPermissionFlagReadable_c), 15, "Chip ELock Demo") +CHARACTERISTIC(char_serial_no, gBleSig_SerialNumberString_d, (gGattCharPropRead_c)) +VALUE(value_serial_no, gBleSig_SerialNumberString_d, (gPermissionFlagReadable_c), 7, "BLESN01") +CHARACTERISTIC(char_fw_rev, gBleSig_FirmwareRevisionString_d, (gGattCharPropRead_c)) +VALUE(value_fw_rev, gBleSig_FirmwareRevisionString_d, (gPermissionFlagReadable_c), 5, "1.1.1") +CHARACTERISTIC(char_sw_rev, gBleSig_SoftwareRevisionString_d, (gGattCharPropRead_c)) +VALUE(value_sw_rev, gBleSig_SoftwareRevisionString_d, (gPermissionFlagReadable_c), 5, "1.1.4") diff --git a/src/platform/nxp/common/legacy/gatt_uuid128.h b/src/platform/nxp/common/legacy/gatt_uuid128.h new file mode 100644 index 00000000000000..938968b1943ce2 --- /dev/null +++ b/src/platform/nxp/common/legacy/gatt_uuid128.h @@ -0,0 +1,26 @@ +/* +* Declare all custom 128-bit UUIDs here using the format: +* +* UUID128(name, bytes) +* +* where: +* -name : an unique tag for the newly defined UUID; + will be used to reference this UUID when defining + services and characteristics in <> +* -bytes: 16 bytes representing the 128-bit value +* +* One definition per line. No semicolon required after each definition. +* +* example: +* UUID128(uuid_service_robot_characteristics, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, +0xCD, 0xEF) +* UUID128(uuid_char_robot_direction, 0x12, 0x34, 0x50, 0x00, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, +0xEF) +*/ +/* Services */ + +#define gChipoBleService_d 0xFFF6 + +UUID128(uuid_chipoble_tx, 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18) +UUID128(uuid_chipoble_rx, 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18) +UUID128(uuid_chipoble_c3, 0x04, 0x8f, 0x21, 0x83, 0x8a, 0x74, 0x7d, 0xb8, 0xf2, 0x45, 0x72, 0x87, 0x38, 0x02, 0x63, 0x64)