Skip to content

Commit df45f10

Browse files
committed
[NXP] add support for rw61x Zephyr on build_examples
With the current change, NXP Matter apps using Zephyr can be built using the build_examples.py. Build examples that are supported are: * all-clusters-app * laundry-washer * thermostat Build variants that are supported for now: * build with factory data More variants can be added later.
1 parent c23e116 commit df45f10

File tree

4 files changed

+108
-26
lines changed

4 files changed

+108
-26
lines changed

.github/workflows/examples-nxp.yaml

+12-12
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,36 @@ jobs:
6060
run: |
6161
scripts/run_in_build_env.sh "\
6262
./scripts/build/build_examples.py \
63-
--target nxp-k32w0-lighting \
64-
--target nxp-k32w0-lighting-factory \
65-
--target nxp-k32w0-lighting-rotating-id \
66-
--target nxp-k32w0-contact-sensor \
67-
--target nxp-k32w0-contact-sensor-low-power \
68-
--target nxp-k32w0-contact-sensor-low-power-factory \
69-
--target nxp-k32w1-lighting \
70-
--target nxp-k32w1-contact-sensor-low-power \
63+
--target nxp-k32w0-freertos-lighting \
64+
--target nxp-k32w0-freertos-lighting-factory \
65+
--target nxp-k32w0-freertos-lighting-rotating-id \
66+
--target nxp-k32w0-freertos-contact-sensor \
67+
--target nxp-k32w0-freertos-contact-sensor-low-power \
68+
--target nxp-k32w0-freertos-contact-sensor-low-power-factory \
69+
--target nxp-k32w1-freertos-lighting \
70+
--target nxp-k32w1-freertos-contact-sensor-low-power \
7171
build \
7272
--copy-artifacts-to out/artifacts \
7373
"
7474
- name: Get lighting app size stats
7575
run: |
7676
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
7777
nxp k32w0+release light \
78-
out/artifacts/nxp-k32w0-lighting/chip-k32w0x-light-example.elf \
78+
out/artifacts/nxp-k32w0-freertos-lighting/chip-k32w0x-light-example.elf \
7979
/tmp/bloat_reports/
8080
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
8181
nxp k32w1+release light \
82-
out/artifacts/nxp-k32w1-lighting/chip-k32w1-light-example.elf \
82+
out/artifacts/nxp-k32w1-freertos-lighting/chip-k32w1-light-example.elf \
8383
/tmp/bloat_reports/
8484
- name: Get contact sensor size stats
8585
run: |
8686
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
8787
nxp k32w0+release contact \
88-
out/artifacts/nxp-k32w0-contact-sensor-low-power/chip-k32w0x-contact-example.elf \
88+
out/artifacts/nxp-k32w0-freertos-contact-sensor-low-power/chip-k32w0x-contact-example.elf \
8989
/tmp/bloat_reports/
9090
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
9191
nxp k32w1+release contact \
92-
out/artifacts/nxp-k32w1-contact-sensor-low-power/chip-k32w1-contact-example.elf \
92+
out/artifacts/nxp-k32w1-freertos-contact-sensor-low-power/chip-k32w1-contact-example.elf \
9393
/tmp/bloat_reports/
9494
- name: Uploading Size Reports
9595
uses: ./.github/actions/upload-size-reports

scripts/build/build/targets.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from builders.mw320 import MW320App, MW320Builder
2929
from builders.nrf import NrfApp, NrfBoard, NrfConnectBuilder
3030
from builders.nuttx import NuttXApp, NuttXBoard, NuttXBuilder
31-
from builders.nxp import NxpApp, NxpBoard, NxpBuilder
31+
from builders.nxp import NxpApp, NxpBoard, NxpBuilder, NxpOsUsed
3232
from builders.openiotsdk import OpenIotSdkApp, OpenIotSdkBuilder, OpenIotSdkCryptoBackend
3333
from builders.qpg import QpgApp, QpgBoard, QpgBuilder
3434
from builders.rw61x import RW61XApp, RW61XBuilder
@@ -499,22 +499,32 @@ def BuildNxpTarget():
499499
# boards
500500
target.AppendFixedTargets([
501501
TargetPart('k32w0', board=NxpBoard.K32W0),
502-
TargetPart('k32w1', board=NxpBoard.K32W1)
502+
TargetPart('k32w1', board=NxpBoard.K32W1),
503+
TargetPart('rw61x', board=NxpBoard.RW61X)
504+
])
505+
506+
# OS
507+
target.AppendFixedTargets([
508+
TargetPart('zephyr', os_env=NxpOsUsed.ZEPHYR).OnlyIfRe('rw61x'),
509+
TargetPart('freertos', os_env=NxpOsUsed.FREERTOS).ExceptIfRe('rw61x'),
503510
])
504511

