[ESP32][Environment Configuration] Clion configures the ESP-IDF development environment, supports compiling and downloading and menucofig

Preface: Why use CLion for development?

I read a lot of tutorials about adapting Clion on the Internet, including Mr. Zhihui’s tutorial on adapting STM32CubeMX to Cion. In general, just two words, easy to use! Its smooth coding experience, especially auto-completion, is the consistent advantage of the Jet family. If you have used the completion of Jet’s family, believe me, you will not be able to go back.

Isn't vscode fragrant? fragrant! But "vscode is really fragrant, as long as you don't use it to write C/C++"

The following tutorial is extremely simple. In order to let everyone understand each step, pictures are prepared. Although the tutorial feels long, most of them are pictures.

In order to ensure compatibility with different versions of Clion, the article is long. It is strongly recommended to look at the catalog first when reading this tutorial, and then decide which chapter to read

CLion new version setting method

Tutorial platform introduction (new version):

  • CLion 2022.3.1 and opened the new UI
  • ESP-IDF 5.0
  • MinGw 11.20 x64 from Qt6.4.0(Option)

1. Install ESP-IDF 5.0

Download link https://dl.espressif.com/dl/esp-idf/ online version Offline version can be selected according to network conditions, here I personally choose the online version

1.1 App fixes

If a fix needs to be applied, click Fix

image-20230218102414855

1.2 Select the path

For easy search, the tools and IDF are stored together here

image-20230218102732371

image-20230218102748195

I personally don’t need these four, it takes up more space, and it is not automatically deleted when uninstalling, obsessive-compulsive disorder,,

image-20230218102907319

After the configuration is complete, wait for the download and installation

image-20230218102944669

2. Configure CLion

2.1 Configure environment variables

Modify the automatic configuration fileidf_cmd_init.bat

image-20230218112059549

edit, first line added

:: set IDF_PATH
set IDF_PATH=D:\ESP-IDF\IDF_5

image-20230218114652312

Open an empty project and close the automatically pop-up project configuration guidance

image-20230218112440975

2.2 Configure Toolchain

Open the settings and create a new toolchain

image-20230218112601652

Select the file you just edited

Note that the mingw version of IDF5.0 should be greater than 10.0, here I have Qt 11.20, so use Qt directly

The bundled that comes with Clion is 8.0, if necessary, you can click Download next to download the new version

image-20230218112652847

2.3 Modify CMake

Select the toolchain you just configured

image-20230218113115121

Set your own MCU model and upload baud rate

image-20230218115602040

Click "OK" to automatically configure CMake. If there is no automatic configuration, choose to reset CMake.

image-20230218115047457

No error is normal

image-20230218115106519

2.4 Test compile and upload

Set to flash, connect ESP32S3, burn test

image-20230218114955444

Test upload is normal

image-20230218120002210

3. Configure menuconfig

Just create a new Shell Script, add the following content in Script text, and modify the path to your own

D:\ESP-IDF\IDF_5\export.ps1; idf.py menuconfig

image-20230218161053841

After confirmation, it can be run, and the up, down, left, and right keys can be used to switch the menu

image-20230218131614012

4. Reference

Build ESP32-C3 development environment based on CLion and ESF-IDF (on)_哔哩哔哩_bilibili

CLion old version setting method

1. ESP-IDF development environment preparation

There are two ways to prepare the development environment:

  1. Directly use the vscode plug-in ESP-IDF to download and install, then go to the installation directory of esp-idf and execute install.ps1
  2. Use the official installation tool to install, to prevent the content from being too long, I won’t go into details here

2. Environment variable configuration (choose one from three)

The screenshots in the article do not match the theme, because the article part is updated later, and Clion ushered in a theme update, which does not affect reading.

2.1 Global environment configuration + environment configuration in CmakeLists.txt

The configuration of this has already been written in great detail, and the blog is directly posted here, which is very well written!

ESP-IDF + Clion development environment construction for ESP32 (1) - Windows version

