Skip to content
Published On:
Oct 15, 2024
Last Updated:
Oct 17, 2024

ESP32 is a series of low-cost, low-power SoC microcontrollers designed by Espressif Systems.

The ESP32 range is supported by the ESP-IDF framework.

Serial Bootloader

ESP32-S3’s have serial bootloaders permanently baked into their ROM, and can talk to a host computer running esptool.py over a USB serial connection. The serial protocol is described here.

To get around limitations with a permanently unmodifiable bootloader, the first thing esptool.py does when it connects is to upload a flasher stub (a.k.a. “stub loader” or “stub”) to the ESP32 SoC. This stub loader than essentially takes over as the bootloader, and can provide extra functionality or fix bugs in the ROM bootloader1.

ESP-IDF

ESP-IDF provides a FreeRTOS port that supports both the Xtensa and RISC-V architectures used by ESP SoCs. ESP-IDF provides different versions of FreeRTOS in order to support SMP (symmetric multiprocessing) on 2-core ESP SoCs. There is also the option of using the Amazon SMP FreeRTOS which supports any number of cores2. ESP-IDF uses CMake as it’s build system.

ESP-IDF supported SoCs as of October 2024.3.

ESP-IDF supports dev containers. There is a Docker image pushed to Docker Hub that can be used for both dev containers and CI/CD pipelines. It contains ESP-IDF plus all of the additional tools required to build a ESP-IDF based project4. It is tagged with the ESP-IDF version.

A screenshot of the .json file describing the ESP-IDF Dev Container.

Post-built Commands

To add a post-build command to a CMake-based ESP-IDF project, you can use the add_custom_command() function, targeting the gen_project_binary target and with the POST_BUILD argument. This function allows you to specify a shell command that should be executed after the build process has completed.

CMakeLists.txt
add_custom_command(
TARGET gen_project_binary
POST_BUILD
COMMAND echo "My custom command that runs after the project binary has been built."
)

Be aware that the shell command may make the project platform dependent. You could couple this with if(CMAKE_HOST_WIN32) style conditionals to run OS specific commands. You can see where the target gen_project_binary is defined in the ESP-IDF code here. app is another valid target you could use to run commands on.

Footnotes

  1. Espressif Systems. esptool.py > Flasher Stub [documentation]. Retrieved 2024-10-18, from https://docs.espressif.com/projects/esptool/en/latest/esp32s3/esptool/flasher-stub.html.

  2. Espressif Systems. ESP-IDF - API Reference > System API > FreeRTOS [documentation]. Retrieved 2024-10-15, from https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/freertos.html.

  3. Espressif Systems. ESP-IDF. Retrieved 2024-10-15, from https://idf.espressif.com/.

  4. dockerhub. espressif/idf [docker image]. Retrieved 2024-10-15, from https://hub.docker.com/r/espressif/idf.