Skip to main content

ESP-IDF Adv. - Lecture 3

·3 mins·
Table of Contents
In this article, we cover two key tools for embedded development on Espressif platforms: size analysis and core dumps. You’ll learn what they do, why they matter, and how to use them to build more efficient and reliable applications.

Introduction
#

We’ll focus on two useful tools:

  • Size Analysis: Understand and manage your application’s memory footprint.
  • Core Dump: Capture the system state after a crash for detailed post-mortem debugging.

Let’s take a closer look at each.

Size Analysis
#

What Is Size Analysis?
#

Size analysis is the process of examining how much flash and RAM your firmware consumes. This helps ensure the application fits within the target hardware and leaves enough memory available for runtime operations such as task scheduling, buffer management, and peripheral interaction.

Performing Size Analysis
#

When building a project with ESP-IDF, the build system automatically provides a memory usage summary. After running:

  • ESP-IDF: Build Your Project

You’ll see output like this:

Total sizes:
 DRAM .data size:   1234 bytes
 DRAM .bss  size:   5678 bytes
 IRAM   size:       9101 bytes
 Flash code size:   11213 bytes
 Flash rodata size: 1415 bytes

This breakdown gives insight into where your application is consuming resources. For deeper analysis, ESP-IDF offers additional commands:

  • idf.py size: Provides a summary of statically-allocated memory usage.
  • idf.py size-components: Shows per-component memory usage.
  • idf.py size-files: Breaks down usage by source file.
  • idf.py size-symbols: Lists symbol-level memory usage (useful for pinpointing heavy functions or variables).

These tools help identify memory hotspots and guide you in optimizing your codebase.

Once you know the memory usage of your firmware, you can begin pruning both the configuration and code to reduce it. After making your changes, test the memory usage again to see how much impact they had.

Core Dumps
#

What Is a Core Dump?
#

A core dump is a snapshot of the device’s memory and processor state at the time of a crash. It includes:

  • Call stacks of all tasks
  • CPU register contents
  • Relevant memory regions

This data allows developers to analyze what went wrong, even after the device resets, making core dumps an invaluable tool for diagnosing hard-to-reproduce bugs.

Enabling and Using Core Dumps
#

To enable core dumps on an Espressif device using ESP-IDF, you need to

  1. Enable the core dump in the menuconfig

  2. Trigger and Analyze the Core Dump When a crash occurs, the Espressif chip saves the core dump to flash or shows it in UART. You can analyze it using:

    idf.py coredump-info
    

These commands decode the core dump and present a readable backtrace, variable states, and register values. This makes it easier to identify the root cause of a failure.

Core dumps are an invaluable tool to be used alongside debugging.

Conclusion
#

Mastering size analysis and core dumps is extremely useful for embedded developers. Size analysis helps ensure your application remains within resource limits and runs efficiently, while core dumps provide a powerful mechanism for post-crash diagnostics.

By integrating these tools into your development workflow, you’ll be better prepared to build robust, high-performance applications.

Next step: assignment 3.1

Further Reading
#

Related

ESP-IDF Adv. - Lecture 2
5 mins
In this article, we explore the event loop—a core component of Espressif’s ESP-IDF framework that facilitates efficient, decoupled, and asynchronous event handling in embedded applications. We examine its functionality, highlight its benefits, explain how it is used by default within ESP-IDF, and provide practical code examples to demonstrate common usage patterns.
ESP-IDF Adv. - Lecture 1
8 mins
In this lecture, we explore the ESP-IDF build system, built on CMake and Ninja. We focus on modular components, the Component Manager, and Board Support Packages (BSPs) for hardware abstraction. We also cover how to create custom components and manage configurations using sdkconfig files and build profiles, enabling flexible and reproducible builds.
ESP-IDF Adv. - Lecture 4
11 mins
In this article, we explore the advanced features required for security: OTA update, flash encryption, and secure bootloader