Stack size for thread is very critical. Use a larger size (2048 bytes or larger) if possible in the beginning. Use the RTOS profiler to reduce the size later.

Hi all,

Today, I used 1024 bytes for my thread's stack.    It kept failing for an unknown reason.  Even the debugger failed to run.  After I doubled the size of the stack to 2048 bytes, the program worked very good and the debugger worked again.    My program makes a multiple function calls. So, I can understand that it may require a larger stack to work with than a simpler program. 

I want to share my experience with you because it seems impossible to debug when the stack is causing the program to crash too early.  I did not have much clue especially when the debugger failed to work.   I was lucky today to find the cause and get it to work.

Best,

Michael

  • Michael, thanks for your contribution. I'm sure this will solve other people frustration. Have a great weekend!
  • In reply to codetricity:

    Sure. Thank you.

    Yes. Moreover, the famous Renesas IOT professor also mentioned in his past ThreadX related post about the danger of the thread stack overflow problem. He recommended making the stack size large (if possible) in the initial stage of the software development and used the RTOS profiler in E2 Studio to reduce the size in the final stage of the software development.

    Base on his posts and other users' forum posts, I developed a section in my tutorial to show how to use the RTOS profiler in E2 Studio. See the Debugging Section. It is very easy to find the best stack size to use with the tool. The ThreadX RTOS profiler is free and comes with E2 Studio.

    Below is the link to my blog domain. Feel free to check it out.
    www.miketechuniverse.com/.../I2C-Tutorial-for-Renesas-S5D9-board-Add-ThreadX-real-time-OS-support-Part-3

    Best,
    Michael