Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pigweed-app example: nrfconnect SDK logs redirect to pw_hdlc #4775

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/common/pigweed/nrfconnect/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
52 changes: 52 additions & 0 deletions examples/common/pigweed/nrfconnect/PigweedLoggerMutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*
* 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.
*/

#pragma once

#include "PigweedLogger.h"
#include "pigweed/RpcService.h"
#include <kernel.h>

namespace chip {
namespace rpc {
class PigweedLoggerMutex : public ::chip::rpc::Mutex
{
public:
PigweedLoggerMutex() {}
void Lock() override
{
k_sem * sem = PigweedLogger::GetSemaphore();
if (sem)
{
k_sem_take(sem, K_FOREVER);
}
}
void Unlock() override
{
k_sem * sem = PigweedLogger::GetSemaphore();
if (sem)
{
k_sem_give(sem);
}
}
};

extern PigweedLoggerMutex logger_mutex;

} // namespace rpc
} // namespace chip
4 changes: 3 additions & 1 deletion examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pw_proto_library(pigweed_lighting_protolib
target_sources(app PRIVATE
main/Rpc.cpp
../../common/pigweed/RpcService.cpp
../../common/pigweed/nrfconnect/PigweedLoggerMutex.cpp
${NRFCONNECT_COMMON}/util/PigweedLogger.cpp
)

Expand All @@ -96,7 +97,8 @@ target_include_directories(app PRIVATE
${PIGWEED_ROOT}/pw_sys_io/public
${CHIP_ROOT}/src/lib/support
${CHIP_ROOT}/src/system
../../common)
../../common
../../common/pigweed/nrfconnect)

target_link_libraries(app PRIVATE
pigweed_lighting_protolib.nanopb_rpc
Expand Down
27 changes: 2 additions & 25 deletions examples/lighting-app/nrfconnect/main/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Rpc.h"
#include "AppTask.h"
#include "PigweedLogger.h"
#include "PigweedLoggerMutex.h"
#include "pigweed/RpcService.h"

#include "main/pigweed_lighting.rpc.pb.h"
Expand Down Expand Up @@ -52,30 +53,6 @@ namespace {

using std::byte;

class PigweedLoggerMutex : public ::chip::rpc::Mutex
{
public:
PigweedLoggerMutex() {}
void Lock() override
{
k_sem * sem = PigweedLogger::GetSemaphore();
if (sem)
{
k_sem_take(sem, K_FOREVER);
}
}
void Unlock() override
{
k_sem * sem = PigweedLogger::GetSemaphore();
if (sem)
{
k_sem_give(sem);
}
}
};

PigweedLoggerMutex uart_mutex;

constexpr size_t kRpcTaskSize = 4096;
constexpr int kRpcPriority = 5;

Expand All @@ -101,7 +78,7 @@ k_tid_t Init()

void RunRpcService(void *, void *, void *)
{
Start(RegisterServices, &uart_mutex);
Start(RegisterServices, &logger_mutex);
}

} // namespace rpc
Expand Down
1 change: 1 addition & 0 deletions examples/pigweed-app/nrfconnect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
38 changes: 35 additions & 3 deletions examples/pigweed-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connect
get_filename_component(NRFCONNECT_COMMON ${CHIP_ROOT}/examples/platform/nrfconnect REALPATH)
set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")

set(CONF_FILE ${CHIP_ROOT}/config/nrfconnect/app/sample-defaults.conf prj.conf)

if(${BOARD} STREQUAL "nrf52840dongle_nrf52840")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-usb_support.conf)
endif()
Expand All @@ -29,17 +31,47 @@ find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(chip-nrf52840-pigweed-example)

target_include_directories(app PRIVATE main/include
zephyr_compile_options(-Werror)

include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)

pw_set_backend(pw_log pw_log_basic)
pw_set_backend(pw_assert pw_assert_log)
pw_set_backend(pw_sys_io pw_sys_io.nrfconnect)
set(dir_pw_third_party_nanopb PRESENT CACHE STRING ${CHIP_ROOT}/third_party/nanopb/repo FORCE)

add_subdirectory(third_party/connectedhomeip/examples/platform/nrfconnect/pw_sys_io)
add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo)
add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo)

