ESP-IDF CLion Plugin for ESP-IDF CMake based projects (4.x and above).
The source for the initial start of the plugin was taken from this project.
- Configuration and Installation
- Creating New Project
- Building Flashing and Serial Monitor
- OpenOCD Debugging
To install the plugin, download the release zip file from the releases section. Unzip the file, but do not unzip the internal zip file. The product files are located in the root of the unzipped folder.
Start the CLion.
It is recommended to first configure the CLion using some example project
-
Next click on the settings wheel on the top and select
Install Plugins from Disk...
-
From the popup window select the zip you extracted and click Ok
-
After the installation you will be show the plugin installed, but you will have to restart the IDE. So click on the Restart IDE button
At this stage you have installed the plugin but since the plugin is in the beta versions, there are some configurations that are required to be done manually for IDF.
- You need to download and install the IDF Tools. You can download and install them from the IDF Page. Once you have downloaded and installed the tools you can continue on the next step.
- Now Load an example project from the idf folder. For this document we will be using hello_world example.
- Once you have selected and opened the project you will be given with the following project configuration wizard. Please remove all the existing toolchains from here.
- After that click on
+
Add and select system from the dropdown
- Next step please configure the Paths. The tools are usually installed under the
.espressif
directory in the user home folder. You can find the tools for the board you are working from there for this example we are using esp32 and the image below shows the paths for those tools. Next once the paths are configured ClickNext
.
- Now in the next window configure the IDF_PATH and the Virtual Python env path as shown below in CMake options, replace path according to your idf installation
- Also make sure that in the env variables you add the following shown below. In the bottom section note that in the path variable we have added the bin directory for the xtensa-esp32-elf bin directory from the espressif tools installation directory.
- Next Press
Ctrl+Alt+S
to open the settings or you can go to settings from the File Menu. Open the settings for Python Interpreter.
Click on...
and selectpython.exe
from the.espressif/python_env/VERSION_OF_IDF_YOU_INSTALLED_PYTHON_VERSION_ON_YOUR_SYSTEM/Scripts
directory in user home and click Ok - If all goes well you will be able to see these launch configurations that you can use to build and deploy the application.
These are the basic configurations that are required since the plugin is in beta version at the moment
- Open CLion and Click on
File > New > Project
- Provide a name and click on
Create
- Once the project is created, follow the steps required for CMake configuration from the Configuration and Installation section.
- Create a directory called
main
in the project root and add a filemain.c/main.cpp
there. Also create aCMakeList.txt
in this directory
set(SOURCES "main.c")
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS "")
- Now add another CMakeList.txt in the project root
cmake_minimum_required(VERSION 3.24)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(CMAKE_C_COMPILER C:/Users/your_user/.espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc.exe)
set(CMAKE_ASM_COMPILER C:/Users/your_user/.espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++.exe)
project(esp_idf_demo)
include_directories("src")
- To export the environment variables for your development platform, open a CLion terminal and navigate to the
esp-idf
home directory. Then, run the appropriate export script:- Windows:
export.ps1
- macOS and Linux:
export.sh
- Windows:
- Now from the terminal you can use
idf.py
commands. - Set the target using the terminal in CLion
idf.py set-target esp32
- You can build and flash your project using the
idf.py
commands. If the configurations are correct, you will also see the launch configurations in the dropdown menu. These launch configurations can be used to build, flash, and debug your project. For more information, see Building Flashing and Serial Monitor section.
To build the project you can select app from the launch configuration and click build.
To flash the application you can select flash option from launch configuration and click Run
button.
To make sure that you are flashing on the correct port you can modify the env variables in flash configuration.
To do that click on the arrow next to flash configuration from dropdown and click Edit.
From the next screen you can add an environment variable as shown below for the port.
The serial monitor for this version is still a work in progress. You cannot run it from the monitor option in
launch configurations at the moment. Although you can try to use the terminal in the CLion
to run idf.py monitor command
but make sure that your CLion is configured to use the default build
directory since
the default build directory in the CLion is different.
ESP Debug Configuration
is the newly added feature to support debugging using the OpenOCD.
Please follow the below steps to configure.
- From the
Run
menu, click onEdit Configurations
and click on+
from the opened window and selectESP Debug Configuration
. - Make sure to select the
Executable
andTarget
from the dropdown. AlsoSelect Board
according to your board. Once you have selected the board and configured other settings, click OK. - To start debugging, click the
Debug
button or pressShift+F9
(the default shortcut for debugging on Windows). Make sure that the debug configuration you created is selected in the plugin. When your breakpoint is hit, you will see the debug view with all the available features in CLion. You can view threads, stacktraces, and access the GDB console.