DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • The Impact of AI Agents on Modern Workflows
  • The Perceptron Algorithm and the Kernel Trick
  • A Developer’s Guide to Multithreading and Swift Concurrency
  • Mastering AI Agents: How Agentic Design Patterns Make Agents Smarter

Trending

  • The Truth About AI and Job Loss
  • The Missing Infrastructure Layer: Why AI's Next Evolution Requires Distributed Systems Thinking
  • Mastering Fluent Bit: Controlling Logs With Fluent Bit on Kubernetes (Part 4)
  • When Agile Teams Fake Progress: The Hidden Danger of Status Over Substance

Understanding FreeRTOS Task Stack Usage and Kernel Awareness Info

Diving into FreeRTOS' Task Lisk in MCUXPresso can be confusing at first. Let's look into how to examine and understand how your stack is being used.

By 
Erich Styger user avatar
Erich Styger
·
May. 25, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
19.9K Views

Join the DZone community and get the full member experience.

Join For Free

When using the FreeRTOS Task List in the Eclipse-based MCUXpresso IDE, it shows the list of tasks with their stack size used. But with the default FreeRTOS settings, it is not able to determine the correct stack size and shows a warning icon:

Warning for Stack Usage

Warning for stack usage

The warning should tell me that the information shown about the stack size is wrong: I did create the App Task with 110 stack units (each 4 bytes) so it should show 440 bytes, but it shows only 308 bytes.

Why is that? The reason is that the debugger (or FreeRTOS Kernel Awareness in Eclipse) does not know the total size of the memory allocated for the task.

On ARM Cortex, the stack is growing from the higher to the lower addresses, as shown in the image below:

FreeRTOS Task Stack Layout

FreeRTOS task stack layout

What FreeRTOS stores in its TCB (Task Control Block, the descriptor of the task) is the pxTopOfStack (current task stack pointer, Stack Top in the Kernel Awareness view) and pxStack (the end of the stack, Stack Base in the Kernel Awareness view). The beginning of the task stack is not stored in the TCB as not necessary for the Kernel.

The ‘Stack High Water Mark’ is something very useful: FreeRTOS fills the stack space at task creation time with a 0x5a byte pattern. The debugger or the RTOS can find out the ‘high water mark’ for each task that way.

The solution is to add the following macro to the FreeRTOSConfig.h file:

#define configRECORD_STACK_HIGH_ADDRESS (1)


With this turned on, FreeRTOS stores an extra pointer pxEndOfStack in each Task TCB:

FreeRTOS Task Stack Information with configRECORD_STACK_HIGH_ADDRESS

FreeRTOS task stack information with configRECORD_STACK_HIGH_ADDRESS

Below is such a TCB in the Global Variables View in Eclipse (MCUXpresso IDE):

Stack Information in FreeRTOS TCB

Stack information of FreeRTOS TCB

With this, the debugger or FreeRTOS Task Awareness knows the real size of the stack and can show the correct information:

FreeRTOS Stack Size

FreeRTOS stack size

Actually, it is still showing 432 bytes because it does not count the first and last entry on the stack.

The image below should help you understand the information provided:

  • Blue: At the bottom, there is the currently used stack. The stack is growing upwards here (from the higher to the lower addresses).
  • Orange: Used stack so far (high water mark) as it has overwritten the 0xA5 pattern.
  • Yellow: Unused stack space so far with the 0xA5 pattern.
FreeRTOS Stack Memory

FreeRTOS stack memory

Of course, there is a reason for FreeRTOS not storing that pxEndOfStack by default: It is not needed by the Kernel. So enabling configRECORD_STACK_HIGH_ADDRESS will need 4 more bytes of RAM for each task, plus a few code bytes to set that value. But for debugging purposes, this is very well spent.

Happy stacking!

Links

  • Better FreeRTOS Debugging in Eclipse
  • FreeRTOS Kernel Awareness for Eclipse from NXP
FreeRTOS Task (computing) Kernel (operating system)

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The Impact of AI Agents on Modern Workflows
  • The Perceptron Algorithm and the Kernel Trick
  • A Developer’s Guide to Multithreading and Swift Concurrency
  • Mastering AI Agents: How Agentic Design Patterns Make Agents Smarter

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: