Skip to content

Commit 1092792

Browse files
ATmobicapull[bot]
authored andcommitted
[Mbed] Add pigweed-app example (#10458)
* 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
1 parent 3c1b160 commit 1092792

File tree

22 files changed

+751
-5
lines changed

22 files changed

+751
-5
lines changed

.github/workflows/examples-mbed.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ jobs:
8282
examples/lighting-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-lighting-app-example.elf \
8383
/tmp/bloat_reports/
8484
85+
- name: Build pigweed-app example
86+
timeout-minutes: 10
87+
run: |
88+
scripts/examples/mbed_example.sh -a=pigweed-app -b=$APP_TARGET -p=$APP_PROFILE
89+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
90+
mbed $APP_TARGET+$APP_PROFILE pigweed-app \
91+
examples/pigweed-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-pigweed-app-example.elf \
92+
/tmp/bloat_reports/
93+
8594
- name: Build unit tests
8695
timeout-minutes: 10
8796
run: scripts/tests/mbed/mbed_unit_tests.sh -b=$APP_TARGET -p=$APP_PROFILE

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
"type": "pickString",
311311
"id": "mbedApp",
312312
"description": "What mbed application do you want to use?",
313-
"options": ["lock-app", "lighting-app"],
313+
"options": ["lock-app", "lighting-app", "pigweed-app"],
314314
"default": "lock-app"
315315
},
316316
{

.vscode/tasks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
"type": "pickString",
185185
"id": "mbedApp",
186186
"description": "What mbed application do you want to use?",
187-
"options": ["lock-app", "lighting-app"],
187+
"options": ["lock-app", "lighting-app", "pigweed-app"],
188188
"default": "lock-app"
189189
},
190190
{

config/mbed/CMakeLists.txt

+105-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ set(CHIP_CFLAG_EXCLUDES
6363
# Helper macros
6464
# ==============================================================================
6565

66+
macro(chip_gn_arg_import FILE)
67+
string(APPEND CHIP_GN_ARGS "import(\"${FILE}\")\n")
68+
endmacro()
69+
6670
macro(chip_gn_arg_string ARG STRING)
6771
string(APPEND CHIP_GN_ARGS "${ARG} = \"${STRING}\"\n")
6872
endmacro()
@@ -95,6 +99,19 @@ macro(mbed_interface_library_named name)
9599
add_library(${name} INTERFACE)
96100
endmacro()
97101

102+
# Select gnu++<YY> standard based on project configuration
103+
macro(mbed_get_gnu_cpp_standard VAR)
104+
if (CONFIG_STD_CPP11)
105+
list(APPEND ${VAR} -std=gnu++11)
106+
elseif (CONFIG_STD_CPP14)
107+
list(APPEND ${VAR} -std=gnu++14)
108+
elseif (CONFIG_STD_CPP17)
109+
list(APPEND ${VAR} -std=gnu++17)
110+
elseif (CONFIG_STD_CPP2A)
111+
list(APPEND ${VAR} -std=gnu++20)
112+
endif()
113+
endmacro()
114+
98115
# ==============================================================================
99116
# Prepare CHIP configuration based on the project configuration
100117
# ==============================================================================
@@ -111,10 +128,16 @@ foreach(NameAndValue ${ConfigContents})
111128
set(${Name} "${Value}")
112129
endforeach()
113130

131+
if (CONFIG_CHIP_PW_RPC)
132+
set(CONFIG_STD_CPP17 y)
133+
endif()
134+
114135
if (NOT CHIP_ROOT)
115136
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH)
116137
endif()
117138

139+
set(GN_ROOT_TARGET ${CHIP_ROOT}/config/mbed/chip-gn)
140+
118141
# Prepare compiler flags
119142

120143
mbed_get_target_common_compile_flags(CHIP_CFLAGS mbed-core)
@@ -165,6 +188,8 @@ if (CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS)
165188
list(APPEND CHIP_CFLAGS ${CHIP_MBEDTLS_CFLAGS})
166189
endif()
167190

191+
mbed_get_gnu_cpp_standard(CHIP_CFLAGS_CC)
192+
168193
list(APPEND CHIP_CFLAGS
169194
\"-D__LINUX_ERRNO_EXTENSIONS__=1\"
170195
)
@@ -196,6 +221,15 @@ if (CONFIG_CHIP_LIB_SHELL)
196221
list(APPEND CHIP_LIBRARIES -lCHIPShell)
197222
endif()
198223

224+
if (CONFIG_CHIP_PW_RPC)
225+
list(APPEND CHIP_LIBRARIES -lPwRpc)
226+
if (${APP_TARGET} MATCHES "pigweed-app")
227+
set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "y")
228+
else()
229+
set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "n")
230+
endif()
231+
endif(CONFIG_CHIP_PW_RPC)
232+
199233
# Set up CHIP project configuration file
200234

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