505512
# apps
506513
target.AppendFixedTargets([
507514
TargetPart('lighting', app=NxpApp.LIGHTING).OnlyIfRe('(k32w0|k32w1)'),
508-
TargetPart('contact-sensor', app=NxpApp.CONTACT).OnlyIfRe('(k32w0|k32w1)')
515+
TargetPart('contact-sensor', app=NxpApp.CONTACT).OnlyIfRe('(k32w0|k32w1)'),
516+
TargetPart('all-clusters', app=NxpApp.ALLCLUSTERS).OnlyIfRe('rw61x'),
517+
TargetPart('laundry-washer', app=NxpApp.LAUNDRYWASHER).OnlyIfRe('rw61x'),
518+
TargetPart('thermostat', app=NxpApp.THERMOSTAT).OnlyIfRe('rw61x')
509519
])
510520

511521
target.AppendModifier(name="factory", enable_factory_data=True)
512522
target.AppendModifier(name="low-power", low_power=True).OnlyIfRe('contact-sensor')
513523
target.AppendModifier(name="lit", enable_lit=True).OnlyIfRe('contact-sensor')
514524
target.AppendModifier(name="fro32k", use_fro32k=True).OnlyIfRe('k32w0')
515525
target.AppendModifier(name="smu2", smu2=True).OnlyIfRe('k32w1-lighting')
516-
target.AppendModifier(name="dac-conversion", convert_dac_pk=True).OnlyIfRe('factory').ExceptIfRe('k32w0')
517-
target.AppendModifier(name="rotating-id", enable_rotating_id=True)
526+
target.AppendModifier(name="dac-conversion", convert_dac_pk=True).OnlyIfRe('factory').ExceptIfRe('(k32w0|rw61x)')
527+
target.AppendModifier(name="rotating-id", enable_rotating_id=True).ExceptIfRe('rw61x')
518528
target.AppendModifier(name="sw-v2", has_sw_version_2=True)
519529

520530
return target

scripts/build/builders/nxp.py

+80-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021 Project CHIP Authors
1+
# Copyright (c) 2021-2024 Project CHIP Authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,22 +12,36 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import logging
1516
import os
1617
from enum import Enum, auto
1718

1819
from .builder import BuilderOutput
1920
from .gn import GnBuilder
2021

22+
class NxpOsUsed(Enum):
23+
FREERTOS = auto()
24+
ZEPHYR = auto()
25+
def OsEnv(self):
26+
if self == NxpOsUsed.ZEPHYR:
27+
return 'zephyr'
28+
elif self == NxpOsUsed.FREERTOS:
29+
return 'freertos'
30+
else:
31+
raise Exception('Unknown OS type: %r' % self)
2132

2233
class NxpBoard(Enum):
2334
K32W0 = auto()
2435
K32W1 = auto()
36+
RW61X = auto()
2537

2638
def Name(self):
2739
if self == NxpBoard.K32W0:
2840
return 'k32w0x'
2941
elif self == NxpBoard.K32W1:
3042
return 'k32w1'
43+
elif self == NxpBoard.RW61X:
44+
return 'rd_rw612_bga'
3145
else:
3246
raise Exception('Unknown board type: %r' % self)
3347

@@ -36,19 +50,30 @@ def FolderName(self):
3650
return 'k32w/k32w0'
3751
elif self == NxpBoard.K32W1:
3852
return 'k32w/k32w1'
53+
elif self == NxpBoard.RW61X:
54+
return 'zephyr'
3955
else:
4056
raise Exception('Unknown board type: %r' % self)
4157

4258

4359
class NxpApp(Enum):
4460
LIGHTING = auto()
4561
CONTACT = auto()
62+
ALLCLUSTERS = auto()
63+
LAUNDRYWASHER = auto()
64+
THERMOSTAT = auto()
4665

4766
def ExampleName(self):
4867
if self == NxpApp.LIGHTING:
4968
return 'lighting-app'
5069
elif self == NxpApp.CONTACT:
5170
return "contact-sensor-app"
71+
elif self == NxpApp.ALLCLUSTERS:
72+
return "all-clusters-app"
73+
elif self == NxpApp.LAUNDRYWASHER:
74+
return "laundry-washer-app"
75+
elif self == NxpApp.THERMOSTAT:
76+
return "thermostat"
5277
else:
5378
raise Exception('Unknown app type: %r' % self)
5479

@@ -57,6 +82,12 @@ def NameSuffix(self):
5782
return 'light-example'
5883
elif self == NxpApp.CONTACT:
5984
return 'contact-example'
85+
elif self == NxpApp.ALLCLUSTERS:
86+
return "all-cluster-example"
87+
elif self == NxpApp.LAUNDRYWASHER:
88+
return "laundry-washer-example"
89+
elif self == NxpApp.THERMOSTAT:
90+
return "thermostat-example"
6091
else:
6192
raise Exception('Unknown app type: %r' % self)
6293

