Visual Studio Code Esp32



Today will be a continuation on the ESP32 Micropython installation, here we'll learn how to work in a code editor and upload your code more smoothly.Micropyt. Recommended way to install ESP-IDF Visual Studio Code Extension is by downloading it from VS Code Marketplace or following Quick Installation Guide. Supported Features ¶ Onboarding, will help you to quickly install ESP-IDF and its relevant toolchain with just few clicks. Click F1 to show Visual studio code actions, then type ESP-IDF to see possible actions. Command Description. Keyboard Shortcuts (Mac) Keyboard Shortcuts (Windows/ Linux) Add Arduino ESP32 as. Well, it looks like the time has finally come because last week at work we decided to look into the ESP32 for its Bluetooth capabilities in order to get some kind of wireless data acquisition for remote debugging going. So I ordered a couple of ESP32-PICO-D4 boards to play around. My first goal was to get Bluetooth Classic Pairing working.

Develop, build, flash, monitor, debug and more with Espressif chips using Espressif IoT Development Framework (ESP-IDF).

Quick links

Prerequisites

There are few dependencies required in your system and available in environment variable PATH before installing this extension:

LinuxMacOSWindows
Python 3.5+Python 3.5+Python 3.5+
GitGitGit
CMakeCMake
Ninja-buildNinja-build

All the other dependencies like ESP-IDF and ESP-IDF Tools can be installed using the ESP-IDF: Configure ESP-IDF extension setup wizard or following the steps in the setup documentation.

Please note that this extension only supports the release versions of ESP-IDF, you can still use the extension on master branch or some other branch, but certain feature might not properly work.

  • Install this extension in your Visual Studio Code.

  • Then

    • Either open Visual Studio Code and create a workspace folder.
    • Run code ${YOUR_PROJECT_DIR} from the command line.
  • Check you have installed the Prerequisites

  • Press F1 and type ESP-IDF: Configure ESP-IDF extension to open the extension configuration wizard. This will install ESP-IDF and tools and configure the extension.

  • Please take a look at SETUP for details about extension configuration.

  • Press F1 and type ESP-IDF: Create ESP-IDF project to generate a template ESP-IDF project.

  • Configure the .vscode/c_cpp_properties.json as explained in C/C++ Configuration.

    Note: If you want to get code navigation and ESP-IDF function references, the Microsoft C/C++ Extension can be used to resolve header/source links. By default, projects created with ESP-IDF: Create ESP-IDF project tries to resolve headers by manually recursing ESP-IDF directory sources with the Tag Parser engine. This can be optimized by building the project first and configure your project to use build/compile_commands.json as explained in C/C++ Configuration.

  • Do some coding!

  • Check you set the correct port of your device by pressing F1, typing ESP-IDF: Select port to use: and choosing the serial port your device is connected.

  • When you are ready, build your project. Then flash to your device by pressing F1 and typing ESP-IDF: Flash your device then selecting Flash allows you to flash the device.

  • You can later start a monitor by pressing F1 and typing ESP-IDF: Monitor your device which will log the activity in a Visual Studio Code terminal.

  • If you want to start a debug session, just press F5 (make sure you had at least build and flash once before so the debugger works correctly). To make sure you can debug your device, set the proper idf.openOcdConfigs settings in your settings.json or by pressing F1 and typing ESP-IDF: Device configuration.

Click F1 to show Visual studio code actions, then type ESP-IDF to see possible actions.

Command DescriptionKeyboard Shortcuts (Mac)Keyboard Shortcuts (Windows/ Linux)
Add Arduino ESP32 as ESP-IDF Component
Add Editor coverage
Add vscode configuration folder
Build, Flash and start a monitor on your device⌘ E DCtrl E D
Build your project⌘ E BCtrl E B
Configure ESP-IDF extension
Configure Paths
Create project from extension template⌘ E CCtrl E C
Create new ESP-IDF Component
Device configuration
Dispose current SDK Configuration editor server process
Doctor command
Flash your project⌘ E FCtrl E F
Full clean project⌘ E XCtrl E X
Get HTML Coverage Report for project
Install ESP-ADF
Install ESP-IDF Python Packages
Install ESP-MDF
Monitor your device⌘ E MCtrl E M
New Project⌘ E NCtrl E N
Open ESP-IDF Terminal⌘ E TCtrl E T
Open NVS Partition Editor
Pick a workspace folder
SDK Configuration editor⌘ E GCtrl E G
Search in documentation..⌘ E QCtrl E Q
Select port to use⌘ E PCtrl E P
Select OpenOCD Board Configuration
Set default sdkconfig file in project
Set Espressif device target
Show Examples Projects
Show ninja build summary
Size analysis of the binaries⌘ E SCtrl E S
Remove Editor coverage