221258
chip_gn_arg_flags("target_cflags" ${CHIP_CFLAGS})
222259
chip_gn_arg_lang_flags("target_cflags_c" ${CHIP_CFLAGS_C})
@@ -231,6 +268,10 @@ chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TEST
231268
chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
232269
chip_gn_arg_bool ("chip_with_platform_mbedtls" CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS)
233270
chip_gn_arg_bool ("chip_bypass_rendezvous" CONFIG_CHIP_BYPASS_RENDEZVOUS)
271+
chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC)
272+
if (CONFIG_CHIP_PW_RPC)
273+
chip_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO)
274+
endif(CONFIG_CHIP_PW_RPC)
234275

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

@@ -242,7 +283,7 @@ ExternalProject_Add(
242283
PREFIX ${CMAKE_CURRENT_BINARY_DIR}
243284
SOURCE_DIR ${CHIP_ROOT}
244285
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
245-
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/mbed/chip-gn gen --export-compile-commands --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
286+
CONFIGURE_COMMAND gn --root=${GN_ROOT_TARGET} gen --export-compile-commands --check --fail-on-unused-args ${CMAKE_CURRENT_BINARY_DIR}
246287
BUILD_COMMAND ninja
247288
INSTALL_COMMAND ""
248289
BUILD_BYPRODUCTS ${CHIP_LIBRARIES}
@@ -291,10 +332,73 @@ if (CONFIG_MBED_BSD_SOCKET_TRACE)
291332
)
292333
endif()
293334

335+
if (CONFIG_CHIP_PW_RPC)
336+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" PARENT_SCOPE)
337+
list(APPEND CHIP_DEFINES
338+
CONFIG_CHIP_PW_RPC=1
339+
)
340+
endif()
341+
294342
target_include_directories(${APP_TARGET} PRIVATE
295343
${CHIP_INCLUDES}
296344
)
297345