target_include_directories(app PRIVATE main/include
${ZEPHYR_BASE}/subsys // required to get access to `log_output_std.h`
${NRFCONNECT_COMMON}/util/include
${CHIP_ROOT}/src/lib/support
${PIGWEED_ROOT}/pw_sys_io/public
${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_status/public
${PIGWEED_ROOT}/pw_preprocessor/public
../../common
../../common/pigweed/nrfconnect
${NRFCONNECT_COMMON}/pw_sys_io/public)

target_sources(app PRIVATE main/main.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp)
target_sources(app PRIVATE main/main.cpp
../../common/pigweed/RpcService.cpp
../../common/pigweed/nrfconnect/PigweedLoggerMutex.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/PigweedLogger.cpp
)

target_link_libraries(app PUBLIC
pw_hdlc
pw_log
pw_rpc.nanopb.echo_service
pw_rpc.server
)
32 changes: 27 additions & 5 deletions examples/pigweed-app/nrfconnect/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

#include "AppConfig.h"
#include "LEDWidget.h"
#include "PigweedLoggerMutex.h"
#include "pigweed/RpcService.h"
#include <kernel.h>

#include "pw_rpc/echo_service_nanopb.h"
#include "pw_sys_io/sys_io.h"
#include "pw_sys_io_nrfconnect/init.h"

Expand All @@ -28,9 +32,26 @@ LOG_MODULE_REGISTER(app);

static LEDWidget sStatusLED;

namespace hdlc_example {
extern void Start();
} // namespace hdlc_example
namespace {
#define RPC_STACK_SIZE (8 * 1024)
#define RPC_PRIORITY 7

K_THREAD_STACK_DEFINE(rpc_stack_area, RPC_STACK_SIZE);
struct k_thread rpc_thread_data;

pw::rpc::EchoService echo_service;

void RegisterServices(pw::rpc::Server & server)
{
server.RegisterService(echo_service);
}

void RunRpcService(void *, void *, void *)
{
Start(RegisterServices, &::chip::rpc::logger_mutex);
}

} // namespace

int main()
{
Expand All @@ -51,7 +72,8 @@ int main()
sStatusLED.Init(SYSTEM_STATE_LED);
sStatusLED.Set(true);

hdlc_example::Start();

k_thread_create(&rpc_thread_data, rpc_stack_area, K_THREAD_STACK_SIZEOF(rpc_stack_area), RunRpcService, NULL, NULL, NULL,
RPC_PRIORITY, 0, K_NO_WAIT);
k_thread_join(&rpc_thread_data, K_FOREVER);
return 0;
}
65 changes: 15 additions & 50 deletions examples/pigweed-app/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
CONFIG_CHIP=y

CONFIG_NEWLIB_LIBC=y

# Export POSIX names for functions implementing a subset of POSIX standard in Zephyr
CONFIG_POSIX_API=y
CONFIG_PTHREAD_IPC=y
CONFIG_EVENTFD=y

CONFIG_LOG=n
CONFIG_LOG_MINIMAL=n
CONFIG_ASSERT=y
CONFIG_HW_STACK_PROTECTION=y

# Generic networking options
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=n

# Application stack size
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_INIT_STACKS=y

# Disable certain parts of Zephyr IPv6 stack
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_MLD=n

# Use mbedTLS from nrf_security library
CONFIG_NORDIC_SECURITY_BACKEND=y
CONFIG_OPENTHREAD_MBEDTLS=n

CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=15360
CONFIG_MBEDTLS_TLS_LIBRARY=y
CONFIG_NRF_SECURITY_ADVANCED=y

CONFIG_MBEDTLS_AES_C=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_ECP_C=y
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
CONFIG_MBEDTLS_CTR_DRBG_C=y
CONFIG_MBEDTLS_CIPHER_MODE_CTR=y
CONFIG_MBEDTLS_ECJPAKE_C=y

# Disable unneeded crypto operations
CONFIG_MBEDTLS_SHA512_C=n
CONFIG_MBEDTLS_CIPHER_MODE_XTS=n
CONFIG_MBEDTLS_CHACHA20_C=n
CONFIG_MBEDTLS_POLY1305_C=n
CONFIG_MBEDTLS_CHACHAPOLY_C=n
CONFIG_MBEDTLS_GCM_C=n

# Add support for LEDs and buttons on Nordic development kits
CONFIG_DK_LIBRARY=y
Expand All @@ -76,9 +27,23 @@ CONFIG_MPU_STACK_GUARD=y
CONFIG_CHIP_PW_RPC=y

# Add support for C++17 to build Pigweed components
CONFIG_STD_CPP14=n
CONFIG_STD_CPP17=y

# Add support for Zephyr console component to use it for Pigweed console purposes
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_CONSOLE_GETCHAR_BUFSIZE=256
CONFIG_CONSOLE_PUTCHAR_BUFSIZE=256

# Disable features which may interfere with Pigweed HDLC transport
CONFIG_SHELL=n
CONFIG_OPENTHREAD_SHELL=n
CONFIG_BOOT_BANNER=n

# Configure Zephyr logger with defaults backends disabled as the app provides its own,
# based on Pigweed HDLC.
CONFIG_LOG=y
CONFIG_LOG_MINIMAL=n
CONFIG_LOG_IMMEDIATE=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_BACKEND_RTT=n