文章目录
首先参考这篇文章 ESP32开发环境搭建:Vscode+Platformio
1. 合宙版ESP32-C3简约版
1. 1 ESP32-C3 + PlatformIO
接着参考这篇文章进行工程配置【ESP32之旅】合宙ESP32-C3 使用PlatformIO编译和Debug调试
完整的配置文件platformio.ini如下:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:airm2m_core_esp32c3]
platform = espressif32
board = airm2m_core_esp32c3
framework = arduino
lib_deps =
madhephaestus/ESP32Servo@^3.0.6
build_flags = ;添加编译链接配置项,类似于Makefile中的-D flag 链接参数,会在编译时链接进代码中以开启对应功能宏
-D ARDUINO_USB_MODE=1 ;开启USB Slave 功能
-D ARDUINO_USB_CDC_ON_BOOT=1 ;开启CDC 下载功能宏
debug_tool = esp-builtin ;内置调试器 进行调试
upload_speed = 2000000 ;Jtag最大传输速度2MHz
board_build.flash_mode = dio ;flash 访问模式 DIO
debug_init_break = tbreak setup
;debug_init_break = tbreak loop
upload_protocol = esp-builtin
新建完项目后,在main.cpp文件中实现如下代码:
#include <Arduino.h>
// 引脚定义
#define LED1 12
#define LED2 13
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED1, 1);
digitalWrite(LED2, 0);
}
void loop() {
// LED指示灯
digitalWrite(LED1, !digitalRead(LED1));
digitalWrite(LED2, !digitalRead(LED2));
delay(1000);
}
构建:
烧录:
可以看到两个LED灯交替闪烁。
1.2 ESP32-C3 + ESP-IDF
首先设置环境变量:
接着新建项目blink:
然后是三个配置文件的修改:
c_cpp_properties,json:
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "${config:idf.toolsPathWin}\\tools\\riscv32-esp-elf\\esp-13.2.0_20230928\\riscv32-esp-elf\\bin\\riscv32-esp-elf-gcc.exe",
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
laun