ESP32 Wsl2 环境搭建
1 wsl2功能开启
WSL搭建就略过了,命令 wsl -v确认是否是WSL2
2 安装usb支持工具
Releases · dorssel/usbipd-win

我们打开 PowerShell 终端,并使用数据线将 PC 机与开发板相连,然后在终端输入“usbipd list“

这里BUSID为1-1是我的设备,状态是 ”不共享“
共享开发板设备
* powershell这里要用超级管理员权限
usbipd bind -b 1-1

3 WSL(ubuntu)安装esp-idf
前置环境(ubuntu)
sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0.0
克隆ESP-IDF软件开发库
mkdir esp
cd esp
git clone https://gitee.com/EspressifSystems/esp-idf.git
# 克隆 ESP-IDF TOOLS 工具库
cd esp-idf
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
# 更新 ESP-IDF 子模块
./esp-gitee-tools/submodule-update.sh
# 设置国内镜像
export IDF_GITHUB_ASSETS="dl.espressif.cn/github_assets"
# 安装 ESP-IDF TOOLS 工具
./esp-gitee-tools/install.sh
打开.bashrc文件,在底部添加以下代码。 alias get_idf='. ~/esp/esp-idf/export.sh'
这个是环境变量的脚本。 根据提示执行添加环境的脚本
. /home/elihe999/esp/esp-idf/export.sh
vscode 远程wsl

搜索ESP-IDF

按下快捷键“F1”或“Ctrl + Shift + P”打开“显示所有命令”界面。然后,在搜索框中输入“Configure ESP-IDF”

。。。。等待安装。。。
安装完会打开设置页面

USE EXISTING SETUP -> Search ESP-IDF in system
点击安装

依然等待下载

安装完了
烧录一个样例
- vscode wsl打开一个路径,里面放idf样例代码
/02_key/components/BSP/KEY/key.h:26:10: fatal error: driver/gpio.h: No such file or directory
Can't proceed with flashing, since project elf file (02_key.elf) is missing from the build dir
说明没有添加相关依赖的库
解决:添加esp_driver_gpio
set(src_dirsLEDKEY)set(include_dirsLEDKEY)set(requiresdriveresp_driver_gpio)idf_component_register(SRC_DIRS ${src_dirs} INCLUDE_DIRS ${include_dirs} REQUIRES ${requires})component_compile_options(-ffast-math -O3 -Wno-error=format=-Wno-format)
点击烧录,No serial ports found. Connect a device, or use '-p PORT' option to set a specific port.
这里还没有配置串口到wsl2
install.sh esp32s3
usbipd unbind -b 1-1
usbipd bind -b 1-1
然后连接wsl
usbipd attach --wsl --busid 1-1
idf.py flash
Memory Type Usage Summary
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Memory Type/Section ┃ Used [bytes] ┃ Used [%] ┃ Remain [bytes] ┃ Total [bytes] ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ Flash Code │ 94014 │ │ │ │
│ .text │ 94014 │ │ │ │
│ DIRAM │ 48951 │ 14.32 │ 292809 │ 341760 │
│ .text │ 34971 │ 10.23 │ │ │
│ .data │ 11700 │ 3.42 │ │ │
│ .bss │ 2280 │ 0.67 │ │ │
│ Flash Data │ 40516 │ │ │ │
│ .rodata │ 40260 │ │ │ │
│ .appdesc │ 256 │ │ │ │
│ IRAM │ 16384 │ 100.0 │ 0 │ 16384 │
│ .text │ 15356 │ 93.73 │ │ │
│ .vectors │ 1028 │ 6.27 │ │ │
│ RTC SLOW │ 36 │ 0.44 │ 8156 │ 8192 │
│ .force_slow │ 36 │ 0.44 │ │ │
│ RTC FAST │ 24 │ 0.29 │ 8168 │ 8192 │
│ .rtc_reserved │ 24 │ 0.29 │ │ │
└─────────────────────┴──────────────┴──────────┴────────────────┴───────────────┘
Total image size: 197621 bytes (.bin may be padded larger)
Note: The reported total sizes may be smaller than those in the technical reference manual due to reserved memory and application configuration. The total flash size available for the application is not included by default, as it cannot be reliably determined due to the presence of other data like the bootloader, partition table, and application partition size.
vscode代码提示
在看.vscode文件夹的内容时,发现settings里面有个idf.espIdfPathWin,这个路径是固定的,但是我window里面没有,到git上再次下载espressif/esp-idf(不是克隆到wsl)然后放到对应目录则有代码相关设置了。
其他
MicroPython
git clone https://github.com/micropython/micropythoncd micropythonmake -C mpy-crosscd ports/unixmake submodulesmake DEBUG=1 -j4 CWARN="-Wno-error=unused-variable"
Reference
Linux 和 macOS 平台工具链的标准设置 - ESP32 - — ESP-IDF 编程指南 v5.5.1 文档
(78 封私信 / 58 条消息) esp32 VScode编译入坑的一些问题解决 - 知乎