The Add Arduino-ESP32 as ESP-IDF Component command will add Arduino-ESP32 as a ESP-IDF component in your current directory (${CURRENT_DIRECTORY}/components/arduino). You can also use the Create ESP-IDF project command with arduino-as-component template to create a new project directory that includes Arduino-esp32 as an ESP-IDF component.

NOTE Not all versions of ESP-IDF are supported. Make sure to check Arduino-ESP32 to see if your ESP-IDF version is compatible.

The Install ESP-ADF will clone ESP-ADF to a selected directory and set idf.espAdfPath (idf.espAdfPathWin in Windows) configuration setting.

The Install ESP-MDF will clone ESP-MDF to a selected directory and set idf.espMdfPath (idf.espMdfPathWin in Windows) configuration setting.

The Show Examples Projects command allows you create a new project using one of the examples in ESP-IDF, ESP-ADF or ESP-MDF directory if related configuration settings are set.

Commands for tasks.json and launch.json

We have implemented some utilities commands that can be used in tasks.json and launch.json like

as shown in the debugging documentation.

  • espIdf.getExtensionPath: Get the installed location absolute path.
  • espIdf.getOpenOcdScriptValue: Return the value of OPENOCD_SCRIPTS from idf.customExtraVars or from system OPENOCD_SCRIPTS environment variable.
  • espIdf.getOpenOcdConfig: Return the openOCD configuration files as string. Example '-f interface/ftdi/esp32_devkitj_v1.cfg' -f board/esp32-wrover.cfg.
  • espIdf.getProjectName: Return the project name from current workspace folder build/project_description.json.
  • espIdf.getXtensaGcc: Return the absolute path of the xtensa toolchain gcc for the ESP-IDF target given by idf.adapterTargetName configuration setting and idf.customExtraPaths.
  • espIdf.getXtensaGdb: Return the absolute path of the xtensa toolchain gdb for the ESP-IDF target given by idf.adapterTargetName configuration setting and idf.customExtraPaths.

Available Tasks in tasks.json

There is also some tasks defined in Tasks.json, which can be executed by running F1 and writing Tasks: Run task and selecting one ofthe following:

  1. Build - Build Project
  2. Set Target to esp32
  3. Set Target to esp32s2
  4. Clean - Clean the project
  5. Flash - Flash the device
  6. Monitor - Start a monitor terminal
  7. OpenOCD - Start the openOCD server
  8. BuildFlash - Execute a build followed by a flash command.

Note that for OpenOCD tasks you need to define OPENOCD_SCRIPTS in your system environment variables with openocd scripts folder path. Open cisco anyconnect windows 10.

Code of Conduct

This project and everyone participating in it is governed by the Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to vscode@espressif.com.

License

This extension is licensed under the Apache License 2.0. Please see the LICENSE file for additional copyright notices and terms.

This document provides a guide to installing OpenOCD for ESP32 and debugging using GDB. The document is structured as follows:

Introduction

Introduction to the purpose of this guide.

How it Works?

Visual Studio Code Esp32

Description how ESP32, JTAG interface, OpenOCD and GDB are interconnected and working together to enable debugging of ESP32.

Selecting JTAG Adapter

What are the criteria and options to select JTAG adapter hardware.

Setup of OpenOCD
Esp32

Procedure to install OpenOCD and verify that it is installed.

Configuring ESP32 Target

Configuration of OpenOCD software and set up JTAG adapter hardware that will make together a debugging target.

Visual Studio Code Esp32 Mac

Launching Debugger

Steps to start up a debug session with GDB from Eclipse and from Command Line.

Debugging Examples

If you are not familiar with GDB, check this section for debugging examples provided from Eclipse as well as from Command Line.

Building OpenOCD from Sources

Procedure to build OpenOCD from sources for Windows, Linux and MacOS operating systems.

Tips and Quirks

This section provides collection of tips and quirks related JTAG debugging of ESP32 with OpenOCD and GDB.

Introduction¶

The ESP32 has two powerful Xtensa cores, allowing for a great deal of variety of program architectures. The FreeRTOS OS that comes with ESP-IDF is capable of multi-core preemptive multithreading, allowing for an intuitive way of writing software.

