Skip to content

Commit

Permalink
[Mbed] Add pigweed-app example (#10458)
Browse files Browse the repository at this point in the history
* Add Mbed pigweed-app example

* Remove custom echo_service and use the pigweed version
Example cleanup

* Fix mbed config CMakeLists

* Update Mbed logging
mbed_app.json cleanup

* Changes for Mbed OS update

* Improve examples startup logging

* Fix MBED_PATH value
Changes restyle

* Pigweed-app example cleanup

* Fix path to pigweed-app executable

* Remove copying  pigweed-app executable to build artifacts
  • Loading branch information
ATmobica authored and pull[bot] committed Nov 12, 2021
1 parent 3c1b160 commit 1092792
Show file tree
Hide file tree
Showing 22 changed files with 751 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/examples-mbed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ jobs:
examples/lighting-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-lighting-app-example.elf \
/tmp/bloat_reports/
- name: Build pigweed-app example
timeout-minutes: 10
run: |
scripts/examples/mbed_example.sh -a=pigweed-app -b=$APP_TARGET -p=$APP_PROFILE
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
mbed $APP_TARGET+$APP_PROFILE pigweed-app \
examples/pigweed-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-pigweed-app-example.elf \
/tmp/bloat_reports/
- name: Build unit tests
timeout-minutes: 10
run: scripts/tests/mbed/mbed_unit_tests.sh -b=$APP_TARGET -p=$APP_PROFILE
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"type": "pickString",
"id": "mbedApp",
"description": "What mbed application do you want to use?",
"options": ["lock-app", "lighting-app"],
"options": ["lock-app", "lighting-app", "pigweed-app"],
"default": "lock-app"
},
{
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"type": "pickString",
"id": "mbedApp",
"description": "What mbed application do you want to use?",
"options": ["lock-app", "lighting-app"],
"options": ["lock-app", "lighting-app", "pigweed-app"],
"default": "lock-app"
},
{
Expand Down
106 changes: 105 additions & 1 deletion config/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ set(CHIP_CFLAG_EXCLUDES
# Helper macros
# ==============================================================================

macro(chip_gn_arg_import FILE)
string(APPEND CHIP_GN_ARGS "import(\"${FILE}\")\n")
endmacro()

macro(chip_gn_arg_string ARG STRING)
string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n")
endmacro()
Expand Down Expand Up @@ -95,6 +99,19 @@ macro(mbed_interface_library_named name)
add_library(${name} INTERFACE)
endmacro()

# Select gnu++<YY> standard based on project configuration
macro(mbed_get_gnu_cpp_standard VAR)
if (CONFIG_STD_CPP11)
list(APPEND ${VAR} -std=gnu++11)
elseif (CONFIG_STD_CPP14)
list(APPEND ${VAR} -std=gnu++14)
elseif (CONFIG_STD_CPP17)
list(APPEND ${VAR} -std=gnu++17)
elseif (CONFIG_STD_CPP2A)
list(APPEND ${VAR} -std=gnu++20)
endif()
endmacro()

# ==============================================================================
# Prepare CHIP configuration based on the project configuration
# ==============================================================================
Expand All @@ -111,10 +128,16 @@ foreach(NameAndValue ${ConfigContents})
set(${Name} "${Value}")
endforeach()

if (CONFIG_CHIP_PW_RPC)
set(CONFIG_STD_CPP17 y)
endif()

if (NOT CHIP_ROOT)
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH)
endif()

set(GN_ROOT_TARGET ${CHIP_ROOT}/config/mbed/chip-gn)

# Prepare compiler flags

mbed_get_target_common_compile_flags(CHIP_CFLAGS mbed-core)
Expand Down Expand Up @@ -165,6 +188,8 @@ if (CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS)
list(APPEND CHIP_CFLAGS ${CHIP_MBEDTLS_CFLAGS})
endif()

mbed_get_gnu_cpp_standard(CHIP_CFLAGS_CC)

list(APPEND CHIP_CFLAGS
\"-D__LINUX_ERRNO_EXTENSIONS__=1\"
)
Expand Down Expand Up @@ -196,6 +221,15 @@ if (CONFIG_CHIP_LIB_SHELL)
list(APPEND CHIP_LIBRARIES -lCHIPShell)
endif()

if (CONFIG_CHIP_PW_RPC)
list(APPEND CHIP_LIBRARIES -lPwRpc)
if (${APP_TARGET} MATCHES "pigweed-app")
set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "y")
else()
set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "n")
endif()
endif(CONFIG_CHIP_PW_RPC)

