From 1030510b2d5d4a995dafc83a371b9d8aa36f5d30 Mon Sep 17 00:00:00 2001 From: weicheng Date: Fri, 9 Jun 2023 11:16:41 +0800 Subject: [PATCH] [ASR] add asr getting stated guide; add ASR582X CI (#27057) * [ASR] add asr getting stated guide; add ASR582X CI * remove unused env in CI; remove app list --------- Co-authored-by: Andrei Litvin --- .github/workflows/examples-asr.yaml | 70 +++++++++ docs/guides/README.md | 1 + docs/guides/asr_getting_started_guide.md | 134 ++++++++++++++++++ docs/guides/index.md | 1 + examples/lighting-app/asr/README.md | 84 ++++------- examples/platform/asr/shell/matter_shell.cpp | 3 + scripts/build/build/targets.py | 2 + scripts/build/builders/asr.py | 5 + .../build/testdata/all_targets_linux_x64.txt | 2 +- src/platform/ASR/ASRConfig.h | 2 - src/platform/ASR/ASROTAImageProcessor.cpp | 4 +- src/platform/ASR/ASRUtils.cpp | 3 - src/platform/ASR/ConnectivityManagerImpl.cpp | 3 +- src/platform/ASR/KeyValueStoreManagerImpl.cpp | 2 +- .../ASR/NetworkCommissioningWiFiDriver.cpp | 7 +- src/platform/ASR/PlatformManagerImpl.h | 2 + src/platform/ASR/args.gni | 2 + 17 files changed, 252 insertions(+), 75 deletions(-) create mode 100644 .github/workflows/examples-asr.yaml create mode 100644 docs/guides/asr_getting_started_guide.md diff --git a/.github/workflows/examples-asr.yaml b/.github/workflows/examples-asr.yaml new file mode 100644 index 00000000000000..08dc3095ca5d7e --- /dev/null +++ b/.github/workflows/examples-asr.yaml @@ -0,0 +1,70 @@ +# 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. + +name: Build example - ASR + +on: + push: + pull_request: + merge_group: + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }} + cancel-in-progress: true + +env: + CHIP_NO_LOG_TIMESTAMPS: true + # XXX: Workaround for https://github.com/actions/cache/issues/1141 + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 3 + +jobs: + asr: + name: ASR + + runs-on: ubuntu-latest + if: github.actor != 'restyled-io[bot]' + + container: + image: connectedhomeip/chip-build-asr:0.7.14 + options: --user root + + steps: + - uses: Wandalen/wretry.action@v1.0.36 + name: Checkout + with: + action: actions/checkout@v3 + with: | + token: ${{ github.token }} + attempt_limit: 3 + attempt_delay: 2000 + - name: Checkout submodules + run: scripts/checkout_submodules.py --allow-changing-global-git-config --shallow --platform asr + - name: Bootstrap cache + uses: actions/cache@v3 + timeout-minutes: 10 + with: + key: ${{ runner.os }}-env-${{ hashFiles('scripts/setup/*', 'third_party/pigweed/**') }} + path: | + .environment + build_overrides/pigweed_environment.gni + - name: Bootstrap + run: bash scripts/bootstrap.sh + - name: Build all ASR582X examples + run: | + ./scripts/run_in_build_env.sh \ + "./scripts/build/build_examples.py \ + --target asr-asr582x-lighting \ + --target asr-asr582x-lighting-ota \ + build \ + " \ No newline at end of file diff --git a/docs/guides/README.md b/docs/guides/README.md index 451a2c6d2fdff7..d37c959e3a602c 100644 --- a/docs/guides/README.md +++ b/docs/guides/README.md @@ -4,6 +4,7 @@ - [Android - Building](./android_building.md) - [Apple - Testing with iPhone, iPad, macOS, Apple TV, HomePod, Watch, etc](./darwin.md) +- [ASR - Getting Started Guide](./asr_getting_started_guide.md) - [Espressif (ESP32) - Getting Started Guide](./esp32/README.md) - [Infineon PSoC6 - Software Update](./infineon_psoc6_software_update.md) - [Linux - Simulated Devices](./simulated_device_linux.md) diff --git a/docs/guides/asr_getting_started_guide.md b/docs/guides/asr_getting_started_guide.md new file mode 100644 index 00000000000000..fa86dfda279328 --- /dev/null +++ b/docs/guides/asr_getting_started_guide.md @@ -0,0 +1,134 @@ +# ASR Getting Started Guide + +The ASR platform is a [Matter](https://github.com/project-chip/connectedhomeip) +platform that uses ASR FreeRTOS SDK. + +--- + +- [ASR Getting Started Guide](#asr-getting-started-guide) + - [Supported Chips](#supported-chips) + - [Matter Example Applications](#matter-example-applications) + - [Building the Example Application](#building-the-example-application) + - [Commissioning](#commissioning) + - [BLE mode](#ble-mode) + - [IP mode](#ip-mode) + - [Shell](#shell) + - [OTA](#ota) + +--- + +## Supported Chips + +The ASR platform is supported on: + +- [ASR582X](http://www.asrmicro.com/en/goods/proinfo/36.html) +- [ASR595X](http://www.asrmicro.com/en/goods/proinfo/42.html) + +## Matter Example Applications + +Sample Matter applications are provided for the ASR platform. They can be used +to speed up development. You can find them in the samples with `/asr` subfolder. + +## Building the Example Application + +- [Setup Matter Environment](./BUILDING.md) + +- Setup toolchain + - for ASR582X + ``` + cd toolchain + wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 + tar -jxvf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 + export ASR_TOOLCHAIN_PATH={abs-path-to-toolchain}/gcc-arm-none-eabi-9-2019-q4-major/bin/ + ``` + - for ASR595X + ``` + git clone --depth=1 https://github.com/asriot/Tools.git + cd Tools/toolchain + cat asr_riscv_gnu_toolchain_10.2_ubuntu-16.04.tar.bz2.part* > asr_riscv_gnu_toolchain_10.2_ubuntu-16.04.tar.bz2 + mkdir -p asr_riscv_gnu_toolchain_10.2_ubuntu-16.04 + tar -jxvf asr_riscv_gnu_toolchain_10.2_ubuntu-16.04.tar.bz2 -C asr_riscv_gnu_toolchain_10.2_ubuntu-16.04/ + export ASR_TOOLCHAIN_PATH={abs-path-to-toolchain}/asr_riscv_gnu_toolchain_10.2_ubuntu-16.04/bin/ + ``` +- Setup Chip environment + - for ASR582X: + ``` + export ASR_BOARD=asr582x + ``` + - for ASR595X: + ``` + export ASR_BOARD=asr595x + ``` +- Building the Application + + If the lighting example is to be built: + + ``` + ./scripts/build/build_examples.py --target asr-$ASR_BOARD-lighting build + ``` + +- The output image files are stored in the subdirectories under `out`, the + subdirectory name is the same as the argument specified after the option + `--target` when build the examples. + +- After building the application, `DOGO` tool is used to flash it to the + board. + +## Commissioning + +There are two commissioning modes supported by ASR platform: + +### BLE mode + +1. Build and Flash +2. The example will run automatically after booting the ASR board. +3. Restore factory settings using command `recovery` +4. Commissioning with + [Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool),for + example: + ``` + ./chip-tool pairing ble-wifi + ``` + +### IP mode + +1. Build and Flash +2. The example will run automatically after booting the ASR board. +3. Restore factory settings using command `recovery` +4. Connect to AP using command `wifi_open sta [ssid] [password]` +5. Commissioning with + [Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool),for + example: + ``` + ./chip-tool pairing onnetwork-long + ``` + +## Shell + +1. To build the example with Matter shell, exactly the same steps as above but + add argument `-shell` when using the `build_examples.py` script. For example: + `./scripts/build/build_examples.py --target asr-$ASR_BOARD-lighting-shell build` +2. The example will run automatically after booting the ASR board. +3. Use `help` command to list all supported commands: + ``` + help + base64 Base64 encode / decode utilities + exit Exit the shell application + help List out all top level commands + version Output the software version + ble BLE transport commands + wifi Usage: wifi + config Manage device configuration. Usage to dump value: config [param_name] and to set some values (discriminator): config [param_name] [param_value]. + device Device management commands + onboardingcodes Dump device onboarding codes. Usage: onboardingcodes none|softap|ble|onnetwork [qrcode|qrcodeurl|manualpairingcode] + dns Dns client commands + OnOff OnOff commands. Usage: OnOff [on|off] + Done + ``` + +## OTA + +To build the example with the Matter OTA Requestor functionality, exactly the +same steps as above but add argument `-ota` when using the `build_examples.py` +script. For example: +`./scripts/build/build_examples.py --target asr-$ASR_BOARD-lighting-ota build` diff --git a/docs/guides/index.md b/docs/guides/index.md index 5d93bbb9b012ae..1cbfcabcf17c61 100644 --- a/docs/guides/index.md +++ b/docs/guides/index.md @@ -20,6 +20,7 @@ esp32/README - [Android - Building](./android_building.md) - [Apple - Testing with iPhone, iPad, macOS, Apple TV, HomePod, Watch, etc](./darwin.md) +- [ASR - Getting Started Guide](./asr_getting_started_guide.md) - [Espressif (ESP32) - Getting Started Guide](./esp32/README.md) - [Infineon PSoC6 - Software Update](./infineon_psoc6_software_update.md) - [Linux - Simulated Devices](./simulated_device_linux.md) diff --git a/examples/lighting-app/asr/README.md b/examples/lighting-app/asr/README.md index 78755f02f9119a..c9b8009b8a35f1 100755 --- a/examples/lighting-app/asr/README.md +++ b/examples/lighting-app/asr/README.md @@ -1,80 +1,33 @@ -# CHIP ASR Lighting Example +# Matter ASR Lighting Example This example demonstrates the Matter Lighting application on ASR platform. --- -- [CHIP ASR Lighting Example](#chip-asr-lighting-example) +- [Matter ASR Lighting Example](#matter-asr-lighting-example) - [Supported Chips](#supported-chips) - - [Building the Example Application](#building-the-example-application) - - [Commissioning](#commissioning) - - [BLE mode](#ble-mode) - - [IP mode](#ip-mode) + - [Building and Commissioning](#building-and-commissioning) - [Cluster Control](#cluster-control) + - [Indicate current state of lightbulb](#indicate-current-state-of-lightbulb) --- ## Supported Chips -The CHIP demo application is supported on: +The Matter demo application is supported on: - ASR582X - ASR595X -## Building the Example Application +## Building and Commissioning -- [Setup CHIP Environment](../../../docs/guides/BUILDING.md) +Please refer +[Building and Commissioning](../../../docs/guides/asr_getting_started_guide.md#building-the-example-application) +guides to get started -- Setup toolchain for ASR582X,download gcc-arm-none-eabi-9-2019-q4-major,then - export `ASR_TOOLCHAIN_PATH`: - ``` - export ASR_TOOLCHAIN_PATH={path-to-toolchain}/gcc-arm-none-eabi-9-2019-q4-major/bin/ - ``` - for ASR595X,download asr_riscv_gnu_toolchain_10.2_ubuntu,then export - `ASR_TOOLCHAIN_PATH`: - ``` - export ASR_TOOLCHAIN_PATH={path-to-toolchain}/asr_riscv_gnu_toolchain_10.2_ubuntu-16.04/bin/ - ``` -- Setup Chip environment - - for ASR582X: - ``` - export ASR_BOARD=asr582x - ``` - - for ASR595X: - ``` - export ASR_BOARD=asr595x - ``` -- Building the Application - ``` - ./scripts/build/build_examples.py --target asr-$ASR_BOARD-lighting build - ``` -- The output image files are stored in the subdirectories under `out`, the - subdirectory name is the same as the argument specified after the option - `--target` when build the examples. - -- After building the application, `DOGO` tool is used to flash it to the - board. - -## Commissioning - -There are two commissioning modes supported by ASR platform: - -### BLE mode - -1. Build and Flash -2. The example will run automatically after booting the ASR board. -3. Restore factory settings using command `recovery` -4. Commissioning with - [Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool) - -### IP mode - -1. Build and Flash -2. The example will run automatically after booting the ASR board. -3. Restore factory settings using command `recovery` -4. Connect to AP using command `wifi_open sta [ssid] [password]` -5. Commissioning with - [Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool) +``` +./scripts/build/build_examples.py --target asr-$ASR_BOARD-lighting build +``` ## Cluster Control @@ -96,3 +49,16 @@ After successful commissioning, use `chip-tool` to control the board ``` ./chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 1 ``` + +## Indicate current state of lightbulb + +By default, a 3-color LED(RGB) module is used to show current state of lightbulb +Connect the module to following pins: + +| Name | Pin | +| :---: | :---: | +| Red | PAD7 | +| Green | PAD6 | +| Blue | PAD10 | + +These default pins are defined at `examples/platform/asr/LEDWidget.h` diff --git a/examples/platform/asr/shell/matter_shell.cpp b/examples/platform/asr/shell/matter_shell.cpp index 55a66b31cf0eaf..f84d6946f6a425 100644 --- a/examples/platform/asr/shell/matter_shell.cpp +++ b/examples/platform/asr/shell/matter_shell.cpp @@ -34,6 +34,9 @@ #include #include #include +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +#include "init_OTARequestor.h" +#endif using namespace ::chip; using namespace ::chip::Credentials; diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index d2024c46209733..f573feec814940 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -425,6 +425,8 @@ def BuildASRTarget(): target.AppendModifier('ota', enable_ota_requestor=True) target.AppendModifier('shell', chip_build_libshell=True) target.AppendModifier('no_logging', chip_logging=False) + target.AppendModifier('factory', enable_factory=True) + target.AppendModifier('rotating_id', enable_rotating_device_id=True) return target diff --git a/scripts/build/builders/asr.py b/scripts/build/builders/asr.py index e8ca5aa8b3f715..c329f70e29ddc7 100644 --- a/scripts/build/builders/asr.py +++ b/scripts/build/builders/asr.py @@ -60,6 +60,7 @@ def __init__(self, chip_build_libshell: bool = False, chip_logging: bool = True, enable_factory: bool = False, + enable_rotating_device_id: bool = False, enable_ota_requestor: bool = False): super(ASRBuilder, self).__init__( root=app.BuildRoot(root), @@ -104,6 +105,10 @@ def __init__(self, self.extra_gn_options.append('chip_use_transitional_commissionable_data_provider=false') self.extra_gn_options.append('chip_enable_factory_data=true') + if enable_rotating_device_id: + self.extra_gn_options.append('chip_enable_additional_data_advertising=true') + self.extra_gn_options.append('chip_enable_rotating_device_id=true') + self.extra_gn_options.append('asr_toolchain_root="%s"' % os.environ['ASR_TOOLCHAIN_PATH']) def GnBuildArgs(self): diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 821e9a84f04bc7..e4f8a8968253f8 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -1,5 +1,5 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} -asr-{asr582x,asr595x}-lighting[-ota][-shell][-no_logging] +asr-{asr582x,asr595x}-lighting[-ota][-shell][-no_logging][-factory][-rotating_id] android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller}[-no-debug] bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light}-light[-shell][-115200][-rpc][-cdc] cc32xx-lock diff --git a/src/platform/ASR/ASRConfig.h b/src/platform/ASR/ASRConfig.h index 10895098a1d2df..af10b47b08d2f9 100644 --- a/src/platform/ASR/ASRConfig.h +++ b/src/platform/ASR/ASRConfig.h @@ -25,8 +25,6 @@ #pragma once -// #include - #include "asr_factory_config.h" #include diff --git a/src/platform/ASR/ASROTAImageProcessor.cpp b/src/platform/ASR/ASROTAImageProcessor.cpp index beb7e6e4d2e534..92a3ab08a4da7b 100644 --- a/src/platform/ASR/ASROTAImageProcessor.cpp +++ b/src/platform/ASR/ASROTAImageProcessor.cpp @@ -150,9 +150,8 @@ void ASROTAImageProcessor::HandleApply(intptr_t context) ChipLogProgress(SoftwareUpdate, "ASROTAImageProcessor::HandleApply()"); imageProcessor->ota_boot_para.res_type = LEGA_OTA_FINISH; + // Set boot mode and then reboot lega_ota_set_boot(&imageProcessor->ota_boot_para); - - // reboot(); } void ASROTAImageProcessor::HandleAbort(intptr_t context) @@ -217,7 +216,6 @@ CHIP_ERROR ASROTAImageProcessor::ProcessHeader(ByteSpan & block) ReturnErrorCodeIf(error == CHIP_ERROR_BUFFER_TOO_SMALL, CHIP_NO_ERROR); ReturnErrorOnFailure(error); - // SL TODO -- store version somewhere ChipLogProgress(SoftwareUpdate, "Image Header software version: %ld payload size: %lu", header.mSoftwareVersion, (long unsigned int) header.mPayloadSize); mParams.totalFileBytes = header.mPayloadSize; diff --git a/src/platform/ASR/ASRUtils.cpp b/src/platform/ASR/ASRUtils.cpp index cecf87f2e20d45..1961de38e834bf 100644 --- a/src/platform/ASR/ASRUtils.cpp +++ b/src/platform/ASR/ASRUtils.cpp @@ -288,9 +288,6 @@ CHIP_ERROR ASRUtils::asr_wifi_connect(void) strncpy((char *) conf.wifi_key, (char *) stationConfig.wifi_key, stationConfig.key_len); conf.security = stationConfig.security; - // before wlan open with sta mode, make sure the wlan is closed. - // lega_wlan_close(); - ChipLogProgress(DeviceLayer, "Connecting to AP : [%s]\r\n", StringOrNullMarker(conf.wifi_ssid)); lega_wlan_clear_pmk(); diff --git a/src/platform/ASR/ConnectivityManagerImpl.cpp b/src/platform/ASR/ConnectivityManagerImpl.cpp index 6e828c897f1e19..b24e6ffe19567b 100644 --- a/src/platform/ASR/ConnectivityManagerImpl.cpp +++ b/src/platform/ASR/ConnectivityManagerImpl.cpp @@ -42,10 +42,9 @@ #include #include +#include "lega_wlan_api.h" #include "lwip/opt.h" #include -// asr wifi -#include "lega_wlan_api.h" #if !CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION #error "WiFi Station support must be enabled when building for ASR" #endif diff --git a/src/platform/ASR/KeyValueStoreManagerImpl.cpp b/src/platform/ASR/KeyValueStoreManagerImpl.cpp index bc499ae3a046fd..546cdea029592b 100644 --- a/src/platform/ASR/KeyValueStoreManagerImpl.cpp +++ b/src/platform/ASR/KeyValueStoreManagerImpl.cpp @@ -44,7 +44,7 @@ KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance; CHIP_ERROR KeyValueStoreManagerImpl::Init() { - // duet_flash_kv_init(); + // KV has already been initialized at init_asrPlatform(), so return success return CHIP_NO_ERROR; } diff --git a/src/platform/ASR/NetworkCommissioningWiFiDriver.cpp b/src/platform/ASR/NetworkCommissioningWiFiDriver.cpp index 5c8167569f8e78..d7ed6266706c58 100644 --- a/src/platform/ASR/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/ASR/NetworkCommissioningWiFiDriver.cpp @@ -15,14 +15,14 @@ * limitations under the License. */ +#include "lega_wlan_api.h" #include #include +#include #include #include #include #include - -#include #include using namespace ::chip; @@ -184,8 +184,7 @@ void ASRWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callbac callback->OnResult(networkingStatus, CharSpan(), 0); } } -// asr wifi -#include "lega_wlan_api.h" + CHIP_ERROR ASRWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid) { if (ASRUtils::EnableStationMode() != CHIP_NO_ERROR) diff --git a/src/platform/ASR/PlatformManagerImpl.h b/src/platform/ASR/PlatformManagerImpl.h index 890fefd72f74de..1a16797c8a9bcc 100644 --- a/src/platform/ASR/PlatformManagerImpl.h +++ b/src/platform/ASR/PlatformManagerImpl.h @@ -29,6 +29,8 @@ #include #endif #include +#include + namespace chip { namespace DeviceLayer { diff --git a/src/platform/ASR/args.gni b/src/platform/ASR/args.gni index 85217656032436..4301315205975a 100755 --- a/src/platform/ASR/args.gni +++ b/src/platform/ASR/args.gni @@ -14,6 +14,8 @@ import("//build_overrides/chip.gni") +import("${chip_root}/examples/platform/asr/args.gni") + riscv_platform_config = "${chip_root}/third_party/asr/asr_riscv.gni" chip_device_platform = "asr"