YAGNI
Setup ESP32 development tools in Gentoo
About
The ESP32 is a family of cost accessible microcontrollers with many features that make them attractive to embedded systems hobbyists.
ESP-IDF is Esspressif's official IoT development framework for a number of ESP32 SoC. Gentoo's main repository doesn't provide an ebuild for this framework, but it's available in the GURU repository.
This post will explain the steps to install the ESP-IDF framework, then use it to build a sample project and flash it into a ESP32-C3 development board.
Install ESP-IDF
Enable the GURU repository and synchronize it, the preferred way is using eselect-repository:
eselect repository enable guru emaint sync -r guru
It's important to enable the riscv32
use flag if one is going to be
developing for a board with a RISCV microcontroller (i.e. ESP32-C3).
By the time of this writing, the following packages had to be unmasked before being able to install the framework:
$ cat /etc/portage/package.accept_keywords/esp-idf dev-embedded/esp-*::guru dev-embedded/freertos-gdb::guru dev-embedded/idf-component-manager::guru dev-python/jsonref dev-python/kconfiglib dev-python/pydantic-settings dev-python/schema
Install the ESP-IDF framework:
emerge -a esp-idf
Build and flash a test project
The ESP-IDF framework comes with a number of examples. This section explains the steps to follow for building and flashing the hello_world project included in the framework:
$ equery f esp-idf | grep get-started/hello_world /usr/share/esp-idf/examples/get-started/hello_world /usr/share/esp-idf/examples/get-started/hello_world/CMakeLists.txt /usr/share/esp-idf/examples/get-started/hello_world/README.md /usr/share/esp-idf/examples/get-started/hello_world/main /usr/share/esp-idf/examples/get-started/hello_world/main/CMakeLists.txt /usr/share/esp-idf/examples/get-started/hello_world/main/hello_world_main.c /usr/share/esp-idf/examples/get-started/hello_world/pytest_hello_world.py /usr/share/esp-idf/examples/get-started/hello_world/sdkconfig.ci
To build the project, copy the hello_world direcotyr to a place with write permissions (i.e. the user's home direcory).
cp -r /usr/share/esp-idf/examples/get-started/hello_world ~ cd ~/hello_world
Now configure the project's target to the correct development board; in this
example it's set to esp32c3
that corresponds to the ESP32-C3-DevKitC.
idf set-target esp32c3
Connect the development board to the computer and proceed to build it, flash it and monitor the execution:
idf build idf flash monitor
The PORT
used for flashing the microcontroller should be automatically
detected; if it wasn't, refer to the links in the See also section.