@@ -71,6 +102,7 @@ def __init__(self,
71102
runner,
72103
app: NxpApp = NxpApp.LIGHTING,
73104
board: NxpBoard = NxpBoard.K32W0,
105+
os_env: NxpOsUsed = NxpOsUsed.FREERTOS,
74106
low_power: bool = False,
75107
smu2: bool = False,
76108
enable_factory_data: bool = False,
@@ -85,6 +117,7 @@ def __init__(self,
85117
self.code_root = root
86118
self.app = app
87119
self.board = board
120+
self.os_env = os_env
88121
self.low_power = low_power
89122
self.smu2 = smu2
90123
self.enable_factory_data = enable_factory_data
@@ -125,15 +158,54 @@ def GnBuildArgs(self):
125158

126159
return args
127160

161+
def WestBuildArgs(self):
162+
args = []
163+
if self.enable_factory_data:
164+
args.append('-DFILE_SUFFIX=fdata')
165+
166+
if self.has_sw_version_2:
167+
args.append('-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2')
168+
169+
build_args = " -- " + " ".join(args) if len(args) > 0 else ""
170+
return build_args
171+
128172
def generate(self):
129-
super(NxpBuilder, self).generate()
173+
if self.os_env == NxpOsUsed.ZEPHYR:
174+
if 'ZEPHYR_NXP_SDK_INSTALL_DIR' in os.environ:
175+
cmd = 'export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_NXP_SDK_INSTALL_DIR"\n'
176+
else:
177+
raise Exception("ZEPHYR_SDK_INSTALL_DIR need to be set")
178+
if 'ZEPHYR_NXP_BASE' in os.environ:
179+
cmd += 'export ZEPHYR_BASE="$ZEPHYR_NXP_BASE"\n'
180+
else:
181+
raise Exception("ZEPHYR_NXP_BASE need to be set")
182+
build_args = self.WestBuildArgs()
183+
cmd += '''
184+
west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_args}
185+
'''.format(
186+
board_name = self.board.Name(),
187+
out_folder = self.output_dir,
188+
example_folder = self.app.BuildRoot(self.code_root, self.board),
189+
build_args=build_args).strip()
190+
self._Execute(['bash', '-c', cmd], title='Generating ' + self.identifier)
191+
else:
192+
super(NxpBuilder, self).generate()
130193

131194
def build_outputs(self):
132195
name = 'chip-%s-%s' % (self.board.Name(), self.app.NameSuffix())
133-
yield BuilderOutput(
134-
os.path.join(self.output_dir, name),
135-
f'{name}.elf')
136-
if self.options.enable_link_map_file:
196+
if self.os_env == NxpOsUsed.ZEPHYR:
197+
yield BuilderOutput(
198+
os.path.join(self.output_dir, 'zephyr', 'zephyr.elf'),
199+
f'{name}.elf')
200+
if self.options.enable_link_map_file:
201+
yield BuilderOutput(
202+
os.path.join(self.output_dir, 'zephyr', 'zephyr.map'),
203+
f'{name}.map')
204+
else:
137205
yield BuilderOutput(
138-
os.path.join(self.output_dir, f'{name}.map'),
139-
f'{name}.map')
206+
os.path.join(self.output_dir, name),
207+
f'{name}.elf')
208+
if self.options.enable_link_map_file:
209+
yield BuilderOutput(
210+
os.path.join(self.output_dir, f'{name}.map'),
211+
f'{name}.map')

scripts/build/testdata/all_targets_linux_x64.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ linux-x64-efr32-test-runner[-clang]
1414
imx-{chip-tool,lighting-app,thermostat,all-clusters-app,all-clusters-minimal-app,ota-provider-app}[-release]
1515
infineon-psoc6-{lock,light,all-clusters,all-clusters-minimal}[-ota][-updateimage][-trustm]
1616
rw61x-{all-clusters-app,thermostat,laundry-washer}[-ota][-wifi][-thread][-factory-data][-matter-shell]
17-
nxp-{k32w0,k32w1}-{lighting,contact-sensor}[-factory][-low-power][-lit][-fro32k][-smu2][-dac-conversion][-rotating-id][-sw-v2]
17+
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]
1818
mbed-cy8cproto_062_4343w-{lock,light,all-clusters,all-clusters-minimal,pigweed,ota-requestor,shell}[-release][-develop][-debug]
1919
mw320-all-clusters-app
2020
nrf-{nrf5340dk,nrf52840dk,nrf52840dongle}-{all-clusters,all-clusters-minimal,lock,light,light-switch,shell,pump,pump-controller,window-covering}[-rpc]

0 commit comments

Comments
 (0)