The downside of the ease of programming is that debugging without the right tools is harder: figuring out a bug that is caused by two threads, running even simultaneously on two different CPU cores, can take a long time when all you have are printf statements. A better and in many cases quicker way to debug such problems is by using a debugger, connected to the processors over a debug port.

Espressif has ported OpenOCD to support the ESP32 processor and the multicore FreeRTOS, which will be the foundation of most ESP32 apps, and has written some tools to help with features OpenOCD does not support natively.

This document provides a guide to installing OpenOCD for ESP32 and debugging using GDB under Linux, Windows and MacOS. Except for OS specific installation procedures, the s/w user interface and use procedures are the same across all supported operating systems.

Note

Screenshots presented in this document have been made for Eclipse Neon 3 running on Ubuntu 16.04 LTS. There may be some small differences in what a particular user interface looks like, depending on whether you are using Windows, MacOS or Linux and / or a different release of Eclipse.

How it Works?¶

The key software and hardware to perform debugging of ESP32 with OpenOCD over JTAG (Joint Test Action Group) interface is presented below and includes xtensa-esp32-elf-gdb debugger, OpenOCD on chip debugger and JTAG adapter connected to ESP32 target.

Under “Application Loading and Monitoring” there is another software and hardware to compile, build and flash application to ESP32, as well as to provide means to monitor diagnostic messages from ESP32.

Debugging using JTAG and application loading / monitoring is integrated under the Eclipse environment, to provide quick and easy transition from writing, compiling and loading the code to debugging, back to writing the code, and so on. All the software is available for Windows, Linux and MacOS platforms.

If the ESP-WROVER-KIT is used, then connection from PC to ESP32 is done effectively with a single USB cable. This is made possible by the FT2232H chip, which provides two USB channels, one for JTAG and the one for UART connection.

Depending on user preferences, both debugger and idf.py build can be operated directly from terminal/command line, instead from Eclipse.

Selecting JTAG Adapter¶

The quickest and most convenient way to start with JTAG debugging is by using ESP-WROVER-KIT. Each version of this development board has JTAG interface already build in. No need for an external JTAG adapter and extra wiring / cable to connect JTAG to ESP32. ESP-WROVER-KIT is using FT2232H JTAG interface operating at 20 MHz clock speed, which is difficult to achieve with an external adapter.

If you decide to use separate JTAG adapter, look for one that is compatible with both the voltage levels on the ESP32 as well as with the OpenOCD software. The JTAG port on the ESP32 is an industry-standard JTAG port which lacks (and does not need) the TRST pin. The JTAG I/O pins all are powered from the VDD_3P3_RTC pin (which normally would be powered by a 3.3 V rail) so the JTAG adapter needs to be able to work with JTAG pins in that voltage range.

On the software side, OpenOCD supports a fair amount of JTAG adapters. See http://openocd.org/doc/html/Debug-Adapter-Hardware.html for an (unfortunately slightly incomplete) list of the adapters OpenOCD works with. This page lists SWD-compatible adapters as well; take note that the ESP32 does not support SWD. JTAG adapters that are hardcoded to a specific product line, e.g. ST-LINK debugging adapters for STM32 families, will not work.

The minimal signalling to get a working JTAG connection are TDI, TDO, TCK, TMS and GND. Some JTAG debuggers also need a connection from the ESP32 power line to a line called e.g. Vtar to set the working voltage. SRST can optionally be connected to the CH_PD of the ESP32, although for now, support in OpenOCD for that line is pretty minimal.

Setup of OpenOCD¶

If you have already set up ESP-IDF with CMake build system according to the Getting Started Guide, then OpenOCD is already installed. After setting up the environment in your terminal, you should be able to run OpenOCD. Check this by executing the following command:

The output should be as follows (although the version may be more recent than listed here):

Visual studio code for esp32Code

You may also verify that OpenOCD knows where its configuration scripts are located by printing the value of OPENOCD_SCRIPTS environment variable, by typing echo$OPENOCD_SCRIPTS (for Linux and macOS) or echo%OPENOCD_SCRIPTS% (for Windows). If a valid path is printed, then OpenOCD is set up correctly.

If any of these steps do not work, please go back to the setting up the tools section of the Getting Started Guide.

Note

It is also possible to build OpenOCD from source. Please refer to Building OpenOCD from Sources section for details.

Configuring ESP32 Target¶

Esp32

Once OpenOCD is installed, move to configuring ESP32 target (i.e ESP32 board with JTAG interface). 808s and heartbreak tracklist. You will do it in the following three steps:

  • Configure and connect JTAG interface

  • Run OpenOCD

  • Upload application for debugging

