From b501fd5319635715aa7f8b43b76a55d3aed6f88e Mon Sep 17 00:00:00 2001 From: Rob Oliver Date: Mon, 22 Aug 2022 10:05:40 -0400 Subject: [PATCH] RPC: Add RPC target for esp32 lighting app Add an RPC target for the DevC Esp32 Lighting app. --- examples/lighting-app/esp32/CMakeLists.txt | 22 +++ .../lighting-app/esp32/main/CMakeLists.txt | 158 +++++++++++++++++- .../lighting-app/esp32/main/Kconfig.projbuild | 38 +++++ examples/lighting-app/esp32/main/main.cpp | 7 + .../lighting-app/esp32/sdkconfig_rpc.defaults | 52 ++++++ scripts/build/build/targets.py | 1 + scripts/build/builders/esp32.py | 1 + .../testdata/all_targets_except_host.txt | 1 + .../build/testdata/build_all_except_host.txt | 18 ++ .../glob_star_targets_except_host.txt | 1 + 10 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 examples/lighting-app/esp32/sdkconfig_rpc.defaults diff --git a/examples/lighting-app/esp32/CMakeLists.txt b/examples/lighting-app/esp32/CMakeLists.txt index 8abe862af3120d..06359e838141bc 100644 --- a/examples/lighting-app/esp32/CMakeLists.txt +++ b/examples/lighting-app/esp32/CMakeLists.txt @@ -45,3 +45,25 @@ idf_build_set_property(COMPILE_OPTIONS "-Wno-error=maybe-uninitialized" APPEND) idf_build_set_property(COMPILE_OPTIONS "-Wno-error=uninitialized" APPEND) flashing_script() + +if (CONFIG_ENABLE_PW_RPC) +get_filename_component(CHIP_ROOT ./third_party/connectedhomeip REALPATH) +include(third_party/connectedhomeip/third_party/pigweed/repo/pw_build/pigweed.cmake) + +pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config) + +pw_set_backend(pw_log pw_log_basic) +pw_set_backend(pw_assert.check pw_assert_log.check_backend) +pw_set_backend(pw_assert.assert pw_assert.assert_compatibility_backend) +pw_set_backend(pw_sys_io pw_sys_io.esp32) +pw_set_backend(pw_trace pw_trace_tokenized) + +add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo) +add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo) +add_subdirectory(third_party/connectedhomeip/examples/platform/esp32/pw_sys_io) + +get_target_property(_target_cxx_flags pw_build.cpp17 INTERFACE_COMPILE_OPTIONS) +list(REMOVE_ITEM _target_cxx_flags $<$:-std=c++17>) +list(APPEND _target_cxx_flags $<$:-std=gnu++17>) +set_target_properties(pw_build.cpp17 PROPERTIES INTERFACE_COMPILE_OPTIONS "${_target_cxx_flags}") +endif(CONFIG_ENABLE_PW_RPC) diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt index 097f5ba8c41357..e82f0c3f33e77c 100644 --- a/examples/lighting-app/esp32/main/CMakeLists.txt +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -16,13 +16,14 @@ # # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) -idf_component_register(PRIV_INCLUDE_DIRS +set(PRIV_INCLUDE_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/include" "${CMAKE_CURRENT_LIST_DIR}/include" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" - SRC_DIRS +) +set(SRC_DIRS_LIST "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" @@ -65,10 +66,161 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server" - PRIV_REQUIRES chip QRCode bt led_strip app_update openthread) +) + +set(PRIV_REQUIRES_LIST chip QRCode bt led_strip app_update openthread) + +if (CONFIG_ENABLE_PW_RPC) +# Append additional directories for RPC build +set(PRIV_INCLUDE_DIRS_LIST "${PRIV_INCLUDE_DIRS_LIST}" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/pw_sys_io/public" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/lib/support" + "${IDF_PATH}/components/freertos/include/freertos" +) +set(SRC_DIRS_LIST "${SRC_DIRS_LIST}" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32" +) +endif (CONFIG_ENABLE_PW_RPC) + +idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST} + SRC_DIRS ${SRC_DIRS_LIST} + PRIV_REQUIRES ${PRIV_REQUIRES_LIST}) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") target_compile_options(${COMPONENT_LIB} PUBLIC "-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=" ) + +if (CONFIG_ENABLE_PW_RPC) + +get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH) + +set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") +include(${PIGWEED_ROOT}/pw_build/pigweed.cmake) +include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake) +set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE) + +pw_proto_library(attributes_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.options + PREFIX + attributes_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(button_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/button_service.proto + PREFIX + button_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(descriptor_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto + PREFIX + descriptor_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(device_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/device_service.options + PREFIX + device_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(lighting_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/lighting_service.proto + PREFIX + lighting_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(locking_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/locking_service.proto + PREFIX + locking_service + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos + DEPS + pw_protobuf.common_proto +) + +pw_proto_library(wifi_service + SOURCES + ${CHIP_ROOT}/examples/common/pigweed/protos/wifi_service.proto + INPUTS + ${CHIP_ROOT}/examples/common/pigweed/protos/wifi_service.options + PREFIX + wifi_service + DEPS + pw_protobuf.common_proto + STRIP_PREFIX + ${CHIP_ROOT}/examples/common/pigweed/protos +) + +target_link_libraries(${COMPONENT_LIB} PUBLIC + attributes_service.nanopb_rpc + button_service.nanopb_rpc + descriptor_service.nanopb_rpc + device_service.nanopb_rpc + lighting_service.nanopb_rpc + locking_service.nanopb_rpc + wifi_service.nanopb_rpc + pw_checksum + pw_hdlc + pw_log + pw_rpc.server + pw_trace_tokenized + pw_trace_tokenized.trace_buffer + pw_trace_tokenized.rpc_service + pw_trace_tokenized.protos.nanopb_rpc +) + +target_link_options(${COMPONENT_LIB} + PUBLIC + "-T${PIGWEED_ROOT}/pw_tokenizer/pw_tokenizer_linker_sections.ld" +) + +target_compile_options(${COMPONENT_LIB} PRIVATE + "-DPW_RPC_ATTRIBUTE_SERVICE=1" + "-DPW_RPC_BUTTON_SERVICE=1" + "-DPW_RPC_DESCRIPTOR_SERVICE=1" + "-DPW_RPC_DEVICE_SERVICE=1" + "-DPW_RPC_LIGHTING_SERVICE=1" + "-DPW_RPC_LOCKING_SERVICE=1" + "-DPW_RPC_TRACING_SERVICE=1" + "-DPW_RPC_WIFI_SERVICE=1" + "-DPW_TRACE_BACKEND_SET=1") + +endif (CONFIG_ENABLE_PW_RPC) diff --git a/examples/lighting-app/esp32/main/Kconfig.projbuild b/examples/lighting-app/esp32/main/Kconfig.projbuild index a13c76c28249b0..43d7d9f0e75381 100644 --- a/examples/lighting-app/esp32/main/Kconfig.projbuild +++ b/examples/lighting-app/esp32/main/Kconfig.projbuild @@ -107,3 +107,41 @@ menu "Demo" default 8 if RENDEZVOUS_MODE_ETHERNET endmenu + +menu "PW RPC Debug channel" +depends on ENABLE_PW_RPC + config EXAMPLE_UART_PORT_NUM + int "UART port number" + range 0 2 if IDF_TARGET_ESP32 + range 0 1 if IDF_TARGET_ESP32C3 + default 0 + help + UART communication port number for the example. + See UART documentation for available port numbers. + + config EXAMPLE_UART_BAUD_RATE + int "UART communication speed" + range 1200 115200 + default 115200 + help + UART communication speed for Modbus example. + + config EXAMPLE_UART_RXD + int "UART RXD pin number" + range 0 34 if IDF_TARGET_ESP32 + range 0 19 if IDF_TARGET_ESP32C3 + default 5 + help + GPIO number for UART RX pin. See UART documentation for more information + about available pin numbers for UART. + + config EXAMPLE_UART_TXD + int "UART TXD pin number" + range 0 34 if IDF_TARGET_ESP32 + range 0 19 if IDF_TARGET_ESP32C3 + default 4 + help + GPIO number for UART TX pin. See UART documentation for more information + about available pin numbers for UART. + +endmenu diff --git a/examples/lighting-app/esp32/main/main.cpp b/examples/lighting-app/esp32/main/main.cpp index a551a6e76199b9..02381fd651fe0d 100644 --- a/examples/lighting-app/esp32/main/main.cpp +++ b/examples/lighting-app/esp32/main/main.cpp @@ -37,6 +37,10 @@ #include #endif // CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER +#if CONFIG_ENABLE_PW_RPC +#include "Rpc.h" +#endif + #if CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER #include #else @@ -81,6 +85,9 @@ extern "C" void app_main() ESP_LOGE(TAG, "nvs_flash_init() failed: %s", esp_err_to_name(err)); return; } +#if CONFIG_ENABLE_PW_RPC + chip::rpc::Init(); +#endif ESP_LOGI(TAG, "=================================================="); ESP_LOGI(TAG, "chip-esp32-light-example starting"); diff --git a/examples/lighting-app/esp32/sdkconfig_rpc.defaults b/examples/lighting-app/esp32/sdkconfig_rpc.defaults new file mode 100644 index 00000000000000..968efdb31ff16f --- /dev/null +++ b/examples/lighting-app/esp32/sdkconfig_rpc.defaults @@ -0,0 +1,52 @@ +# +# Copyright (c) 2020 Project CHIP Authors +# Copyright (c) 2018 Nest Labs, Inc. +# 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. +# +# Description: +# CI uses this to select the ESP32C3-DevKitM. +# +# Default to 921600 baud when flashing and monitoring device +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_COMPRESSED=y +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#enable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" + +#enable lwIP route hooks +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# Serial Flasher config +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" + +# PW RPC Debug channel +CONFIG_EXAMPLE_UART_PORT_NUM=0 +CONFIG_EXAMPLE_UART_BAUD_RATE=115200 +CONFIG_EXAMPLE_UART_RXD=3 +CONFIG_EXAMPLE_UART_TXD=1 +CONFIG_ENABLE_PW_RPC=y diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index cb457e61a4b6a6..f68860306d8231 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -376,6 +376,7 @@ def Esp32Targets(): yield devkitc.Extend('all-clusters-minimal-ipv6only', app=Esp32App.ALL_CLUSTERS_MINIMAL, enable_ipv4=False) yield devkitc.Extend('shell', app=Esp32App.SHELL) yield devkitc.Extend('light', app=Esp32App.LIGHT) + yield devkitc.Extend('light-rpc', app=Esp32App.LIGHT, enable_rpcs=True) yield devkitc.Extend('lock', app=Esp32App.LOCK) yield devkitc.Extend('bridge', app=Esp32App.BRIDGE) yield devkitc.Extend('temperature-measurement', app=Esp32App.TEMPERATURE_MEASUREMENT) diff --git a/scripts/build/builders/esp32.py b/scripts/build/builders/esp32.py index 53929a7015898d..d84e8f56e8edbc 100644 --- a/scripts/build/builders/esp32.py +++ b/scripts/build/builders/esp32.py @@ -105,6 +105,7 @@ def IsCompatible(self, board: Esp32Board): def DefaultsFileName(board: Esp32Board, app: Esp32App, enable_rpcs: bool): rpc_enabled_apps = [Esp32App.ALL_CLUSTERS, Esp32App.ALL_CLUSTERS_MINIMAL, + Esp32App.LIGHT, Esp32App.OTA_REQUESTOR, Esp32App.TEMPERATURE_MEASUREMENT] if app == Esp32App.TESTS: diff --git a/scripts/build/testdata/all_targets_except_host.txt b/scripts/build/testdata/all_targets_except_host.txt index fe98801f8ee5ac..b1462119bf72d0 100644 --- a/scripts/build/testdata/all_targets_except_host.txt +++ b/scripts/build/testdata/all_targets_except_host.txt @@ -149,6 +149,7 @@ esp32-devkitc-all-clusters-minimal esp32-devkitc-all-clusters-minimal-ipv6only esp32-devkitc-bridge esp32-devkitc-light +esp32-devkitc-light-rpc esp32-devkitc-lock esp32-devkitc-ota-requestor esp32-devkitc-ota-requestor-rpc diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt index 6cb3d25fcf67a2..5a7453c3fc976b 100644 --- a/scripts/build/testdata/build_all_except_host.txt +++ b/scripts/build/testdata/build_all_except_host.txt @@ -612,6 +612,17 @@ bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-light/sdkconfig.defaults idf.py -C examples/lighting-app/esp32 -B {out}/esp32-devkitc-light reconfigure' +# Generating esp32-devkitc-light-rpc +mkdir -p {out}/esp32-devkitc-light-rpc + +cp examples/lighting-app/esp32/sdkconfig_rpc.defaults {out}/esp32-devkitc-light-rpc/sdkconfig.defaults + +rm -f examples/lighting-app/esp32/sdkconfig + +bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; +export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-light-rpc/sdkconfig.defaults +idf.py -C examples/lighting-app/esp32 -B {out}/esp32-devkitc-light-rpc reconfigure' + # Generating esp32-devkitc-lock mkdir -p {out}/esp32-devkitc-lock @@ -1948,6 +1959,13 @@ bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-light/sdkconfig.defaults idf.py -C examples/lighting-app/esp32 -B {out}/esp32-devkitc-light build' +rm -f examples/lighting-app/esp32/sdkconfig + +# Building esp32-devkitc-light-rpc +bash -c 'source $IDF_PATH/export.sh; source scripts/activate.sh; +export SDKCONFIG_DEFAULTS={out}/esp32-devkitc-light-rpc/sdkconfig.defaults +idf.py -C examples/lighting-app/esp32 -B {out}/esp32-devkitc-light-rpc build' + rm -f examples/lock-app/esp32/sdkconfig # Building esp32-devkitc-lock diff --git a/scripts/build/testdata/glob_star_targets_except_host.txt b/scripts/build/testdata/glob_star_targets_except_host.txt index d7090c2c52ccfd..21916fd50391c1 100644 --- a/scripts/build/testdata/glob_star_targets_except_host.txt +++ b/scripts/build/testdata/glob_star_targets_except_host.txt @@ -43,6 +43,7 @@ esp32-devkitc-all-clusters-minimal esp32-devkitc-all-clusters-minimal-ipv6only esp32-devkitc-bridge esp32-devkitc-light +esp32-devkitc-light-rpc esp32-devkitc-lock esp32-devkitc-ota-requestor esp32-devkitc-ota-requestor-rpc