TECHNOLOGY

FreeRTOS stack units: ESP-IDF and upstream API names can hide different sizes

In this article
THE QUICK TAKE

Record the actual port and API units before comparing stack values; identical names do not make upstream word counts interchangeable with ESP-IDF byte counts.

A copied configuration changes its meaning

A sensor application moves an inference task from an upstream FreeRTOS project into ESP-IDF. It copies the numeric stack setting and the dashboard conversion used for a high-water value. The task name and API names look familiar, but the quantities no longer mean the same allocation. Before interpreting a crash or reducing an apparently oversized stack, record the specific RTOS implementation, task-creation function and reporting function. A porting change can create a unit defect without changing the model itself.

Upstream depth is expressed in stack words

The upstream task API header documents stack depth in words and high-water results as minimum free stack words since task creation. Preserve the relevant port’s stack element type when converting to bytes; do not hard-code a conversion from an unrelated processor example. The source reviewed is a development branch, so deployment evidence should retain the installed release and port. API declarations explain the unit contract but do not measure the application’s actual deepest call path.

ESP-IDF deliberately changes those units

The ESP-IDF documentation explicitly says its task stack sizes use bytes rather than upstream words. It also describes its high-water result in bytes. Treat this as a documented implementation difference, not a typo to normalize away. Review wrapper functions and telemetry exporters because a hidden additional multiplication can overstate the observed margin even after task creation was corrected. Keep the raw value, unit and originating API together rather than storing an unlabelled stack-free field.

Historical free stack is not global free heap

A high-water observation concerns the specified task’s history under paths that ran. It is not current global heap capacity and does not prove that an untested error branch fits. Identify parsing, preprocessing, inference and diagnostic paths that can deepen the task’s call chain or create large automatic objects. Also distinguish the task stack from interrupt-context resources and separately allocated tensor arenas. A generous arena does not repair a small task stack, and a large free-heap reading cannot certify the configured stack allowance.

Propose a unit-labelled task fixture

For the intended port, retain creation parameters with explicit units and observe the documented high-water API for the actual inference task. Exercise harmless representative and supported failure paths, keeping the firmware build fixed. Compare telemetry conversion with the API contract before using the result to change capacity. Acceptance requires consistent units and correct task behavior within a justified allowance. No firmware was flashed, stack exhausted or board memory measured here; the fixture describes validation without inventing a safe universal stack size.

Keep the port identity in the deployment record

CUDA thread-stack limits concern another execution context. Embedded memory boundaries explain why allocation categories should stay separate. Add RTOS implementation, stack units, task identity and exercised paths to a firmware record. That makes a porting regression diagnosable without claiming a model memory leak or interpreting familiar API spelling as proof that two embedded environments allocate and report identical resources.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles