From dfb50d059e404e41060871941ad276f9b88ade75 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Tue, 1 Feb 2022 12:08:50 +0100 Subject: [PATCH] [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 --- config/nrfconnect/app/sample-defaults.conf | 1 + .../platform/internal/GenericPlatformManagerImpl_Zephyr.cpp | 5 ++++- .../platform/internal/GenericPlatformManagerImpl_Zephyr.h | 6 +++--- src/platform/Zephyr/PlatformManagerImpl.h | 2 +- 4 files changed, 9 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/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..28a12ccad27c81 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; };