VSCode with ESP32 Official Development Environment
Installation
Install the latest version of VSCode Before you install IDF extension, you should install few dependencies required in your system.
Open Extensions tab on the left side of VSCode, enter ESP-IDF to search Espressif IDF extension and install it.https://gyazo.com/b738933fcec47f2406b93ed8419799c8
After the installation of IDF extension, press F1 and type ESP-IDF: Configure ESP-IDF extension to start configure session.
In this tutorial, we choose Express mode to configure our development environment.https://gyazo.com/b79d996e019d55070be1d2d904540313https://gyazo.com/464b1cb06b19b63134112c6b6e405dc5
Press Install button will start configuration session, and the installation session will take a while to finish all procedures which depends on your network condition.
After the configuration finished, now we can open a new project folder to start development.
Coding - Hello World
Press F1 and type ESP-IDF: Show Examples Projects to create a project from examples.
Follow default settings and press Create project using example hello_world button to create a hello world project.
In this tutorial, we use ex5-test as our project name.
Configure the .vscode/c_cpp_properties.json as you need. Default configuration should work in this tutorial.
Do your code.
./main/hello_world_main.c is the c file including main entry.
Building and Flashing - Hello World
Press F1 to set flash port to the ESP32 board.
Be sure the port is the one connects to ESP32 board.
Or press the button in the task bar, as shown in the figure, could make the same setting.https://gyazo.com/c449ec185bf5e0d352719036294c1b9f
Press F1 and type ESP-IDF: Set Espressif device target to choose ESP32 in this case.
Or press the button in the task bar, as shown in the figure, could make the same setting.https://gyazo.com/d5491bccc152a0e28a829f377a853f45
Press F1 and type ESP-IDF: Build your project to build the example project.
Or press the build button in the task bar.
Normally, after compling and linking, your project will be built to a binary file. In case of FAILED: esp-idf/mbedtls/x509_crt_bundle \driver\libdriver.a, you should modify ESP-IDF SDK configuration to avoid this error.
F1 + type ESP-IDF: SDK Configuration Editor to open configuration editor. Or press the gear button in the task bar.https://gyazo.com/89e807e47a28e0d78cf1e24b3298e4ec
Find section Certificate Bundle, then change the option Default certificate bundle options to Use only the most common certificates from the default bundle and save. This will fix the build error.
F1 + type ESP-IDF: Select Flash Method and Flash to select UART mode to flash your binary file to ESP32.
Or the flash button in the task bar.
Monitoring - Hello World
F1 + type ESP-IDF: Monitor your device, then you will see the monitoring message from your ESP32 device.
Or the monitor button in the task bar.
When you see the output in the VSCode terminal like
Hello world!
This is esp32 chip with 2 CPU core(s), WiFi/BT/BLE, silicon revision 1, 4MB external flash
Minimum free heap size: 291376 bytes
Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
your program is running normally.
(Optional) Debugging - Hello World
F1 + type ESP-IDF: Select OpenOCD Board Configuration to select debugger configuration file for our device.
In this case, we choose the Custom Board.
https://gyazo.com/abfbbdf5fee11fb47b044ac15fdaf588
Open Run and Debug tab on the left, and you can click Launch button to start your debug session.
Insert a breakpoint at any line you want, then the program will stop at the line you insert the breakpoint for debugging.https://gyazo.com/a89561246745065a5c893bc6ca7e5f59
Notes
For details, you could refer the official manual about this VSCode extension to get advanced settings. This tutorial is for Windows user only.