298346
target_compile_definitions(${APP_TARGET} PRIVATE
299347
${CHIP_DEFINES}
300348
)
349+
350+
351+
if (CONFIG_CHIP_PW_RPC)
352+
353+
set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
354+
355+
target_sources(${APP_TARGET} PRIVATE
356+
${CHIP_ROOT}/examples/common/pigweed/RpcService.cpp
357+
${CHIP_ROOT}/examples/common/pigweed/mbed/PigweedLoggerMutex.cpp
358+
${MBED_COMMON}/util/PigweedLogger.cpp
359+
)
360+
361+
target_include_directories(${APP_TARGET} PRIVATE
362+
${PIGWEED_ROOT}/pw_sys_io/public
363+
${PIGWEED_ROOT}/pw_assert/public
364+
${PIGWEED_ROOT}/pw_assert_log/public
365+
${PIGWEED_ROOT}/pw_assert_log/public_overrides
366+
${PIGWEED_ROOT}/pw_bytes/public
367+
${PIGWEED_ROOT}/pw_checksum/public
368+
${PIGWEED_ROOT}/pw_containers/public
369+
${PIGWEED_ROOT}/pw_hdlc/public
370+
${PIGWEED_ROOT}/pw_log/public
371+
${PIGWEED_ROOT}/pw_log_basic/public
372+
${PIGWEED_ROOT}/pw_log_basic/public_overrides
373+
${PIGWEED_ROOT}/pw_span/public_overrides
374+
${PIGWEED_ROOT}/pw_span/public
375+
${PIGWEED_ROOT}/pw_polyfill/public
376+
${PIGWEED_ROOT}/pw_polyfill/standard_library_public
377+
${PIGWEED_ROOT}/pw_polyfill/public_overrides
378+
${PIGWEED_ROOT}/pw_rpc/public
379+
${PIGWEED_ROOT}/pw_rpc/nanopb/public
380+
${PIGWEED_ROOT}/pw_rpc/raw/public
381+
${PIGWEED_ROOT}/pw_protobuf/public
382+
${PIGWEED_ROOT}/pw_status/public
383+
${PIGWEED_ROOT}/pw_stream/public
384+
${PIGWEED_ROOT}/pw_result/public
385+
${PIGWEED_ROOT}/pw_varint/public
386+
${PIGWEED_ROOT}/pw_function/public
387+
${PIGWEED_ROOT}/pw_preprocessor/public
388+
${PIGWEED_ROOT}/pw_rpc/system_server/public
389+
${CHIP_ROOT}/third_party/nanopb/repo
390+
391+
${CHIP_ROOT}/examples/common
392+
${CHIP_ROOT}/examples//common/pigweed/mbed
393+
${MBED_COMMON}/pw_sys_io/public
394+
)
395+
396+
if (CONFIG_CHIP_PW_RPC_ECHO_PROTO)
397+
target_include_directories(${APP_TARGET} PRIVATE
398+
${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb_rpc
399+
${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb
400+
${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb
401+
)
402+
endif(CONFIG_CHIP_PW_RPC_ECHO_PROTO)
403+
404+
endif(CONFIG_CHIP_PW_RPC)

config/mbed/chip-gn/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import("//${chip_root}/build/chip/tests.gni")
1919
assert(current_os == "mbed")
2020

2121
declare_args() {
22+
chip_build_pw_rpc_lib = false
2223
chip_custom_build_cflags = []
2324
}
2425

@@ -32,6 +33,10 @@ group("mbed") {
3233
if (chip_build_tests) {
3334
deps += [ "${chip_root}/src:tests" ]
3435
}
36+
37+
if (chip_build_pw_rpc_lib) {
38+
deps += [ "//lib/pw_rpc" ]
39+
}
3540
}
3641

3742
group("default") {
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("//build_overrides/pigweed.gni")
17+
import("$dir_pw_build/target_types.gni")
18+
19+
declare_args() {
20+
chip_build_pw_rpc_echo_proto = false
21+
}
22+
23+
static_library("pw_rpc") {
24+
output_name = "libPwRpc"
25+
26+
public_configs = [ "${dir_pigweed}/pw_hdlc:default_config" ]
27+
deps = [
28+
"$dir_pw_rpc:server",
29+
"${chip_root}/examples/platform/mbed/pw_sys_io:pw_sys_io_mbed",
30+
"${dir_pigweed}/pw_hdlc:pw_rpc",
31+
dir_pw_assert,
32+
dir_pw_hdlc,
33+
dir_pw_log,
34+
]
35+
36+
if (chip_build_pw_rpc_echo_proto) {
37+
deps += [ "$dir_pw_rpc/nanopb:echo_service" ]
38+
}
39+
40+
deps += pw_build_LINK_DEPS
41+
42+
output_dir = "${root_out_dir}/lib"
43+
44+
complete_static_lib = true
45+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2021 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
import("//build_overrides/pigweed.gni")
17+
18+
pw_log_BACKEND = "$dir_pw_log_basic"
19+
pw_assert_BACKEND = "$dir_pw_assert_log"
20+
pw_sys_io_BACKEND =
21+
"${chip_root}/examples/platform/mbed/pw_sys_io:pw_sys_io_mbed"
22+
pw_rpc_system_server_BACKEND =
23+
"${chip_root}/examples/common/pigweed:system_rpc_server"
24+
25+
pw_build_LINK_DEPS = [
26+
"$dir_pw_assert:impl",
27+
"$dir_pw_log:impl",
28+
]
29+
30+
dir_pw_third_party_nanopb = "${chip_root}/third_party/nanopb/repo"
31+
32+
chip_enable_pw_rpc = true

config/mbed/mbed-util.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ function(convert_list_of_flags_to_string_of_flags ptr_list_of_flags string_of_fl
136136

137137
# Set the output variable in the parent scope
138138
set(${string_of_flags} ${locally_scoped_string_of_flags} PARENT_SCOPE)
139-
endfunction()
139+
endfunction()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
* Copyright (c) 2021 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "PigweedLoggerMutex.h"
20+
21+
namespace chip {
22+
namespace rpc {
23+
24+
PigweedLoggerMutex logger_mutex;
25+
26+
} // namespace rpc
27+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* Copyright (c) 2021 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include "PigweedLogger.h"
21+
#include "pigweed/RpcService.h"
22+
#include "rtos/Mutex.h"
23+
24+
namespace chip {
25+
namespace rpc {
26+
class PigweedLoggerMutex : public chip::rpc::Mutex
27+
{
28+
29+
public:
30+
void Lock() override
31+
{
32+
rtos::Mutex * mutex = PigweedLogger::GetSemaphore();
33+
if (mutex)
34+
{
35+
mutex->lock();
36+
}
37+
}
38+
void Unlock() override
39+
{
40+
rtos::Mutex * mutex = PigweedLogger::GetSemaphore();
41+
if (mutex)
42+
{
43+
mutex->unlock();
44+
}
45+
}
46+
};
47+
48+
extern PigweedLoggerMutex logger_mutex;
49+
50+
} // namespace rpc
51+
} // namespace chip

examples/pigweed-app/mbed/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config/
2+
build-*/

0 commit comments

Comments
 (0)