# Set up CHIP project configuration file

set(CHIP_DEFAULT_CONFIG_FILE "<${CHIP_ROOT}/config/mbed/CHIPProjectConfig.h>")
Expand All @@ -217,6 +251,9 @@ endif()
# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================
if (CONFIG_CHIP_PW_RPC)
chip_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni")
endif()

chip_gn_arg_flags("target_cflags" ${CHIP_CFLAGS})
chip_gn_arg_lang_flags("target_cflags_c" ${CHIP_CFLAGS_C})
Expand All @@ -231,6 +268,10 @@ chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TEST
chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
chip_gn_arg_bool ("chip_with_platform_mbedtls" CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS)
chip_gn_arg_bool ("chip_bypass_rendezvous" CONFIG_CHIP_BYPASS_RENDEZVOUS)
chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC)
if (CONFIG_CHIP_PW_RPC)
chip_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO)
endif(CONFIG_CHIP_PW_RPC)

file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS})

Expand All @@ -242,7 +283,7 @@ ExternalProject_Add(
PREFIX ${CMAKE_CURRENT_BINARY_DIR}
SOURCE_DIR ${CHIP_ROOT}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/mbed/chip-gn gen --export-compile-commands --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
CONFIGURE_COMMAND gn --root=${GN_ROOT_TARGET} gen --export-compile-commands --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
BUILD_COMMAND ninja
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${CHIP_LIBRARIES}
Expand Down Expand Up @@ -291,10 +332,73 @@ if (CONFIG_MBED_BSD_SOCKET_TRACE)
)
endif()

