Skip to content

Commit

Permalink
Chef Sample App - yaml configuration file (project-chip#17330)
Browse files Browse the repository at this point in the history
* chg: removed config file, SDK path needs to be set as environment variable

Change-Id: Ied6a186f5d7370818461f921e76309a0508aaaf5

* chg: config file is now a YAML file

Change-Id: Ia34b45c1e54245b94da06dca626170a78581b7b9

* chg: zap-generated files in independent folders by device type

Change-Id: If86a393576166a03f1aa801947b36233308e6df4

* fix: fixes CMakeLists files for ESP32 and nrfconnect to build on current tot

Change-Id: Ia6f94dfc6a186036f41af1c567b4b8416ff2ef22

* chg: applied restyle

Change-Id: I38f52568e0a7f967b35ad42ca7ade1373235c3fe

* fix: added a words to .wordslist

Change-Id: I84a7cb6ea7830146711450d0d713b9da2fd895b4

* Update .wordlist.txt

* Update README.md

* Update README.md

* Update .wordlist.txt

* fix: reverted unwanted change to submodule hash reference

Change-Id: I15fee54e792d8aa06d83051b803c9e27093d29d3
  • Loading branch information
rochaferraz authored and vinitg1 committed Apr 22, 2022
1 parent 824b0e2 commit 0beddff
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 95 deletions.
2 changes: 1 addition & 1 deletion examples/chef/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zap-generated
config.yaml
project_include.cmake
linux/args.gni
linux/sample.gni
30 changes: 26 additions & 4 deletions examples/chef/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@ Run `chef.py -h` to see the available commands
## Building your first sample

1. Make sure you have the toolchain installed for your desired target
2. Update your SoC SDK paths on `chef_config.py` and flip the `configured`
variable to True
3. Run `$ chef.py -u` to update zap and the toolchain (on selected platforms)
4. Run `$ chef.py -gzbf -t <platform> -d lighting`. This command will run the
2. Run `chef.py` the first time to create a `config.yaml` configuration file. If
you already have SDK environment variables such as IDF_PATH (esp32) and
ZEPHYR_BASE (nrfconnect) it will use those values as default.
3. Update your the SDK paths on `config.yaml`. TTY is the path used by the
platform to enumerate its device as a serial port. Typical values are:

```
# ESP32 macOS
TTY: /dev/tty.usbmodemXXXXXXX
# ESP32 Linux
TTY: /dev/ttyACM0
# NRFCONNECT macOS
TTY: /dev/tty.usbserial-XXXXX
# NRFCONNECT Linux
TTY: /dev/ttyUSB0
```

4. Run `$ chef.py -u` to update zap and the toolchain (on selected platforms)
5. Run `$ chef.py -gzbf -t <platform> -d lighting`. This command will run the
ZAP GUI opening the `devices/lighting.zap` file and will allow editing. It
will then generate the zap artifacts, place them on the `zap-generated`
folder, run a build and flash the binary in your target
Expand Down
101 changes: 71 additions & 30 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import os
import subprocess
from pathlib import Path
import chef_config as config
from sys import platform
import yaml

global commandQueue
commandQueue = ""
Expand Down Expand Up @@ -50,13 +50,39 @@ def printc(strInput):
print(color + strInput + TermColors.STRRESET)


def loadConfig(paths):
config = dict()
config["nrfconnect"] = dict()
config["esp32"] = dict()

configFile = paths["scriptFolder"] + "/config.yaml"
if (os.path.exists(configFile)):
configStream = open(configFile, 'r')
config = yaml.load(configStream, Loader=yaml.SafeLoader)
configStream.close()
else:
print("Running for the first time and configuring config.yaml. " +
"Change this configuration file to include correct configuration " +
"for the vendor's SDK")
configStream = open(configFile, 'w')
config["nrfconnect"]["ZEPHYR_BASE"] = os.environ.get('ZEPHYR_BASE')
config["nrfconnect"]["TTY"] = None
config["esp32"]["IDF_PATH"] = os.environ.get('IDF_PATH')
config["esp32"]["TTY"] = None
print(yaml.dump(config))
yaml.dump(config, configStream)
configStream.close()

return config


def definePaths():
paths = dict()
paths["scriptFolder"] = os.path.abspath(os.path.dirname(__file__))
paths["matterFolder"] = paths["scriptFolder"] + "/../../"
paths["rootSampleFolder"] = paths["scriptFolder"]
paths["genFolder"] = paths["rootSampleFolder"] + "/zap-generated"
paths["devices"] = []

for filepath in Path(f"{paths['rootSampleFolder']}/devices").rglob('*.zap'):
paths["devices"].append(
str(os.path.splitext(os.path.basename(filepath))[0]))
Expand Down Expand Up @@ -108,6 +134,8 @@ def hexInputToInt(valIn):
def main(argv):
checkPythonVersion()
paths = definePaths()
config = loadConfig(paths)

global myEnv
myEnv = os.environ.copy()

Expand All @@ -124,13 +152,6 @@ def main(argv):
print('Windows is currently not supported. Use Linux or MacOS platforms')
exit(1)

#
# Checks if user has configured its custom settings
#
if not config.configured:
print('Please edit chef_config.py file and change the <configured> flag to True')
exit(1)

#
# Arguments parser
#
Expand All @@ -140,7 +161,7 @@ def main(argv):
usage = f'''usage: chef.py [options]
Platforms:
nrf52840dk_nrf52840
nrfconnect
esp32
linux
Expand Down Expand Up @@ -179,7 +200,7 @@ def main(argv):
action='store',
dest="buildTarget",
help="specifies target platform. Default is esp32. See info below for currently supported target platforms",
choices=['nrf52840dk_nrf52840', 'esp32', 'linux', ],
choices=['nrfconnect', 'esp32', 'linux', ],
metavar="TARGET",
default="esp32")
parser.add_option("-r", "--rpc", help="enables Pigweed RPC interface. Enabling RPC disables the shell interface. Your sdkconfig configurations will be reverted to default. Default is PW RPC off. When enabling or disabling this flag, on the first build force a clean build with -c", action="store_true", dest="doRPC")
Expand All @@ -189,6 +210,8 @@ def main(argv):
help="specifies the Product ID. Default is 0x8000", metavar="PID", default=0x8000)
parser.add_option("", "--rpc_console", help="Opens PW RPC Console",
action="store_true", dest="doRPC_CONSOLE")
parser.add_option("-y", "--tty", help="Enumerated USB tty/serial interface enumerated for your physical device. E.g.: /dev/ACM0",
dest="tty", metavar="TTY", default=None)

options, _ = parser.parse_args(argv)

Expand All @@ -199,15 +222,23 @@ def main(argv):
#

queuePrint(f"Target is set to {options.sampleDeviceTypeName}")
paths["genFolder"] = paths["rootSampleFolder"] + f"/out/{options.sampleDeviceTypeName}/zap-generated/"

queuePrint("Setting up environment...")
if options.buildTarget == "esp32":
if config['esp32']['IDF_PATH'] is None:
print('Path for esp32 SDK was not found. Make sure esp32.IDF_PATH is set on your config.yaml file')
exit(1)
paths["platFolder"] = os.path.normpath(
paths["rootSampleFolder"] + "/esp32")
queueCommand(f"source {config.esp32Folder}/export.sh")
elif options.buildTarget == "nrf52840dk_nrf52840":
queueCommand(f'source {config["esp32"]["IDF_PATH"]}/export.sh')
elif options.buildTarget == "nrfconnect":
if config['nrfconnect']['ZEPHYR_BASE'] is None:
print('Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file')
exit(1)
paths["platFolder"] = os.path.normpath(
paths["rootSampleFolder"] + "/nrfconnect")
queueCommand(f"source {config.nrfconnectFolder}/zephyr/zephyr-env.sh")
queueCommand(f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh')
queueCommand("export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb")
elif options.buildTarget == "linux":
pass
Expand All @@ -223,7 +254,7 @@ def main(argv):
if options.doUpdateToolchain:
if options.buildTarget == "esp32":
queuePrint("ESP32 toolchain update not supported. Skipping")
elif options.buildTarget == "nrf52840dk_nrf52840":
elif options.buildTarget == "nrfconnect":
queuePrint("Updating toolchain")
queueCommand(
f"cd {paths['matterFolder']} && python3 scripts/setup/nrfconnect/update_ncs.py --update")
Expand Down Expand Up @@ -264,7 +295,7 @@ def main(argv):
queueCommand(f"rm {paths['genFolder']}/*")
queueCommand(
f"{paths['matterFolder']}/scripts/tools/zap/generate.py {paths['rootSampleFolder']}/devices/{options.sampleDeviceTypeName}.zap -o {paths['genFolder']}")
# sometimes af-gen-event.h is not generated
# af-gen-event.h is not generated
queueCommand(f"touch {paths['genFolder']}/af-gen-event.h")

#
Expand All @@ -275,7 +306,7 @@ def main(argv):
if options.buildTarget == "esp32":
queueCommand(f"cd {paths['rootSampleFolder']}/esp32")
queueCommand("idf.py menuconfig")
elif options.buildTarget == "nrf52840dk_nrf52840":
elif options.buildTarget == "nrfconnect":
queueCommand(f"cd {paths['rootSampleFolder']}/nrfconnect")
queueCommand("west build -t menuconfig")
elif options.buildTarget == "linux":
Expand All @@ -301,7 +332,7 @@ def main(argv):
f"Product ID 0x{options.pid:02X} / Vendor ID 0x{options.vid:02X}")
queueCommand(f"cd {paths['rootSampleFolder']}")

if (options.buildTarget == "esp32") or (options.buildTarget == "nrf52840dk_nrf52840"):
if (options.buildTarget == "esp32") or (options.buildTarget == "nrfconnect"):
queueCommand(f'''
cat > project_include.cmake <<EOF
set(CONFIG_DEVICE_VENDOR_ID {options.vid})
Expand All @@ -316,15 +347,16 @@ def main(argv):
if options.doClean:
queueCommand(f"rm {paths['rootSampleFolder']}/esp32/sdkconfig")
queueCommand(f"cd {paths['rootSampleFolder']}/esp32")
queueCommand(f"rm -rf {paths['rootSampleFolder']}/build")
queueCommand(f"rm -rf {paths['rootSampleFolder']}/esp32/build")
queueCommand("idf.py fullclean")
queueCommand("idf.py build")
elif options.buildTarget == "nrf52840dk_nrf52840":
elif options.buildTarget == "nrfconnect":
queueCommand(f"cd {paths['rootSampleFolder']}/nrfconnect")
if options.doClean:
queueCommand(f"west build -b {options.buildTarget} -c")
# queueCommand(f"rm -rf {paths['rootSampleFolder']}/nrfconnect/build")
queueCommand(f"west build -b nrf52840dk_nrf52840")
else:
queueCommand(f"west build -b {options.buildTarget}")
queueCommand(f"west build -b nrf52840dk_nrf52840")
elif options.buildTarget == "linux":
queueCommand(f"cd {paths['rootSampleFolder']}/linux")
queueCommand(f'''
Expand Down Expand Up @@ -356,15 +388,18 @@ def main(argv):
if options.doFlash:
queuePrint("Flashing target")
if options.buildTarget == "esp32":
if config['esp32']['TTY'] is None:
print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file')
exit(1)
queueCommand(f"cd {paths['rootSampleFolder']}/esp32")
if options.doErase:
queueCommand(
f"idf.py -p {config.esp32SerialDevice} erase_flash")
queueCommand(f"idf.py -p {config.esp32SerialDevice} flash")
elif options.buildTarget == "nrf52840dk_nrf52840":
f"idf.py -p {config['esp32']['TTY']} erase-flash")
queueCommand(f"idf.py -p {config['esp32']['TTY']} flash")
elif options.buildTarget == "nrfconnect":
queueCommand(f"cd {paths['rootSampleFolder']}/nrfconnect")
if options.doErase:
queueCommand("west flash --erase")
queueCommand("rm -rf build")
else:
queueCommand("west flash")

Expand All @@ -375,11 +410,17 @@ def main(argv):
if options.doInteract:
queuePrint("Starting terminal...")
if options.buildTarget == "esp32":
if config['esp32']['TTY'] is None:
print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file')
exit(1)
queueCommand(f"cd {paths['rootSampleFolder']}/esp32")
queueCommand(f"idf.py -p {config.esp32SerialDevice} monitor")
elif options.buildTarget == "nrf52840dk_nrf52840":
queueCommand(f"idf.py -p {config['esp32']['TTY']} monitor")
elif options.buildTarget == "nrfconnect":
if config['nrfconnect']['TTY'] is None:
print('The path for the serial enumeration for nordic is not set. Make sure nrfconnect.TTY is set on your config.yaml file')
exit(1)
queueCommand("killall screen")
queueCommand(f"screen {config.nrfConnectSerialDevice} 115200")
queueCommand(f"screen {config['nrfconnect']['TTY']} 115200")
elif options.buildTarget == "linux":
queuePrint(
f"{paths['rootSampleFolder']}/linux/out/{options.sampleDeviceTypeName}")
Expand All @@ -391,7 +432,7 @@ def main(argv):
#
if options.doRPC_CONSOLE:
queueCommand(
f"python3 -m chip_rpc.console --device {config.esp32SerialDevice}")
f"python3 -m chip_rpc.console --device {config['esp32']['TTY']}")

queuePrint("Done")

Expand Down
17 changes: 0 additions & 17 deletions examples/chef/chef_config.py

This file was deleted.

3 changes: 2 additions & 1 deletion examples/chef/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../.. REALPATH)
get_filename_component(CHEF ${CMAKE_CURRENT_SOURCE_DIR}/../../ REALPATH)
get_filename_component(GEN_DIR ${CHEF}/zap-generated/ REALPATH)
get_filename_component(GEN_DIR ${CHEF}/out/${SAMPLE_NAME}/zap-generated REALPATH)

# include(${CMAKE_CURRENT_LIST_DIR}/../../project_include.cmake)

Expand All @@ -33,6 +33,7 @@ set(PRIV_INCLUDE_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/third_party/nlio/repo/include"
"${CMAKE_SOURCE_DIR}/../"
"${GEN_DIR}/../"
"${CMAKE_SOURCE_DIR}/main/include/"
)

Expand Down
4 changes: 3 additions & 1 deletion examples/chef/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ void printQRCode()
void InitServer(intptr_t)
{
// Start IM server
chip::Server::GetInstance().Init();
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
chip::Server::GetInstance().Init(initParams);

// Device Attestation & Onboarding codes
chip::Credentials::SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());
Expand Down
3 changes: 2 additions & 1 deletion examples/chef/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ project_dir = "./.."
chip_data_model("chef-data-model") {
zap_file = "${project_dir}/devices/${sample_zap_file}"

zap_pregenerated_dir = "${chip_root}/examples/chef/zap-generated"
zap_pregenerated_dir =
"${chip_root}/examples/chef/out/${sample_name}/zap-generated/"
is_server = true
}

Expand Down
21 changes: 13 additions & 8 deletions examples/chef/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connect
get_filename_component(NRFCONNECT_COMMON ${CHIP_ROOT}/examples/platform/nrfconnect REALPATH)
get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH)
get_filename_component(CHEF ${CMAKE_CURRENT_SOURCE_DIR}/../ REALPATH)
get_filename_component(GEN_DIR ${CHEF}/zap-generated/ REALPATH)

include(${CHIP_ROOT}/config/nrfconnect/app/check-nrfconnect-version.cmake)
include(${CHEF}/project_include.cmake)

get_filename_component(GEN_DIR ${CHEF}/out/${SAMPLE_NAME}/zap-generated REALPATH)

set(CONF_FILE prj.conf)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID}")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${CONFIG_DEVICE_VENDOR_ID}")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_PLATFORM_NRFCONNECT=1")
message(STATUS "Product ID " ${CONFIG_DEVICE_PRODUCT_ID})
message(STATUS "Vendor ID " ${CONFIG_DEVICE_VENDOR_ID})

# Load NCS/Zephyr build system
set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)
# Set Kconfig root files that will be processed as a first Kconfig for used child images.
set(mcuboot_KCONFIG_ROOT ${CHIP_ROOT}/config/nrfconnect/chip-module/Kconfig.mcuboot.root)
set(multiprotocol_rpmsg_KCONFIG_ROOT ${CHIP_ROOT}/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.root)

list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.conf)
list(APPEND CONF_FILE boards/${BOARD}.conf)
endif()

list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-nrfconnect-shell-example)
project(chip-nrfconnect-chef-example)

include(${CHIP_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)
include(${CHIP_ROOT}/src/app/chip_data_model.cmake)
Expand All @@ -58,7 +62,8 @@ target_include_directories(app PRIVATE
${APP_ROOT}/shell_common/include
${GEN_DIR}
${CHEF}
${GEN_DIR}/app-common
${GEN_DIR}/../
${CHIP_ROOT}/src
${NRFCONNECT_COMMON}/util/include
${NRFCONNECT_COMMON}/app/include
)
Expand Down
Loading

0 comments on commit 0beddff

Please sign in to comment.