Skip to content

Commit

Permalink
[zephyr] Fixed defining thread stack for Matter thread (#14625)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
kkasperczyk-no authored and pull[bot] committed Feb 16, 2022
1 parent b21b8ca commit 2722354
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions config/nrfconnect/app/sample-defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions examples/lighting-app/nrfconnect/rpc.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions examples/pigweed-app/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ void GenericPlatformManagerImpl_Zephyr<ImplClass>::EventLoopTaskMain(void * this
template <class ImplClass>
CHIP_ERROR GenericPlatformManagerImpl_Zephyr<ImplClass>::_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ template <class ImplClass>
class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl<ImplClass>
{
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;
Expand All @@ -65,7 +65,7 @@ class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl<Impl
// Although defining thread stack as a class member is feasible it's discouraged according to
// the Zephyr documentation (see remarks on K_THREAD_STACK_MEMBER macro). Therefore, this class
// requires the stack reference to be passed in the constructor.
ThreadStack & mChipThreadStack;
ThreadStack mChipThreadStack;
k_thread mChipThread;

// ===== Methods that implement the PlatformManager abstract interface.
Expand All @@ -82,7 +82,7 @@ class GenericPlatformManagerImpl_Zephyr : public GenericPlatformManagerImpl<Impl
CHIP_ERROR _Shutdown(void);

// ===== Methods available to the implementation subclass.
explicit GenericPlatformManagerImpl_Zephyr(ThreadStack & stack) : mChipThreadStack(stack) {}
explicit GenericPlatformManagerImpl_Zephyr(ThreadStack stack) : mChipThreadStack(stack) {}

private:
// ===== Private members for use by this class only.
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Zephyr/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
System::Clock::Timestamp mStartTime = System::Clock::kZero;
uint32_t mSavedOperationalHoursSinceBoot = 0;

explicit PlatformManagerImpl(ThreadStack & stack) : Internal::GenericPlatformManagerImpl_Zephyr<PlatformManagerImpl>(stack) {}
explicit PlatformManagerImpl(ThreadStack stack) : Internal::GenericPlatformManagerImpl_Zephyr<PlatformManagerImpl>(stack) {}

static PlatformManagerImpl sInstance;
};
Expand Down

0 comments on commit 2722354

Please sign in to comment.