Improve thread stack size

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

Hello.

I've bought CYW943907AEVAL1F and I developed a firmware that use WiFi and USB as CDC-ACM.

I create some threads using 1024 as stack size.

I observe that WICED resets when I send a particular TCP packet  to one of my thread that is waiting for TCP packet.

 

Today I launch debugger and I notice that there is a "threadx stack overflow". So I decide to increase this thread stack size progressively. This problems disappears when I set thread stack size to 2048.

 

I observe this problem in another thread , so I have to increase "thread stack size" for this other thread.

 

MaFa_974161_0-1621843739954.png

 

 

My question is : it is possibile that I have to use so large stack size ?

0 Likes
1 Solution
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

Hello:

How big a stack should be is one of the most
frequently asked questions about threads. A thread’s
stack area must be large enough to accommodate
worst-case function call nesting, local variable
allocation, and saving its last execution context.
The minimum stack size, TX_MINIMUM_STACK, is
defined by ThreadX. A stack of this size supports
saving a thread’s context and minimum amount of
function calls and local variable allocation.
For most threads, however, the minimum stack size
is too small, and the user must ascertain the worstcase
size requirement by examining function-call nesting and local variable allocation.

Of course, it is  always better to start with a larger stack area.

View solution in original post

0 Likes
3 Replies
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

Hello:

  I just check some stack setting in our release, just for your reference:

#define WWD_THREAD_STACK_SIZE (1248 + 1400) /*(632)*/ /* Stack checking requires a larger stack */

#define P2P_THREAD_STACK_SIZE (5*1024)

/************************************************************************
* Application thread stack size */
#define WICED_DEFAULT_APPLICATION_STACK_SIZE (61440)

#define SUPPLICANT_THREAD_STACK_SIZE ( 4*1024 )
#define TLS_AGENT_THREAD_STACK_SIZE ( 4*1024 )

I think the size change of your customized thread is reasonable, if you want to use smaller stack size, you need to check the thread func usage , thanks.

 

0 Likes

In which file ?

I believe "WICED.ROTS.ThreadX.WWD.wwd_rtos.h" ...

In this file I found 

MaFa_974161_0-1621923732828.png

 

What do you mean with " thread func usage " ?

 

 

0 Likes
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

Hello:

How big a stack should be is one of the most
frequently asked questions about threads. A thread’s
stack area must be large enough to accommodate
worst-case function call nesting, local variable
allocation, and saving its last execution context.
The minimum stack size, TX_MINIMUM_STACK, is
defined by ThreadX. A stack of this size supports
saving a thread’s context and minimum amount of
function calls and local variable allocation.
For most threads, however, the minimum stack size
is too small, and the user must ascertain the worstcase
size requirement by examining function-call nesting and local variable allocation.

Of course, it is  always better to start with a larger stack area.

0 Likes