From 272235422eb16dd8d0a2fc0e7d6058443fe8d63f Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Thu, 3 Feb 2022 15:48:57 +0100 Subject: [PATCH] [zephyr] Fixed defining thread stack for Matter thread (#14625) * [zephyr] Fixed defining thread stack for Matter thread By the way of enabling hardware FPU it turned out that we use wrong Zephyr macro to define thread stack size and it may happen that it will not be consistent with exact thread stack size. * Removed using K_THREAD_STACK_LEN macro * Changed ThreadStack to be pointer on k_thread_stack_t, as Zephyr API doesn't expose API to calculate aligned Thread stack size based on desired stack size * Aligned other methods API to ThreadStack changes * Enabled using hardware floating-point unit for nrfconnect platform * Disabled HW FPU for builds with libprotobuf-nanopb Libprotobuf-nanpobd seems to not support building with hardware floating-point unit and linking the target fails. --- config/nrfconnect/app/sample-defaults.conf | 1 + examples/lighting-app/nrfconnect/rpc.overlay | 3 +++ examples/pigweed-app/nrfconnect/prj.conf | 3 +++ .../platform/internal/GenericPlatformManagerImpl_Zephyr.cpp | 5 ++++- .../platform/internal/GenericPlatformManagerImpl_Zephyr.h | 6 +++--- src/platform/Zephyr/PlatformManagerImpl.h | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config/nrfconnect/app/sample-defaults.conf b/config/nrfconnect/app/sample-defaults.conf index 7e451f40ed6536..9dc094c92f2052 100644 --- a/config/nrfconnect/app/sample-defaults.conf +++ b/config/nrfconnect/app/sample-defaults.conf @@ -25,6 +25,7 @@ CONFIG_PRINTK_SYNC=y CONFIG_ASSERT=y CONFIG_HW_STACK_PROTECTION=y CONFIG_SHELL=y +CONFIG_FPU=y # Enable getting reboot reasons information CONFIG_HWINFO=y diff --git a/examples/lighting-app/nrfconnect/rpc.overlay b/examples/lighting-app/nrfconnect/rpc.overlay index eac4807039a8d4..aee22afb4a39c5 100644 --- a/examples/lighting-app/nrfconnect/rpc.overlay +++ b/examples/lighting-app/nrfconnect/rpc.overlay @@ -26,6 +26,9 @@ CONFIG_CHIP_PW_RPC=y CONFIG_STD_CPP14=n CONFIG_STD_CPP17=y +# Disable HW floating point, as libprotobuf nano doesn't support building with it +CONFIG_FPU=n + # Add support for Zephyr console component to use it for Pigweed console purposes CONFIG_CONSOLE_SUBSYS=y CONFIG_CONSOLE_GETCHAR=y diff --git a/examples/pigweed-app/nrfconnect/prj.conf b/examples/pigweed-app/nrfconnect/prj.conf index 58a0fe63277b34..0895493dcc8f72 100644 --- a/examples/pigweed-app/nrfconnect/prj.conf +++ b/examples/pigweed-app/nrfconnect/prj.conf @@ -30,6 +30,9 @@ CONFIG_CHIP_PW_RPC=y CONFIG_STD_CPP14=n CONFIG_STD_CPP17=y +# Disable HW floating point, as libprotobuf nano doesn't support building with it +CONFIG_FPU=n + # Add support for Zephyr console component to use it for Pigweed console purposes CONFIG_CONSOLE_SUBSYS=y CONFIG_CONSOLE_GETCHAR=y diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp index b8358b59f269bf..6b4d5996d250be 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp @@ -174,7 +174,10 @@ void GenericPlatformManagerImpl_Zephyr::EventLoopTaskMain(void * this template CHIP_ERROR GenericPlatformManagerImpl_Zephyr::_StartEventLoopTask(void) { - const auto tid = k_thread_create(&mChipThread, mChipThreadStack, K_THREAD_STACK_SIZEOF(mChipThreadStack), EventLoopTaskMain, + if (!mChipThreadStack) + return CHIP_ERROR_WELL_UNINITIALIZED; + + const auto tid = k_thread_create(&mChipThread, mChipThreadStack, CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE, EventLoopTaskMain, this, nullptr, nullptr, CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY, 0, K_NO_WAIT); #ifdef CONFIG_THREAD_NAME diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h index 9fc1438f4beff6..884a052a207ea6 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h @@ -45,7 +45,7 @@ template class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl { protected: - using ThreadStack = k_thread_stack_t[K_THREAD_STACK_LEN(CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE)]; + using ThreadStack = k_thread_stack_t *; // Members for select() loop int mMaxFd; @@ -65,7 +65,7 @@ class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl(stack) {} + explicit PlatformManagerImpl(ThreadStack stack) : Internal::GenericPlatformManagerImpl_Zephyr(stack) {} static PlatformManagerImpl sInstance; };