CLion 2021.1 Help

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

  1. 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.

  2. In the same shell, install the tools:

    cd ~/esp/esp-idf ./install.sh

Set up a sample project using CLion's terminal

  1. In CLion, go to File | Open and select the ~/esp/esp-idf directory.

    At this point, project loading might fail due to the Current directory '../esp/esp-idf' is not buildable... error.

  2. Open CLion's built-in terminal (View | Tool Windows | Terminal or Alt+F12).

  3. Set up the environment variables by running . $HOME/esp/esp-idf/export.sh:

    The result of setting ESP-IDF environment

  4. 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.

    Configuration menu

    Step out from the menu, and check the configuration is complete.

  5. Now we can build hello_world by running idf.py build:

    Build result

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.

Configure CMake

  1. First step would be to switch from the top-level CMakeLists.txt to the one located in examples/get-started/hello_world. Navigate to it in the project tree, right-click it, and select Load CMake project. Loading might fail at this point.

  2. 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).

  3. 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).

    Environment variables for CMake

Last modified: 08 March 2021