if (CONFIG_CHIP_PW_RPC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" PARENT_SCOPE)
list(APPEND CHIP_DEFINES
CONFIG_CHIP_PW_RPC=1
)
endif()

target_include_directories(${APP_TARGET} PRIVATE
${CHIP_INCLUDES}
)

target_compile_definitions(${APP_TARGET} PRIVATE
${CHIP_DEFINES}
)


if (CONFIG_CHIP_PW_RPC)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")

target_sources(${APP_TARGET} PRIVATE
${CHIP_ROOT}/examples/common/pigweed/RpcService.cpp
${CHIP_ROOT}/examples/common/pigweed/mbed/PigweedLoggerMutex.cpp
${MBED_COMMON}/util/PigweedLogger.cpp
)

target_include_directories(${APP_TARGET} PRIVATE
${PIGWEED_ROOT}/pw_sys_io/public
${PIGWEED_ROOT}/pw_assert/public
${PIGWEED_ROOT}/pw_assert_log/public
${PIGWEED_ROOT}/pw_assert_log/public_overrides
${PIGWEED_ROOT}/pw_bytes/public
${PIGWEED_ROOT}/pw_checksum/public
${PIGWEED_ROOT}/pw_containers/public
${PIGWEED_ROOT}/pw_hdlc/public
${PIGWEED_ROOT}/pw_log/public
${PIGWEED_ROOT}/pw_log_basic/public
${PIGWEED_ROOT}/pw_log_basic/public_overrides
${PIGWEED_ROOT}/pw_span/public_overrides
${PIGWEED_ROOT}/pw_span/public
${PIGWEED_ROOT}/pw_polyfill/public
${PIGWEED_ROOT}/pw_polyfill/standard_library_public
${PIGWEED_ROOT}/pw_polyfill/public_overrides
${PIGWEED_ROOT}/pw_rpc/public
${PIGWEED_ROOT}/pw_rpc/nanopb/public
${PIGWEED_ROOT}/pw_rpc/raw/public
${PIGWEED_ROOT}/pw_protobuf/public
${PIGWEED_ROOT}/pw_status/public
${PIGWEED_ROOT}/pw_stream/public
${PIGWEED_ROOT}/pw_result/public
${PIGWEED_ROOT}/pw_varint/public
${PIGWEED_ROOT}/pw_function/public
${PIGWEED_ROOT}/pw_preprocessor/public
${PIGWEED_ROOT}/pw_rpc/system_server/public
${CHIP_ROOT}/third_party/nanopb/repo

${CHIP_ROOT}/examples/common
${CHIP_ROOT}/examples//common/pigweed/mbed
${MBED_COMMON}/pw_sys_io/public
)

if (CONFIG_CHIP_PW_RPC_ECHO_PROTO)
target_include_directories(${APP_TARGET} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb_rpc
${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb
${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb
)
endif(CONFIG_CHIP_PW_RPC_ECHO_PROTO)

endif(CONFIG_CHIP_PW_RPC)
5 changes: 5 additions & 0 deletions config/mbed/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import("//${chip_root}/build/chip/tests.gni")
assert(current_os == "mbed")

declare_args() {
chip_build_pw_rpc_lib = false
chip_custom_build_cflags = []
}

Expand All @@ -32,6 +33,10 @@ group("mbed") {
if (chip_build_tests) {
deps += [ "${chip_root}/src:tests" ]
}

if (chip_build_pw_rpc_lib) {
deps += [ "//lib/pw_rpc" ]
}
}

group("default") {
Expand Down
45 changes: 45 additions & 0 deletions config/mbed/chip-gn/lib/pw_rpc/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2020 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("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")

declare_args() {
chip_build_pw_rpc_echo_proto = false
}

static_library("pw_rpc") {
output_name = "libPwRpc"

public_configs = [ "${dir_pigweed}/pw_hdlc:default_config" ]
deps = [
"$dir_pw_rpc:server",
"${chip_root}/examples/platform/mbed/pw_sys_io:pw_sys_io_mbed",
"${dir_pigweed}/pw_hdlc:pw_rpc",
dir_pw_assert,
dir_pw_hdlc,
dir_pw_log,
]

if (chip_build_pw_rpc_echo_proto) {
deps += [ "$dir_pw_rpc/nanopb:echo_service" ]
}

deps += pw_build_LINK_DEPS

output_dir = "${root_out_dir}/lib"

complete_static_lib = true
}
32 changes: 32 additions & 0 deletions config/mbed/chip-gn/lib/pw_rpc/pw_rpc.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2021 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("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")

pw_log_BACKEND = "$dir_pw_log_basic"
pw_assert_BACKEND = "$dir_pw_assert_log"
pw_sys_io_BACKEND =
"${chip_root}/examples/platform/mbed/pw_sys_io:pw_sys_io_mbed"
pw_rpc_system_server_BACKEND =
"${chip_root}/examples/common/pigweed:system_rpc_server"

pw_build_LINK_DEPS = [
"$dir_pw_assert:impl",
"$dir_pw_log:impl",
]

dir_pw_third_party_nanopb = "${chip_root}/third_party/nanopb/repo"

chip_enable_pw_rpc = true
2 changes: 1 addition & 1 deletion config/mbed/mbed-util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ function(convert_list_of_flags_to_string_of_flags ptr_list_of_flags string_of_fl

# Set the output variable in the parent scope
set(${string_of_flags} ${locally_scoped_string_of_flags} PARENT_SCOPE)
endfunction()
endfunction()
27 changes: 27 additions & 0 deletions examples/common/pigweed/mbed/PigweedLoggerMutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* 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.
*/

#include "PigweedLoggerMutex.h"

namespace chip {
namespace rpc {

PigweedLoggerMutex logger_mutex;

} // namespace rpc
} // namespace chip
51 changes: 51 additions & 0 deletions examples/common/pigweed/mbed/PigweedLoggerMutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
*
* Copyright (c) 2021 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.
*/

#pragma once

#include "PigweedLogger.h"
#include "pigweed/RpcService.h"
#include "rtos/Mutex.h"

namespace chip {
namespace rpc {
class PigweedLoggerMutex : public chip::rpc::Mutex
{

public:
void Lock() override
{
rtos::Mutex * mutex = PigweedLogger::GetSemaphore();
if (mutex)
{
mutex->lock();
}
}
void Unlock() override
{
rtos::Mutex * mutex = PigweedLogger::GetSemaphore();
if (mutex)
{
mutex->unlock();
}
}
};

extern PigweedLoggerMutex logger_mutex;

} // namespace rpc
} // namespace chip
2 changes: 2 additions & 0 deletions examples/pigweed-app/mbed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config/
build-*/
Loading

0 comments on commit 1092792

Please sign in to comment.