This tutorial will go over integrating the panics component of the Memfault Firmware SDK into a system that is using the ESP-IDF for an ESP32 chip. It assumes you already have a working project/toolchain for the ESP32. If you do not, the official getting started guide is a great resource!
The integration works for both ESP-IDF 3.x and 4.x releases.
Using a Git client, clone the
In your top level
CMakeLists.txt, you can register the Memfault esp-idf port
as a "component" by simply including
You can also include Memfault build ID generation by adding a custom post-build
step to your top level
fw_build_id.py script adds a build ID that changes whenever the binary
changes. You can use this build ID as part of your software version reported by
memfault_platform_get_device_info(). See the demo app in
<PATH_TO_MEMFAULT_FIRMARE_SDK>/examples/esp32/apps/memfault_demo_app for an
example of how to use the build ID in your code.
fw_build_id_py depends on
pyelftools so you may need to install it by
pip install pyelftools.
By default, the esp-idf uses the
will need to update
sdkconfig (either via
idf.py menuconfig or manually) to
CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH=y. The change you will see in the
sdkconfig file will look something like:
You will need to allocate an internal flash partition for panic data to be stored in to your partition*.csv file. The change will look something like this:
The device metrics and trace event subsystems require configuration files to be added to your include path. ("memfault_metrics_heartbeat_config.def" & "memfault_trace_reason_user_config.def", respectively)
As a starting point, simply create empty files and add them to your include path:
When a panic occurs, information is collected to uniquely identify the device
and version of software running. Create a file, (i.e
and add it to your projects
Then implement the following function:
An API key will need to be included in order to communicate with Memfault's web
services. Go to https://app.memfault.com/, navigate to the project you want to
use and select 'Settings'. Copy the 'Project Key' and replace
<YOUR API KEY HERE> below and then add the following to your code:
At this point, the Memfault SDK has been integrated into your ESP-IDF project and you need to rebuild:
The esp-idf port registers some CLI commands so you can easily try things out!
As a first step you can try collecting and sending a coredump with the following commands:
With the esp-idf, data can be posted anytime you are connected to the internet
by calling the following code. We recommend running it at a periodic interval.
If there is no new data to send, the call reduces to a no-op. The same logic can
also be invoked via the memfault CLI with the
mflt post_chunks mentioned