Configure and connect JTAG interface¶

This step depends on JTAG and ESP32 board you are using - see the two cases described below.

Run OpenOCD¶

Once target is configured and connected to computer, you are ready to launch OpenOCD.

I tend to use this all over my lips underneath Lady Danger, as it provides the perfect base colour and literally lasts for hours without needing any topping up. Seriously impressive! I really want to try a few more of MAC's pro longwear liners now, as I don't have too many lip liners and this one has become a fast favourite in my make up. Best lip liner for mac lady danger “Copy that, Lady Danger. Good work!” Russian Red, Ruby Woo and Lady Danger may sound like secret agent codenames, but they’re actually three of MAC’s most popular red lipsticks. If Russian Red’s too cool for you, but Ruby isn’t quite warm enough, give pinup worthy MAC Lady Danger a try ($14.50). More coral than red, it has a matte finish like both Ruby Woo. MAC Lady Danger Lipstick ($18.50 for 0.10 oz.) is a rich, orange-red with warm undertones and a semi-matte finish. It had nearly opaque pigmentation with a lightly creamy, slightly denser/thicker texture, though it didn't drag and didn't feel heavy on my lips.

Open a terminal and set it up for using the ESP-IDF as described in the setting up the environment section of the Getting Started Guide. Then run OpenOCD (this command works on Windows, Linux, and macOS):

Note

The files provided after -f above are specific for ESP-WROVER-KIT with ESP32-WROOM-32 module. You may need to provide different files depending on used hardware. For guidance see Configuration of OpenOCD for specific target.

You should now see similar output (this log is for ESP-WROVER-KIT with ESP32-WROOM-32 module):

  • If there is an error indicating permission problems, please see the “Permissions delegation” bit in the OpenOCD README file in ~/esp/openocd-esp32 directory.

  • In case there is an error finding configuration files, e.g. Can'tfindboard/esp32-wrover-kit-3.3v.cfg, check OPENOCD_SCRIPTS environment variable is set correctly. This variable is used by OpenOCD to look for the files specified after -f. See Setup of OpenOCD section for details. Also check if the file is indeed under provided path.

  • If you see JTAG errors (…all ones/…all zeroes) please check your connections, whether no other signals are connected to JTAG besides ESP32’s pins, and see if everything is powered on.

Upload application for debugging¶

Build and upload your application to ESP32 as usual, see Step 8. Build the Project.

Another option is to write application image to flash using OpenOCD via JTAG with commands like this:

OpenOCD flashing command program_esp has the following format:

program_esp<image_file><offset>[verify][reset][exit]

  • image_file - Path to program image file.

  • offset - Offset in flash bank to write image.

  • verify - Optional. Verify flash contents after writing.

  • reset - Optional. Reset target after programing.

  • exit - Optional. Finally exit OpenOCD.

You are now ready to start application debugging. Follow steps described in section below.

Launching Debugger¶

The toolchain for ESP32 features GNU Debugger, in short GDB. It is available with other toolchain programs under filename: xtensa-esp32-elf-gdb. GDB can be called and operated directly from command line in a terminal. Another option is to call it from within IDE (like Eclipse, Visual Studio Code, etc.) and operate indirectly with help of GUI instead of typing commands in a terminal.

Both options of using debugger are discussed under links below.

It is recommended to first check if debugger works from Command Line and then move to using Eclipse.

Debugging Examples¶

This section is intended for users not familiar with GDB. It presents example debugging session from Eclipse using simple application available under get-started/blink and covers the following debugging actions:

Similar debugging actions are provided using GDB from Command Line.

Before proceeding to examples, set up your ESP32 target and load it with get-started/blink.

Building OpenOCD from Sources¶

Please refer to separate documents listed below, that describe build process.

Visual Studio Code Esp32 Linux

The examples of invoking OpenOCD in this document assume using pre-built binary distribution described in section Setup of OpenOCD.

Platformio

To use binaries build locally from sources, change the path to OpenOCD executable to src/openocd and set the OPENOCD_SCRIPTS environment variable so that OpenOCD can find the configuration files. For Linux and macOS:

For Windows:

Example of invoking OpenOCD build locally from sources, for Linux and macOS:

and Windows:

Tips and Quirks¶

This section provides collection of links to all tips and quirks referred to from various parts of this guide.

Programming Esp32 With Visual Studio

  • Tips and Quirks

Visual Studio Code Platform Io

Related Documents¶