Skip to content

Commit

Permalink
update build_examples.py build support,update README
Browse files Browse the repository at this point in the history
  • Loading branch information
asriot committed May 11, 2023
1 parent d19e64c commit 41fd6bc
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 25 deletions.
1 change: 0 additions & 1 deletion .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ ASAN
asdk
AssertionError
ASR
asr
AST
ASYNC
atomics
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/asr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ asr_sdk_sources("lighting_app_sdk_sources") {
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}",
]

if (chip_use_factory) {
if (chip_enable_factory_data) {
defines += [
"CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER=1",
"CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER=1",
Expand Down
60 changes: 38 additions & 22 deletions examples/lighting-app/asr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This example demonstrates the Matter Lighting application on ASR platform.
- [Commissioning](#commissioning)
- [BLE mode](#ble-mode)
- [IP mode](#ip-mode)
- [Cluster Control](#cluster-control)

---

Expand All @@ -34,28 +35,22 @@ The CHIP demo application is supported on:
```
export ASR_TOOLCHAIN_PATH={path-to-toolchain}/asr_riscv_gnu_toolchain_10.2_ubuntu-16.04/bin/
```
- Setup environment for ASR582X:
- Setup Chip environment
- for ASR582X:
```
export ASR_BOARD=asr582x
```
- for ASR595X:
```
export ASR_BOARD=asr595x
```
- Building the Application
```
export ASR_IC=asr582x
export ASR_ARCH=arm
./scripts/build/build_examples.py --target asr-$ASR_BOARD-lighting build
```
for ASR595X:
```
export ASR_IC=asr595x
export ASR_ARCH=riscv
```
- Setup ASR SDK:
```
export ASR_SDK_ROOT=//third_party/connectedhomeip/third_party/asr/$ASR_IC
```
- To build the demo application:
```
./scripts/examples/gn_build_example.sh ./examples/lighting-app/asr out/example_app \
custom_toolchain=\"//../../../config/asr/toolchain:asrtoolchain\" target_cpu=\"$ASR_ARCH\" \
asr_ic_family=\"$ASR_IC\" asr_sdk_build_root=\"$ASR_SDK_ROOT\" \
mbedtls_target=\"$ASR_SDK_ROOT:asr_build\" asr_toolchain_root=\"$ASR_TOOLCHAIN_PATH\"
```
- The output image files are stored in `out/example_app` folder.
- 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.
Expand All @@ -69,7 +64,7 @@ There are two commissioning modes supported by ASR platform:
1. Build and Flash
2. The example will run automatically after booting the ASR board.
3. Restore factory settings using command `recovery`
4. Test with
4. Commissioning with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
### IP mode
Expand All @@ -78,5 +73,26 @@ There are two commissioning modes supported by ASR platform:
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. Test with
5. Commissioning with
[Chip-Tool](https://github.com/project-chip/connectedhomeip/tree/master/examples/chip-tool)
## Cluster Control
After successful commissioning, use `chip-tool` to control the board
- OnOff Cluster
```
./chip-tool onoff on <NODE ID> 1
./chip-tool onoff off <NODE ID> 1
./chip-tool onoff toggle <NODE ID> 1
```
- LevelControl Cluster
```
./chip-tool levelcontrol move-to-level 128 10 0 0 <NODE ID> 1
```
- ColorControl Cluster
```
./chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 <NODE ID> 1
```
2 changes: 1 addition & 1 deletion examples/lighting-app/asr/cfg.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

declare_args() {
chip_use_factory = false
chip_enable_factory_data = false

chip_lwip_ip6_hook = false

Expand Down
1 change: 1 addition & 0 deletions scripts/build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pw_python_package("build_examples") {
"builders/__init__.py",
"builders/ameba.py",
"builders/android.py",
"builders/asr.py",
"builders/bouffalolab.py",
"builders/builder.py",
"builders/efr32.py",
Expand Down
24 changes: 24 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from builders.ameba import AmebaApp, AmebaBoard, AmebaBuilder
from builders.android import AndroidApp, AndroidBoard, AndroidBuilder, AndroidProfile
from builders.asr import ASRApp, ASRBoard, ASRBuilder
from builders.bouffalolab import BouffalolabApp, BouffalolabBoard, BouffalolabBuilder
from builders.cc13x2x7_26x2x7 import cc13x2x7_26x2x7App, cc13x2x7_26x2x7Builder
from builders.cc32xx import cc32xxApp, cc32xxBuilder
Expand Down Expand Up @@ -371,6 +372,28 @@ def BuildAmebaTarget():
return target


def BuildASRTarget():
target = BuildTarget('asr', ASRBuilder)

# board
target.AppendFixedTargets([
TargetPart('asr582x', board=ASRBoard.ASR582X),
TargetPart('asr595x', board=ASRBoard.ASR595X),
])

# apps
target.AppendFixedTargets([
TargetPart('lighting', app=ASRApp.LIGHT),
])

# modifiers
target.AppendModifier('ota', enable_ota_requestor=True)
target.AppendModifier('shell', chip_build_libshell=True)
target.AppendModifier('no_logging', chip_logging=False)

return target


def BuildK32WTarget():
target = BuildTarget('k32w', K32WBuilder)

Expand Down Expand Up @@ -581,6 +604,7 @@ def BuildOpenIotSdkTargets():

BUILD_TARGETS = [
BuildAmebaTarget(),
BuildASRTarget(),
BuildAndroidTarget(),
BuildBouffalolabTarget(),
Buildcc13x2x7_26x2x7Target(),
Expand Down
122 changes: 122 additions & 0 deletions scripts/build/builders/asr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 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.

import os
from enum import Enum, auto

from .gn import GnBuilder


class ASRApp(Enum):
LIGHT = auto()

def ExampleName(self):
if self == ASRApp.LIGHT:
return 'lighting-app'
else:
raise Exception('Unknown app type: %r' % self)

def AppNamePrefix(self):
if self == ASRApp.LIGHT:
return 'chip-asr-lighting-app'
else:
raise Exception('Unknown app type: %r' % self)

def BuildRoot(self, root):
return os.path.join(root, 'examples', self.ExampleName(), 'asr')


class ASRBoard(Enum):
ASR582X = auto()
ASR595X = auto()

def GetIC(self):
if self == ASRBoard.ASR582X:
return 'asr582x'
elif self == ASRBoard.ASR595X:
return 'asr595x'
else:
raise Exception('Unknown board #: %r' % self)


class ASRBuilder(GnBuilder):

def __init__(self,
root,
runner,
app: ASRApp = ASRApp.LIGHT,
board: ASRBoard = ASRBoard.ASR582X,
chip_build_libshell: bool = False,
chip_logging: bool = True,
enable_factory: bool = False,
enable_ota_requestor: bool = False):
super(ASRBuilder, self).__init__(
root=app.BuildRoot(root),
runner=runner)

self.board = board
self.app = app

asr_chip = self.board.GetIC()
self.extra_gn_options = ['asr_ic_family="%s"' % asr_chip]

if asr_chip == "asr582x":
ASR_ARCH = "arm"
ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr582x"
elif asr_chip == "asr595x":
ASR_ARCH = "riscv"
ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr595x"
self.extra_gn_options.append('target_cpu="%s"' % ASR_ARCH)

toolchain = os.path.join(root, os.path.split(os.path.realpath(__file__))[0], '../../../config/asr/toolchain')
toolchain = 'custom_toolchain="{}:asrtoolchain"'.format(toolchain)
if toolchain:
self.extra_gn_options.append(toolchain)

self.extra_gn_options.append('asr_sdk_build_root="%s"' % ASR_SDK_ROOT)
self.extra_gn_options.append('mbedtls_target="%s:asr_build"' % ASR_SDK_ROOT)

if (asr_chip == "asr582x"
or asr_chip == "asr595x"):
self.extra_gn_options.append('chip_config_network_layer_ble=true')

if enable_ota_requestor:
self.extra_gn_options.append('chip_enable_ota_requestor=true')

if chip_build_libshell:
self.extra_gn_options.append('chip_build_libshell=true')

if chip_logging is False:
self.extra_gn_options.append('chip_logging=false')

if enable_factory:
self.extra_gn_options.append('chip_use_transitional_commissionable_data_provider=false')
self.extra_gn_options.append('chip_enable_factory_data=true')

self.extra_gn_options.append('asr_toolchain_root="%s"' % os.environ['ASR_TOOLCHAIN_PATH'])

def GnBuildArgs(self):
return self.extra_gn_options

def build_outputs(self):
items = {
'%s.out' % self.app.AppNamePrefix():
os.path.join(self.output_dir, '%s.out' %
self.app.AppNamePrefix()),
'%s.out.map' % self.app.AppNamePrefix():
os.path.join(self.output_dir,
'%s.out.map' % self.app.AppNamePrefix()),
}

return items

0 comments on commit 41fd6bc

Please sign in to comment.