Here, if I follow this configuration, there is no way to use menucofig and flash, so I supplement and partially modify it. The second method is to combine the method in this article and my own supplementary method to realize flash and "Pseudo" menuconfig. Why is it "pseudo", look down and talk slowly

2.2 Clion internal environment variable configuration + global variable environment configuration (personal recommendation)

We mentioned the first method. I have supplemented and modified the above method. Personally, I feel that there are quite a lot of modifications. I am too lazy to read the above and just follow this, but if you want to use ESP-IDF in other IDEs Be sure to check out that blog above, it’s great!

By analogy, other IDEs can also do this directly if they support the direct configuration of environment variables inside the software.

2.2.1 System environment variable configuration:

Here, add a column in the system variable IDF_PATHand fill in your installation path when installing ESP-IDF. (Here is the environment variable configuration of the windows system, not the interface of Clion)

2.2.2 Create a project

  1. Open Powershell, and then use cdthe command to go to the path shown IDF_PATHin the figure above and execute:
.\export.ps1

If your environment is Powershell, you must execute export.ps1 and cannot execute .bat, otherwise there will be situations where PATH cannot be written

A statement similar to the following indicates success

  1. Then cdgo to your own project directory (choose whatever you want), execute idf.py create-project 你的工程名, for example, mine is
idf.py create-project TestenvByTxwh

2.2.3 Configure your project with CLion

Open the project you just created, if the default pops up.

The expected error is reported, indicating that the path corresponding to python has not been found.

Go to the PowerShell window where the project was created just now (it must be in this window, because only the environment variables of this window are expanded, because it was executed before export.ps1)

$env:PATH

image-20230115160033946

We copy all the PATH, then find the settings that enter CLion, set the Environment, and then write the copied path to Path (in the user environment variable), and click OK after inputting

Create a new variable called Path, and fill in the one you just copied

image-20230115160240958

After confirming, open it again, and you will find that Clion has been automatically integrated.

image-20230115160503470

After clicking Apply, CLion will automatically perform the refactoring of CMake, and there is no problem if such a description appears.

Let's click the green arrow to compile, it looks fine

There is no problem with the header file reference and completion

2.2.4 Download configuration

Directly click the upper right corner to switch Application

and click the green triangle button to execute, and the following window will pop up


Choose your own project and apply. After running, if there are multiple COM ports, they will be traversed automatically, and they will be flashed if they meet the conditions.

Here we are required to specify the port and upload baud rate.

Open the environment configuration page of Clion, just add the corresponding environment variables just like the page above adding PATH

This time, there will be no prompt and I will directly connect to the COM port I set up. In the future, it is recommended to run the flash directly. Before the flash runs, you can see that it will compile again.

2.2.5 menuconfig configuration

I just selected the flash interface and there is a menuConfig option, but because CLion cannot be redirected, it cannot be executed

So here I used another method myself to solve this problem.
chooseEdit configuration

Then add it Shell Script, and then configure it.
Add the following code in the fourth one:

.$env:IDF_PATH\export.ps1; idf.py menuconfig


Here the ESC and CLion shortcut keys conflict, save the settings directly or Q to exit

Delete some personal unnecessary configuration

2.3 Complete environment variable configuration inside Clion

This method has to be configured once every time a new project is created, but the same file modification of ESP-IDF itself is also the least

This is not much different from [Clion internal environment variable configuration + global variable environment configuration (personal recommendation)](#2.Clion internal environment variable configuration + global variable environment configuration (personal recommendation)), nothing more than putting the system environment in IDF_PATHCLion Configure it inside, so that the system variables do not need to be configured

The other steps are exactly the same as the second one, then you can start to enjoy!

3. Reference

ESP-IDF + Clion development environment for ESP32 (1) - Windows version_Augtons Zheng(MCU) Blog-CSDN Blog_clion esp32

Guess you like

Origin blog.csdn.net/qq_38844263/article/details/123989779