Introduction
This article outlines steps to create new projects under the VS Code with ESP-IDF extension environment. Two approaches to create new project —
— From existing examples, and
— Use project templates
From examples
- In VSC, press F1 and access ESP-IDF: Show Examples Projects
- Click Create project using example xxxx
- Select a container directory where to copy the example project
- Select an Espressif MCU, access ESP-IDF: Set Espressif device target
- Configure the project, access ESP-IDF: SDK Configuration editor
- NOTE: The SDK Configuration editor is built from the project’s build/config/kconfig_menus.json which is generated by the build system from ESP-IDF and user defined components Kconfig files on the first run of SDK Configuration editor. This process takes a bit of time so we keep the process running in the background to speed things up. If you are making changes to any Kconfig file or you want to re-run the SDK Configuration editor from scratch, you need to dispose the current process with the ESP-IDF: Dispose current SDK Configuration editor server process and run the ESP-IDF: SDK Configuration editor again.
- Build project, access ESP-IDF: Build your project
- Select serial port, connect the development board to PC via the USB port, then access ESP-IDF: Select port to use
- to find the COM port number, open Device Manager -> Ports (COM & LPT) and observe the port com for the USB to UART device.
- Flash the project, access ESP-IDF: Flash your project
- Monitor project running, access ESP-IDF: Monitor your device
From template
In VSC, press F1 and access ESP-IDF: Create ESP-IDF project and select the template to be used, Then follow the above steps.
Rename Project
After cloning the project with the above methods, it may be necessary to rename the project.
- Delete the ‘build’ directory
- Under the root folder, rename the project name in CMAKEList.txt and Makefile.
- Under the main folder, rename main.c file if necessary.
- Change the directory name to the name of the project.
- Build the project again, access ESP-IDF: Build your project
Convert C Project to C++
- change /main/main.c to /main/main.cpp
- In /main/CMakeLists.txt, change the SRCS property to the new .cpp file name.
- In /main/main.cpp, add extern “C” in front of void app_main( ).
#include <iostream>
extern "C" void app_main() {
.....
}
- Open CMakeLists.txt and check its content with reference to the example below.
- Cmake minimum version is 3.8 in order to support C++ standard 17.
cmake_minimum_required(VERSION 3.8)
set(CMAKE_CXX_STANDARD 17)
set(EXTRA_COMPONENT_DIRS components)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(proj_name)
