-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: guide for vscode esp-target setup
- Loading branch information
Showing
6 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: Chen Ji Chang | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: Igor Udot | ||
--- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
--- | ||
title: "ESP-IDF VSCode Setup Guide for Esp Target Development" | ||
date: 2025-01-21T16:07:09+08:00 | ||
showAuthor: true | ||
featureAsset: "" | ||
tags: ["ESP-IDF extension", "VSCode", "Visual Studio Code"] | ||
authors: | ||
- "igor-udot" | ||
- "chen-ji-chang" | ||
- "brian-ignacio" | ||
--- | ||
|
||
## Overview | ||
This guide helps you configure VSCode's C/C++ extension for ESP32xx development, addressing common issues like incorrect syntax highlighting, header file navigation, and false error indicators. | ||
|
||
## Common Issues | ||
- Incorrect syntax highlighting for code within preprocessor macros | ||
- Incorrect header file resolution (e.g., wrong ll.h file being referenced) | ||
- False positive error indicators in source files | ||
- Navigation issues between different ESP32xx chip variants | ||
|
||
## Prerequisites | ||
- VSCode with C/C++ extension installed | ||
- ESP-IDF toolchain installed | ||
- Basic understanding of ESP32 development environment | ||
|
||
## Configuration Steps | ||
|
||
### 1. Basic Setup | ||
1. Open your ESP-IDF project in VSCode | ||
2. Create or modify `.vscode/c_cpp_properties.json` | ||
3. Configure alias to fix build directory using `alias idf.b="idf.py -B ~/esp/build"` | ||
4. Run `idf.b build` at least once to generate necessary files | ||
|
||
### Why Fixed Build Directory? | ||
Using a fixed build directory (ex: `~/esp/build`) provides several benefits: | ||
- Prevents need to update path in `c_cpp_properties.json` for each project | ||
- Makes switching between projects cleaner with centralized build location | ||
- Simplifies configuration for multiple ESP32 variants | ||
|
||
### 2. Configuration File Structure | ||
Create separate configurations for each ESP32xx variant in `c_cpp_properties.json`: | ||
|
||
**Build-Related Paths** | ||
|
||
Two important files are generated during build: `compile_commands.json` and `sdkconfig.h`. | ||
|
||
These files are why we need to run `idf.b build` before VSCode can properly resolve includes and macros. | ||
|
||
**Key Configuration Paths** | ||
```json | ||
|
||
{ | ||
"configurations": [ | ||
{ | ||
// Compiler path: Path to your ESP-IDF GCC compiler for specific chip | ||
"compilerPath": "${env:HOME}/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc", | ||
|
||
// Build output: Contains compilation file with include paths and flags | ||
"compileCommands": "${env:HOME}/esp/build/compile_commands.json", | ||
|
||
// Project config: Generated header with chip-specific settings | ||
"forcedInclude": [ | ||
"${env:HOME}/esp/build/config/sdkconfig.h" | ||
] | ||
|
||
} | ||
] | ||
} | ||
|
||
``` | ||
|
||
**Complete Configuration Example** | ||
|
||
```json | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "ESP32", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17", | ||
"compilerPath": "${env:HOME}/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc", | ||
"compileCommands": "${env:HOME}/esp/build/compile_commands.json", | ||
"forcedInclude": [ | ||
"${env:HOME}/esp/build/config/sdkconfig.h" | ||
], | ||
"configurationProvider": "ms-vscode.cmake-tools", | ||
"includePath": [ | ||
"${workspaceFolder}/**" | ||
] | ||
} | ||
// Additional configurations for S2, S3, and RISC-V variants... | ||
], | ||
"version": 4 | ||
} | ||
``` | ||
|
||
### 3. Chip-Specific Configurations | ||
Four main configurations are needed: | ||
1. ESP32 | ||
2. ESP32-S2 | ||
3. ESP32-S3 | ||
4. ESP32 RISC-V series | ||
|
||
Each configuration differs primarily in the `compilerPath` setting. | ||
|
||
## Best Practices | ||
|
||
### Setup Build Directory Alias | ||
|
||
```bash | ||
# Add alias to your shell configuration | ||
alias idf.b="idf.py -B ~/esp/build" | ||
# Now you can use: | ||
idf.b build # Builds project | ||
idf.b fullclean # Cleans build directory | ||
``` | ||
|
||
### Switching Between Configurations | ||
1. Press F1 or Ctrl+Shift+P | ||
2. Search for "C/C++: Select a Configuration" | ||
3. Choose the appropriate chip variant | ||
|
||
### Toolchain Management | ||
```bash | ||
# Script to find latest toolchain | ||
LATEST_XTENSA_DIR=$(ls -d ~/.espressif/tools/xtensa-esp-elf/esp-*/ | sort | tail -n 1) | ||
LATEST_RISCV_DIR=$(ls -d ~/.espressif/tools/riscv32-esp-elf/esp-*/ | sort | tail -n 1) | ||
``` | ||
|
||
### Configuration Generator Script | ||
```bash | ||
# Find latest toolchain directories | ||
LATEST_XTENSA_DIR=$(ls -d ~/.espressif/tools/xtensa-esp-elf/esp-*/ | sort | tail -n 1) | ||
LATEST_RISCV_DIR=$(ls -d ~/.espressif/tools/riscv32-esp-elf/esp-*/ | sort | tail -n 1) | ||
|
||
# Function to echo a configuration block | ||
echo_config() { | ||
local name=$1 | ||
local compiler_path=$2 | ||
|
||
cat << EOF | ||
--------------------------- | ||
Configuration for $name | ||
--------------------------- | ||
{ | ||
"name": "$name", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17", | ||
"compilerPath": "$compiler_path", | ||
"compileCommands": "$HOME/esp/build/compile_commands.json", | ||
"forcedInclude": [ | ||
"$HOME/esp/build/config/sdkconfig.h" | ||
], | ||
"configurationProvider": "ms-vscode.cmake-tools", | ||
"includePath": [ | ||
"\${workspaceFolder}/**" | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
# Echo ESP32 configuration | ||
echo_config "ESP32" "${LATEST_XTENSA_DIR}xtensa-esp-elf/bin/xtensa-esp32-elf-gcc" | ||
# Echo ESP32-S2 configuration | ||
echo_config "ESP32-S2" "${LATEST_XTENSA_DIR}xtensa-esp-elf/bin/xtensa-esp32s2-elf-gcc" | ||
# Echo ESP32-S3 configuration | ||
echo_config "ESP32-S3" "${LATEST_XTENSA_DIR}xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc" | ||
# Echo ESP32-RISC-V configuration | ||
echo_config "ESP32-RISC-V" "${LATEST_RISCV_DIR}riscv32-esp-elf/bin/riscv32-esp-elf-gcc" | ||
|
||
``` | ||
|
||
**Note**: When switching projects or target chips, always run `idf.b fullclean` first to avoid compilation issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Chen Ji Chang", | ||
"bio": "", | ||
"image": "https://avatars.githubusercontent.com/u/25845066" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "Igor Udot", | ||
"bio": "", | ||
"image": "https://avatars.githubusercontent.com/u/47724762", | ||
"social": [ | ||
{ "github": "https://github.com/horw" } | ||
] | ||
|
||
} |