StuckInLoop / VSC-Guide-for-esp32

This is a guide showing how to setup esp32 freeRTOS project on Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting up Visual Studio Code for ESP32 IDF (FreeRTOS)

Logo Logo

ESP32 IoT IDF

Xtensa IoT framework.

Steps

Download and install VSC

Below link will point to the latest version of the Microsoft code editor which is free and open source.
Go ahead and download the latest release.

Visual Studio Code

Install VSC extensions

After the installation open editor and go to 'Extensions' section to browse all available vsc extensions.
You need the following:

  • C++
  • Native Debug
  • Code Outline or AL Outline (to display and navigate properties)

Setup toolchain

Next you need tools for compilation and linking your projects Go to below link and follow instructions https://docs.espressif.com/projects/esp-idf/en/feature-cmake/get-started/index.html#setup-toolchain

You need to download all-in-one esp-idf tools installer https://dl.espressif.com/dl/esp-idf-tools-setup-1.1.exe and get the latest ESP-IDF framework

How to get ESP-IDF

Setup and verify environment variables

Make sure all path and idf variables are present and pointing to right locations. IDF_PATH is cruicial. You can use run-command way to set them up with setx IDF_PATH "...your path to esp-idf folder"

Example setup:

Note: If you want to quickly install whole environment with esp-idf framework - I created a batch file that will pull esp-idf from github repository, download it to user profile location (C:\Users\NAME\ESP32) and set the IDF_PATH automatically.
IMPORTANT: Please run this file as administrator!!
esp32setenv.bat

Make sure you install Git for Windows
Git Client download page

Create project

To create project that can properly compile you need the following:

.vscode folder must be present in the root project directory

.vscode folder must have the following files:

to have key shortcuts you need to modify keybindings.json file

keybindings.json is located in C:\Users....your profile name.... \AppData\Roaming\Code\User This file will allow to run compilation etc with just pressing keyshortcut

alternatively and what I recommend - use the command line from terminal to compile,monitor and run your app

  • idf.py -p COM3 flash -- wil compile and flash the board on port COM3
  • idf.py -p COM3 monitor -- will display live serial monitor in console

if you want to flash and immefiately monitor use

  • idf.py -p COM3 flash monitor

build will build project with changes
fullclean will erase old files and refresh the whole build for new compilation

Typical project file structure:

Important note:

To open your project you must choose 'Open Folder' option

Configure ESP32

Before compiling your project run the command to set up all necessary settings that IDF will use for your ESP32 chip.
In Integrated Terminal window run idf.py menuconfig
If you are not in Powershell but in cmd.exe - you can run powershell idf.py menuconfig

Example:


Hit ESC until menuconfig asks about saving the configuration.
Confirm save.

CMake

To use CMake environment your project must have CMakeLists.txt (just like Make files) in project directory

It usually contains f.ex. below lines

set(MAIN_SRCS
    main/spi_master_example_main.c
    main/pretty_effect.c
    main/decode_image.c)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(spi_master)

You can change them to the project files you have. Follow the examples provided in examples folder together with idf framework that you downloaded There are CMakeList.txt files in different folders that will help you how to add directories and component references

I will post more later on CMake... ;)

About

This is a guide showing how to setup esp32 freeRTOS project on Windows


Languages

Language:Batchfile 100.0%