ESP-IDF
ESP-IDF is the official development framework for the ESP32 and ESP32-S Series SoCs. This article is an introductory guide for working with ESP-IDF in CLion.
Some steps replicate the ESP-IDF Get Started guide. Examples below are given for the case of macOS.
Prepare the environment
Using your system terminal, create a directory for ESP-IDF and clone the official repository:
mkdir -p ~/esp cd ~/esp git clone --recursive https://github.com/espressif/esp-idf.git
ESP-IDF will be downloaded into ~
/esp ./esp-idf In the same shell, install the tools:
cd ~/esp/esp-idf ./install.sh
Set up a sample project using CLion's terminal
In CLion, go to File | Open and select the ~
/esp directory./esp-idf At this point, project loading might fail due to the Current directory '../esp/esp-idf' is not buildable... error.
Open CLion's built-in terminal (View | Tool Windows | Terminal or Alt+F12).
Set up the environment variables by running
. $HOME/esp/esp-idf/export.sh
:Let's configure the hello_world project from the examples/get-started directory. The following commands set ESP32 chip as the target and run the menuconfig configuration utility:
cd $IDF_PATH/examples/get-started/hello_world idf.py set-target esp32 idf.py menuconfig
The last command opens the configuration menu. As the hello_world project we are using will run with default configuration, you don't need to set it up in this menu.
Step out from the menu, and check the configuration is complete.
Now we can build hello_world by running
idf.py build
:
Next up, you can continue working with the project in CLion using the terminal. This will not require additional CMake configuration. Alternatively, you can set up CMake so that the project can be loaded, built and run without the command line. A few tips are given below.
note
There's a feature request for the ability to initialize toolchain environment via a script.
Configure CMake
First step would be to switch from the top-level CMakeLists.txt to the one located in examples
/get-started . Navigate to it in the project tree, right-click it, and select Load CMake project. Loading might fail at this point./hello_world Check the build failure message and set up the required environment variables.
For this, you can use the CMake settings dialog (Settings / Preferences | Build, Execution, Deployment | CMake, the Environment field).
Also, make sure you have the compiler, which is xtensa-esp32-elf-gcc for our project by default, installed on your machine. Add the full path to the
PATH
variable for CMake to be able to find it. Another option is to specify the paths in CMake settings (see Switching compilers in CLion).