ESP32 Development with CLion
Since I wasn’t used to VSCode’s half-baked C++ IDE features, I turned to CLion. But CLion in turn faces the problem of having fewer plugins than VSCode, so I ran into issues when developing for the ESP32. Finally, let me stress: if you primarily use VSCode for development, just use the official plugin provided by ESP32 — it’s simple and convenient, no command line required.
Steps
Actually, there is no need to bother with environment variables or cross-compilation toolchains. I’ve tried them, and they’re useless — they only add unnecessary trouble.
Just open the ESP32 project directly with the default toolchain, as long as CMake is provided. Compile once with idf.py build, then reload the CMake project in CLion, and CLion will seemingly recognize the build artifacts on its own and configure automatically.
Then you can happily edit code with intelligent suggestions.
If you occasionally run into code recognition issues, just repeat the steps above.
Windows is even simpler: after installing ESP-IDF, two command-line shortcuts are placed on the desktop, ESP-IDF <version> CMD and ESP-IDF <version> PowerShell. Pick either one and type clion, and the CLion that opens will automatically use ESP-IDF’s variables.
Issues
The downside is that there is no official support after all. Based on my testing, only the build and flash commands execute successfully; other commands like monitor are either ineffective or malfunction.
It’s better to type commands by hand in the command line and use CLion’s code-editing assistance features for development. If you find that troublesome, you can also manually add a Run/Debug Configuration, except that it cannot be used as a template across projects — it has to be reconfigured for every project.
If that’s too much trouble, you can also set up aliases for the commands:
| |
In addition, on Linux systems you may also run into the issue of no permission for the serial port. Here’s how to solve it:
Check the permissions of the serial port ttyUSB0:
| |
You can see that the owning user group is dialout, and only the root user has the permission to operate it.
Check the current user:
| |
Then add the current user to the dialout group so that they have permission to operate the serial port ttyUSB0:
| |
Done, just reboot the system.