esp32编译环境配置

本文主要记录了在Windows平台进行ESP开发环境配置、编译及开发板烧录的过程。介绍了两种开发环境安装方式,编译时遇到子仓库未同步问题及解决办法,分步配置编译环境所需工具,环境变量配置时的错误及解决,还记录了编译日志和开发板烧录时的问题与解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 初步配置开发环境

Windows 平台工具链的标准设置
上面这个链接是官方详细配置说明,其实这里有2种安装方式,在安装前需要安装python命令(当时我安装的是python3.9),最好安装好git.exe命令,本人当时安装的cmder.exe终端工具,。

  • 1.安装方式1:
    下载exe安装器,这个需要很长时间
    https://dl.espressif.com/dl/esp-idf-tools-setup-2.3.exe
  • 2.安装方式2:
    通过esp_idf源码目录下的安装命令安装,在命令行下执行install.bat即可安装,如果之前有安装其它旧版本的编译工具,这里会进行更新(记住这里,可以通过install.bat进行更新工具)。默认安装在C:\Users\username\.espressif
    在这里插入图片描述
    下面是我的安装日志,安装完成后提示需要执行export.bat,linux是export.sh.执行这个命令,主要是把一些编译工具的环境变量配置到系统,方便我们在其他目录能够使用编译命令。
E:\board_project\esp32\esp-idf (master -> origin)
λ install.bat
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, xtensa-esp32s2-elf, xtensa-esp32s3-elf, riscv32-esp-elf, esp32ulp-elf, esp32s2ulp-elf, cmake, openocd-esp32, ninja, idf-exe, ccache, dfu-util
Skipping xtensa-esp32-elf@esp-2020r3-8.4.0 (already installed)
Skipping xtensa-esp32s2-elf@esp-2020r3-8.4.0 (already installed)
Skipping xtensa-esp32s3-elf@esp-2020r3-8.4.0 (already installed)
Skipping riscv32-esp-elf@1.24.0.123_64eb9ff-8.4.0 (already installed)
Skipping esp32ulp-elf@2.28.51-esp-20191205 (already installed)
Skipping esp32s2ulp-elf@2.28.51-esp-20191205 (already installed)
Skipping cmake@3.16.4 (already installed)
Skipping openocd-esp32@v0.10.0-esp32-20210401 (already installed)
Skipping ninja@1.10.2 (already installed)
Skipping idf-exe@1.0.1 (already installed)
Skipping ccache@3.7 (already installed)
Skipping dfu-util@0.9 (already installed)
Setting up Python environment
Python 3.9.5
pip 21.1.2 from D:\espressif\python_env\idf4.4_py3.9_env\lib\site-packages\pip (python 3.9)
Installing Python packages from E:\board_project\esp32\esp-idf\requirements.txt
Looking in indexes: https://pypi.org/simple, https://dl.espressif.com/pypi
Processing e:\board_project\esp32\esp-idf\tools\kconfig_new\esp-windows-curses
  DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
   pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
Requirement already satisfied: setuptools>=21 in d:\espressif\python_env\idf4.4_py3.9_env\lib\site-packages (from -r E:\board_project\esp32\esp-idf\requirements.txt (line 4)) (57.0.0)
Collecting click>=7.0
  Using cached click-8.0.1-py3-none-any.whl (97 kB)
Collecting pyserial>=3.3
  Using cached https://dl.espressif.com/pypi/pyserial/pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting future>=0.15.2
  Using cached https://dl.espressif.com/pypi/future/future-0.18.2.tar.gz (829 kB)
Collecting cryptography>=2.1.4
  Using cached cryptography-3.4.7-cp36-abi3-win_amd64.whl (1.6 MB)
Collecting pyparsing<2.4.0,>=2.0.3
  Using cached https://dl.espressif.com/pypi/pyparsing/pyparsing-2.3.1-py2.py3-none-any.whl (61 kB)
Collecting pyelftools>=0.22
  Using cached https://dl.espressif.com/pypi/pyelftools/pyelftools-0.27-py2.py3-none-any.whl (151 kB)
Collecting gdbgui==0.13.2.0
  Using cached https://dl.espressif.com/pypi/gdbgui/gdbgui-0.13.2.0-py3-none-any.whl (878 kB)
Collecting pygdbmi<=0.9.0.2
  Using cached https://dl.espressif.com/pypi/pygdbmi/pygdbmi-0.9.0.2-py3-none-any.whl (16 kB)
Collecting python-socketio<5
  Downloading python_socketio-4.6.1-py2.py3-none-any.whl (51 kB)
     |████████████████████████████████| 51 kB 393 kB/s
Collecting kconfiglib==13.7.1
  Downloading https://dl.espressif.com/pypi/kconfiglib/kconfiglib-13.7.1-py2.py3-none-any.whl (145 kB)
     |████████████████████████████████| 145 kB 930 kB/s
Collecting reedsolo<=1.5.4,>=1.5.3
  Downloading https://dl.espressif.com/pypi/reedsolo/reedsolo-1.5.4.tar.gz (271 kB)
     |████████████████████████████████| 271 kB 1.6 MB/s
Collecting bitstring>=3.1.6
  Downloading https://dl.espressif.com/pypi/bitstring/bitstring-3.1.7.tar.gz (195 kB)
     |████████████████████████████████| 195 kB 819 kB/s
Collecting ecdsa>=0.16.0
  Downloading ecdsa-0.17.0-py2.py3-none-any.whl (119 kB)
     |████████████████████████████████| 119 kB 364 kB/s
Collecting construct==2.10.54
  Downloading https://dl.espressif.com/pypi/construct/construct-2.10.54.tar.gz (55 kB)
     |████████████████████████████████| 55 kB 660 kB/s
Collecting windows-curses
  Downloading windows_curses-2.2.0-cp39-cp39-win_amd64.whl (88 kB)
     |████████████████████████████████| 88 kB 380 kB/s
Collecting Flask-Compress<2.0,>=1.4.0
  Downloading Flask_Compress-1.9.0-py3-none-any.whl (7.3 kB)
Collecting Flask-SocketIO<3.0,>=2.9
  Downloading Flask_SocketIO-2.9.6-py2.py3-none-any.whl (16 kB)
Collecting Flask<1.0,>=0.12.2
  Downloading https://dl.espressif.com/pypi/flask/Flask-0.12.5-py2.py3-none-any.whl (81 kB)
     |████████████████████████████████| 81 kB 742 kB/s
Collecting Pygments<3.0,>=2.2.0
  Downloading Pygments-2.9.0-py3-none-any.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 504 kB/s
Collecting gevent<2.0,>=1.2.2
  Downloading https://dl.espressif.com/pypi/gevent/gevent-1.5.0-cp39-cp39-win_amd64.whl (1.6 MB)
     |████████████████████████████████| 1.6 MB 726 kB/s
Collecting colorama
  Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting cffi>=1.12
  Downloading https://dl.espressif.com/pypi/cffi/cffi-1.14.5-cp39-cp39-win_amd64.whl (179 kB)
     |████████████████████████████████| 179 kB 819 kB/s
Collecting python-engineio<4,>=3.13.0
  Downloading python_engineio-3.14.2-py2.py3-none-any.whl (51 kB)
     |████████████████████████████████| 51 kB 990 kB/s
Collecting six>=1.9.0
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting pycparser
  Downloading https://dl.espressif.com/pypi/pycparser/pycparser-2.20-py2.py3-none-any.whl (112 kB)
     |████████████████████████████████| 112 kB 1.6 MB/s
Collecting itsdangerous>=0.21
  Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Werkzeug<1.0,>=0.7
  Downloading https://dl.espressif.com/pypi/werkzeug/Werkzeug-0.16.1-py2.py3-none-any.whl (327 kB)
     |████████████████████████████████| 327 kB 2.2 MB/s
Collecting Jinja2>=2.4
  Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 504 kB/s
Collecting brotli
  Downloading https://dl.espressif.com/pypi/brotli/Brotli-1.0.9-cp39-cp39-win_amd64.whl (383 kB)
     |████████████████████████████████| 383 kB 731 kB/s
Collecting greenlet>=0.4.14
  Downloading greenlet-1.1.0-cp39-cp39-win_amd64.whl (95 kB)
     |████████████████████████████████| 95 kB 364 kB/s
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.0.1-cp39-cp39-win_amd64.whl (14 kB)
Building wheels for collected packages: esp-windows-curses, construct, future, reedsolo, bitstring
  Building wheel for esp-windows-curses (setup.py) ... done
  Created wheel for esp-windows-curses: filename=esp_windows_curses-0.1-py3-none-any.whl size=1170 sha256=02b9327e722460a2b8acc0b5fac0ddb84c451704f88b3cc51c404662a3d659a7
  Stored in directory: c:\users\administrator\appdata\local\pip\cache\wheels\95\d0\1e\d956a637ce6258c8eabafbf76802ede6da6eecff7689ad9a76
  Building wheel for construct (setup.py) ... done
  Created wheel for construct: filename=construct-2.10.54-py3-none-any.whl size=57415 sha256=f7899a1fa5d866abb5f2639b5b0cacf530d2d2a1b18af75e8157a44f1c1da52d
  Stored in directory: c:\users\administrator\appdata\local\pip\cache\wheels\c2\97\ac\60f52abe77d72be6b51c19a67410e346410656f7a3be7facd4
  Building wheel for future (setup.py) ... done
  Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=31d36b38d9a9b686fcb8d3300af05165f3a6364b2c51ec55cb4643101bb619c1
  Stored in directory: c:\users\administrator\appdata\local\pip\cache\wheels\f0\ff\d2\7a9af47e9994accb0ae1b2365d30f811691be4a8e9010a7fdf
  Building wheel for reedsolo (setup.py) ... done
  Created wheel for reedsolo: filename=reedsolo-1.5.4-py3-none-any.whl size=28970 sha256=f6cc1e33e944f303628cc2e6e452d63b28781577d668960ff3c1318c61a2b650
  Stored in directory: c:\users\administrator\appdata\local\pip\cache\wheels\f7\1f\ed\764f0e7a774d1d580c3f5c865e78e2922d7f6d3924eef78b56
  Building wheel for bitstring (setup.py) ... done
  Created wheel for bitstring: filename=bitstring-3.1.7-py3-none-any.whl size=37961 sha256=9ae08c415974784e263246a364973932db9687651eb7cba6ef9b680203ca9479
  Stored in directory: c:\users\administrator\appdata\local\pip\cache\wheels\0e\7b\03\0db50e4a034a4fe8231e3a144402c7f4240631b13a3e733dd1
Successfully built esp-windows-curses construct future reedsolo bitstring
Installing collected packages: six, MarkupSafe, colorama, Werkzeug, python-engineio, pycparser, Jinja2, itsdangerous, click, python-socketio, greenlet, Flask, cffi, brotli, windows-curses, Pygments, pygdbmi, gevent, Flask-SocketIO, Flask-Compress, reedsolo, pyserial, pyparsing, pyelftools, kconfiglib, gdbgui, future, esp-windows-curses, ecdsa, cryptography, construct, bitstring
Successfully installed Flask-0.12.5 Flask-Compress-1.9.0 Flask-SocketIO-2.9.6 Jinja2-3.0.1 MarkupSafe-2.0.1 Pygments-2.9.0 Werkzeug-0.16.1 bitstring-3.1.7 brotli-1.0.9 cffi-1.14.5 click-8.0.1 colorama-0.4.4 construct-2.10.54 cryptography-3.4.7 ecdsa-0.17.0 esp-windows-curses-0.1 future-0.18.2 gdbgui-0.13.2.0 gevent-1.5.0 greenlet-1.1.0 itsdangerous-2.0.1 kconfiglib-13.7.1 pycparser-2.20 pyelftools-0.27 pygdbmi-0.9.0.2 pyparsing-2.3.1 pyserial-3.5 python-engineio-3.14.2 python-socketio-4.6.1 reedsolo-1.5.4 six-1.16.0 windows-curses-2.2.0
All done! You can now run:
   export.bat

下面是执行export.bat输出的日志,提示已经就绪了。

E:\board_project\esp32\esp-idf (master -> origin)
λ export.bat
Setting IDF_PATH: E:\board_project\esp32\esp-idf

Adding ESP-IDF tools to PATH...
    D:\espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin
    D:\espressif\tools\xtensa-esp32s2-elf\esp-2020r3-8.4.0\xtensa-esp32s2-elf\bin
    D:\espressif\tools\xtensa-esp32s3-elf\esp-2020r3-8.4.0\xtensa-esp32s3-elf\bin
    D:\espressif\tools\riscv32-esp-elf\1.24.0.123_64eb9ff-8.4.0\riscv32-esp-elf\bin
    D:\espressif\tools\esp32ulp-elf\2.28.51-esp-20191205\esp32ulp-elf-binutils\bin
    D:\espressif\tools\esp32s2ulp-elf\2.28.51-esp-20191205\esp32s2ulp-elf-binutils\bin
    D:\espressif\tools\cmake\3.16.4\bin
    D:\espressif\tools\openocd-esp32\v0.10.0-esp32-20210401\openocd-esp32\bin
    D:\espressif\tools\ninja\1.10.2\
    D:\espressif\tools\idf-exe\1.0.1\
    D:\espressif\tools\ccache\3.7\
    D:\espressif\tools\dfu-util\0.9\dfu-util-0.9-win64
    D:\espressif\python_env\idf4.4_py3.9_env\Scripts
    E:\board_project\esp32\esp-idf\tools

Checking if Python packages are up to date...
Python requirements from E:\board_project\esp32\esp-idf\requirements.txt are satisfied.

Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

2.编译时遇到问题

按着上面说的,我把example目录下的hello_world拷贝到外部esp目录进行编译,但是遇到一些子仓库没有同步下来,其实不清楚这里是不是非必须依赖(非必须的可以在makefile将其移除掉),此时需要下载包含子仓库的代码,下面有链接。

λ idf.py set-target esp32
Adding "set-target"'s dependency "fullclean" to list of commands with default set of options.
Executing action: fullclean
Build directory 'e:\board_project\esp32\esp-idf\esp\hello_world\build' not found. Nothing to clean.
Executing action: set-target
Set Target to: esp32, new sdkconfig created. Existing sdkconfig renamed to sdkconfig.old.
Running cmake in directory e:\board_project\esp32\esp-idf\esp\hello_world\build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 -DIDF_TARGET=esp32 -DCCACHE_ENABLE=1 e:\board_project\esp32\esp-idf\esp\hello_world"...
-- Found Git: D:/Program Files/cmder/vendor/git-for-windows/cmd/git.exe (found version "2.29.1.windows.1")
-- Initialising new submodule components/asio/asio...
Submodule 'components/asio/asio' (git@gitee.com:espressif/asio.git) registered for path 'components/asio/asio'
Cloning into 'E:/board_project/esp32/esp-idf/components/asio/asio'...
Access deined: Repository Not Found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@gitee.com:espressif/asio.git' into submodule path 'E:/board_project/esp32/esp-idf/components/asio/asio' failed
Failed to clone 'components/asio/asio'. Retry scheduled
Cloning into 'E:/board_project/esp32/esp-idf/components/asio/asio'...
Access deined: Repository Not Found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@gitee.com:espressif/asio.git' into submodule path 'E:/board_project/esp32/esp-idf/components/asio/asio' failed
Failed to clone 'components/asio/asio' a second time, aborting
CMake Error at E:/board_project/esp32/esp-idf/tools/cmake/git_submodules.cmake:48 (message):
  Git submodule init failed for components/asio/asio
Call Stack (most recent call first):
  E:/board_project/esp32/esp-idf/tools/cmake/build.cmake:77 (git_submodule_check)
  E:/board_project/esp32/esp-idf/tools/cmake/build.cmake:168 (__build_get_idf_git_revision)
  E:/board_project/esp32/esp-idf/tools/cmake/idf.cmake:50 (__build_init)
  E:/board_project/esp32/esp-idf/tools/cmake/project.cmake:7 (include)
  CMakeLists.txt:5 (include)

解决方案请参考(使用linux版本):
https://gitee.com/EspressifSystems/esp-gitee-tools/issues/I38ERF
上面问题的主要原因是部分仓库代码没有下载到本地,在国内访问github权限问题,所以esp_idf最好下载完整包
包含submodule的链接(当时参考的这个)。

3.分步配置编译环境

官方链接

  • 安装cmake: https://cmake.org/download/
  • 安装ninja:https://ninja-build.org/
    上面的2个工具在第一步用(https://dl.espressif.com/dl/esp-idf-tools-setup-2.3.exe)安装时已经安装好了
    在这里插入图片描述

4.环境变量配置

在这里插入图片描述
bin path配置
在这里插入图片描述
到了这里我以为可以编译了,结果在执行export.bat时报了下面这个错误,头大了,可以看到有些工具已经不支持了。重新执行install.bat升级下工具

RROR: tool openocd-esp32 has no installed versions. Please run ‘E:\board_project\esp32\esp-idf-v4.2.1\install.bat’ to install it.
ERROR: tool ninja has no installed versions. Please run ‘E:\board_project\esp32\esp-idf-v4.2.1\install.bat’ to install it.

全部日志:


E:\board_project\esp32\esp-idf-v4.2.1 (HEAD detached at 21ecef5)
λ export.bat
Setting IDF_PATH: E:\board_project\esp32\esp-idf-v4.2.1

Adding ESP-IDF tools to PATH...
ERROR: tool openocd-esp32 has no installed versions. Please run 'E:\board_project\esp32\esp-idf-v4.2.1\install.bat' to install it.
ERROR: tool ninja has no installed versions. Please run 'E:\board_project\esp32\esp-idf-v4.2.1\install.bat' to install it.
An unsupported version of tool ninja was found in PATH: 1.10.2.

E:\board_project\esp32\esp-idf-v4.2.1 (HEAD detached at 21ecef5)
λ install
install.bat        install.exe        install_tools.bat
E:\board_project\esp32\esp-idf-v4.2.1 (HEAD detached at 21ecef5)
λ install
install.bat        install.exe        install_tools.bat
E:\board_project\esp32\esp-idf-v4.2.1 (HEAD detached at 21ecef5)

重新执行export.bat

λ export.bat
Setting IDF_PATH: E:\board_project\esp32\esp-idf-v4.2.1

Adding ESP-IDF tools to PATH...
Not using an unsupported version of tool ninja found in PATH: 1.10.2.
    D:\espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin
    D:\espressif\tools\xtensa-esp32s2-elf\esp-2020r3-8.4.0\xtensa-esp32s2-elf\bin
    D:\espressif\tools\esp32ulp-elf\2.28.51-esp-20191205\esp32ulp-elf-binutils\bin
    D:\espressif\tools\esp32s2ulp-elf\2.28.51-esp-20191205\esp32s2ulp-elf-binutils\bin
    D:\espressif\tools\openocd-esp32\v0.10.0-esp32-20200709\openocd-esp32\bin
    D:\espressif\tools\ninja\1.10.0\
    D:\espressif\tools\idf-exe\1.0.1\
    D:\espressif\tools\ccache\3.7\
    D:\espressif\tools\dfu-util\0.9\dfu-util-0.9-win64
    D:\espressif\python_env\idf4.2_py3.9_env\Scripts
    E:\board_project\esp32\esp-idf-v4.2.1\tools

Checking if Python packages are up to date...
The following Python requirements are not satisfied:
click>=5.0
pyserial>=3.0
future>=0.15.2
cryptography>=2.1.4
pyparsing>=2.0.3,<2.4.0
pyelftools>=0.22
gdbgui==0.13.2.0
pygdbmi<=0.9.0.2
reedsolo>=1.5.3,<=1.5.4
bitstring>=3.1.6
ecdsa>=0.16.0
esp-windows-curses; sys_platform == 'win32'
To install the missing packages, please run "E:\board_project\esp32\esp-idf-v4.2.1\install.bat"
Diagnostic information:
    IDF_PYTHON_ENV_PATH: D:\espressif\python_env\idf4.2_py3.9_env
    Python interpreter used: D:\espressif\python_env\idf4.2_py3.9_env\Scripts\python.exe

重新执行install.bat报了如下错误

error: Microsoft Visual C++ 14.0 is required问题

在这里插入图片描述
一开始按着这个文档尝试解决,结果最后提示包丢失或损坏。没辙
https://blog.youkuaiyun.com/weixin_40547993/article/details/89399825

后来考虑到是缺少“Microsoft Visual C++ 14.0”,索性我就安装了一个visual studio community 2019 ,然后重新执行install.bat,后面就没有报错了。

5.完成编译(部分日志)

idf.py build

λ idf.py build
Executing action: all (aliases: build)
Running ninja in directory e:\board_project\esp32\esp\hello_world\build
Executing "ninja all"...
[0/1] Re-running CMake...
-- ccache will be used for faster recompilation
-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file E:/board_project/esp32/esp/hello_world/sdkconfig
-- App "hello-world" version: 1
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom/esp32/ld/esp32.rom.newlib-time.ld
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom/esp32/ld/esp32.rom.ld
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
-- Adding linker script E:/board_project/esp32/esp/hello_world/build/esp-idf/esp32/esp32_out.ld
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp32/ld/esp32.project.ld.in
-- Adding linker script E:/board_project/esp32/esp-idf-v4.2.1/components/esp32/ld/esp32.peripherals.ld
-- Components: app_trace app_update asio bootloader bootloader_support bt cbor coap console cxx driver efuse esp-tls esp32 esp_adc_cal esp_common esp_eth esp_event esp_gdbstub esp_hid esp_http_client esp_http_server esp_https_ota esp_https_server esp_ipc esp_local_ctrl esp_netif esp_ringbuf esp_rom esp_serial_slave_link esp_system esp_timer esp_websocket_client esp_wifi espcoredump esptool_py expat fatfs freemodbus freertos heap idf_test jsmn json libsodium log lwip main mbedtls mdns mqtt newlib nghttp nvs_flash openssl partition_table perfmon protobuf-c protocomm pthread sdmmc soc spi_flash spiffs tcp_transport tcpip_adapter tinyusb ulp unity vfs wear_levelling wifi_provisioning wpa_supplicant xtensa
-- Component paths: E:/board_project/esp32/esp-idf-v4.2.1/components/app_trace E:/board_project/esp32/esp-idf-v4.2.1/components/app_update E:/board_project/esp32/esp-idf-v4.2.1/components/asio E:/board_project/esp32/esp-idf-v4.2.1/components/bootloader E:/board_project/esp32/esp-idf-v4.2.1/components/bootloader_support E:/board_project/esp32/esp-idf-v4.2.1/components/bt E:/board_project/esp32/esp-idf-v4.2.1/components/cbor E:/board_project/esp32/esp-idf-v4.2.1/components/coap E:/board_project/esp32/esp-idf-v4.2.1/components/console E:/board_project/esp32/esp-idf-v4.2.1/components/cxx E:/board_project/esp32/esp-idf-v4.2.1/components/driver E:/board_project/esp32/esp-idf-v4.2.1/components/efuse E:/board_project/esp32/esp-idf-v4.2.1/components/esp-tls E:/board_project/esp32/esp-idf-v4.2.1/components/esp32 E:/board_project/esp32/esp-idf-v4.2.1/components/esp_adc_cal E:/board_project/esp32/esp-idf-v4.2.1/components/esp_common E:/board_project/esp32/esp-idf-v4.2.1/components/esp_eth E:/board_project/esp32/esp-idf-v4.2.1/components/esp_event E:/board_project/esp32/esp-idf-v4.2.1/components/esp_gdbstub E:/board_project/esp32/esp-idf-v4.2.1/components/esp_hid E:/board_project/esp32/esp-idf-v4.2.1/components/esp_http_client E:/board_project/esp32/esp-idf-v4.2.1/components/esp_http_server E:/board_project/esp32/esp-idf-v4.2.1/components/esp_https_ota E:/board_project/esp32/esp-idf-v4.2.1/components/esp_https_server E:/board_project/esp32/esp-idf-v4.2.1/components/esp_ipc E:/board_project/esp32/esp-idf-v4.2.1/components/esp_local_ctrl E:/board_project/esp32/esp-idf-v4.2.1/components/esp_netif E:/board_project/esp32/esp-idf-v4.2.1/components/esp_ringbuf E:/board_project/esp32/esp-idf-v4.2.1/components/esp_rom E:/board_project/esp32/esp-idf-v4.2.1/components/esp_serial_slave_link E:/board_project/esp32/esp-idf-v4.2.1/components/esp_system E:/board_project/esp32/esp-idf-v4.2.1/components/esp_timer E:/board_project/esp32/esp-idf-v4.2.1/components/esp_websocket_client E:/board_project/esp32/esp-idf-v4.2.1/components/esp_wifi E:/board_project/esp32/esp-idf-v4.2.1/components/espcoredump E:/board_project/esp32/esp-idf-v4.2.1/components/esptool_py E:/board_project/esp32/esp-idf-v4.2.1/components/expat E:/board_project/esp32/esp-idf-v4.2.1/components/fatfs E:/board_project/esp32/esp-idf-v4.2.1/components/freemodbus E:/board_project/esp32/esp-idf-v4.2.1/components/freertos E:/board_project/esp32/esp-idf-v4.2.1/components/heap E:/board_project/esp32/esp-idf-v4.2.1/components/idf_test E:/board_project/esp32/esp-idf-v4.2.1/components/jsmn E:/board_project/esp32/esp-idf-v4.2.1/components/json E:/board_project/esp32/esp-idf-v4.2.1/components/libsodium E:/board_project/esp32/esp-idf-v4.2.1/components/log E:/board_project/esp32/esp-idf-v4.2.1/components/lwip E:/board_project/esp32/esp/hello_world/main E:/board_project/esp32/esp-idf-v4.2.1/components/mbedtls E:/board_project/esp32/esp-idf-v4.2.1/components/mdns E:/board_project/esp32/esp-idf-v4.2.1/components/mqtt E:/board_project/esp32/esp-idf-v4.2.1/components/newlib E:/board_project/esp32/esp-idf-v4.2.1/components/nghttp E:/board_project/esp32/esp-idf-v4.2.1/components/nvs_flash E:/board_project/esp32/esp-idf-v4.2.1/components/openssl E:/board_project/esp32/esp-idf-v4.2.1/components/partition_table E:/board_project/esp32/esp-idf-v4.2.1/components/perfmon E:/board_project/esp32/esp-idf-v4.2.1/components/protobuf-c E:/board_project/esp32/esp-idf-v4.2.1/components/protocomm E:/board_project/esp32/esp-idf-v4.2.1/components/pthread E:/board_project/esp32/esp-idf-v4.2.1/components/sdmmc E:/board_project/esp32/esp-idf-v4.2.1/components/soc E:/board_project/esp32/esp-idf-v4.2.1/components/spi_flash E:/board_project/esp32/esp-idf-v4.2.1/components/spiffs E:/board_project/esp32/esp-idf-v4.2.1/components/tcp_transport E:/board_project/esp32/esp-idf-v4.2.1/components/tcpip_adapter E:/board_project/esp32/esp-idf-v4.2.1/components/tinyusb E:/board_project/esp32/esp-idf-v4.2.1/components/ulp E:/board_project/esp32/esp-idf-v4.2.1/components/unity E:/board_project/esp32/esp-idf-v4.2.1/components/vfs E:/board_project/esp32/esp-idf-v4.2.1/components/wear_levelling E:/board_project/esp32/esp-idf-v4.2.1/components/wifi_provisioning E:/board_project/esp32/esp-idf-v4.2.1/components/wpa_supplicant E:/board_project/esp32/esp-idf-v4.2.1/components/xtensa
-- Configuring done
-- Generating done
-- Build files have been written to: E:/board_project/esp32/esp/hello_world/build
[5/934] Generating ../../partition_table/partition-table.bin
Partition table binary generated. Contents:
*******************************************************************************
# ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs,data,nvs,0x9000,24K,
phy_init,data,phy,0xf000,4K,
factory,app,factory,0x10000,1M,

上面详细显示了编译的模块,已经链接过程。

6.开发板烧录

6.1开发板原生串口log

这个是开发板买回来后直接打印的日志,可以看到开发布的idf版本是v3.1,这里我使用的v4.2.1

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5656
load:0x40078000,len:0
ho 12 tail 0 room 4
load:0x40078000,len:13920
entry 0x40078fd8
[0;32mI (30) boot: ESP-IDF v3.1-dev-463-g77eae33a-dirty 2nd stage bootloader[0m
[0;32mI (30) boot: compile time 10:52:13[0m
[0;32mI (32) boot: Enabling RNG early entropy source...[0m
[0;32mI (37) boot: SPI Speed      : 40MHz[0m
[0;32mI (41) boot: SPI Mode       : DIO[0m
[0;32mI (45) boot: SPI Flash Size : 4MB[0m
[0;32mI (49) boot: Partition Table:[0m
[0;32mI (53) boot: ## Label            Usage          Type ST Offset   Length[0m
[0;32mI (60) boot:  0 nvs              WiFi data        01 02 00009000 00004000[0m
[0;32mI (68) boot:  1 otadata          OTA data         01 00 0000d000 00002000[0m
[0;32mI (75) boot:  2 phy_init         RF data          01 01 0000f000 00001000[0m
[0;32mI (83) boot:  3 factory          factory app      00 00 00010000 00100000[0m
[0;32mI (90) boot:  4 ota_0            OTA app          00 10 00110000 00100000[0m
[0;32mI (97) boot:  5 ota_1            OTA app          00 11 00210000 00100000[0m
[0;32mI (105) boot: End of partition table[0m
[0;32mI (109) boot: Defaulting to factory image[0m
[0;32mI (114) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x17178 ( 94584) map[0m
[0;32mI (156) esp_image: segment 1: paddr=0x000271a0 vaddr=0x3ffb0000 size=0x031d8 ( 12760) load[0m
[0;32mI (161) esp_image: segment 2: paddr=0x0002a380 vaddr=0x40080000 size=0x00400 (  1024) load[0m
[0;32mI (163) esp_image: segment 3: paddr=0x0002a788 vaddr=0x40080400 size=0x05888 ( 22664) load[0m
[0;32mI (181) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x6fcf0 (457968) map[0m
[0;32mI (340) esp_image: segment 5: paddr=0x0009fd10 vaddr=0x40085c88 size=0x053e0 ( 21472) load[0m
[0;32mI (349) esp_image: segment 6: paddr=0x000a50f8 vaddr=0x400c0000 size=0x00000 (     0) load[0m
[0;32mI (356) boot: Loaded app from partition at offset 0x10000[0m
[0;32mI (356) boot: Disabling RNG early entropy source...[0m
[0;32mI (361) cpu_start: Pro cpu up.[0m
[0;32mI (364) cpu_start: Starting app cpu, entry point is 0x4008122c[0m
[0;32mI (356) cpu_start: App cpu up.[0m
[0;32mI (375) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (382) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m
[0;32mI (388) heap_init: At 3FFB9980 len 00026680 (153 KiB): DRAM[0m
[0;32mI (394) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM[0m
[0;32mI (400) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (407) heap_init: At 4008B068 len 00014F98 (83 KiB): IRAM[0m
[0;32mI (413) cpu_start: Pro cpu start user code[0m
ets Jun  8 2016 00:22:57

6.2 烧录开发板固件

  • 问题日志
λ D:\espressif\python_env\idf4.2_py3.9_env\Scripts\python.exe ..\..\esp-idf-v4.2.1\components\esptool_py\esptool\esptool.py -p COM5 -b 115200 --before default_reset --after hard_reset --chip esp32  write_flash --fl ash_mode dio --flash_size detect --flash_freq 40m 0x1000 build\bootloader\bootloader.bin 0x8000 build\partition_table\partition-table.bin 0x10000 build\hello-world.bin
esptool.py v3.0
Serial port COM5
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0xFC)

上面提示连接失败,这里需要手动将GPIO0拉低进入boot模式,就可以下载了。

E:\board_project\esp32\esp\hello_world
λ D:\espressif\python_env\idf4.2_py3.9_env\Scripts\python.exe ..\..\esp-idf-v4.2.1\components\esptool_py\esptool\esptool.py -p COM5 -b 115200 --before default_reset --after hard_reset --chip esp32  write_flash --fl ash_mode dio --flash_size detect --flash_freq 40m 0x1000 build\bootloader\bootloader.bin 0x8000 build\partition_table\partition-table.bin 0x10000 build\hello-world.bin
esptool.py v3.0
Serial port COM5
Connecting........_
Chip is ESP32-D0WD (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 94:3c:c6:14:44:84
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Compressed 25072 bytes to 15276...
Wrote 25072 bytes (15276 compressed) at 0x00001000 in 1.4 seconds (effective 144.7 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 712.3 kbit/s)...
Hash of data verified.
Compressed 150848 bytes to 79350...
Wrote 150848 bytes (79350 compressed) at 0x00010000 in 7.2 seconds (effective 167.7 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

烧录v4.2的idf固件,可以看到已经打印出了Hello world!,日志中也显示这是一个V4.2的日志

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4
load:0x3fff0034,len:7184
ho 0 tail 12 room 4
load:0x40078000,len:13212
load:0x40080400,len:4568
entry 0x400806f4
[0;32mI (31) boot: ESP-IDF v4.2.1-dirty 2nd stage bootloader[0m
[0;32mI (31) boot: compile time 21:17:37[0m
[0;32mI (31) boot: chip revision: 1[0m
[0;32mI (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0[0m
[0;32mI (41) boot.esp32: SPI Speed      : 40MHz[0m
[0;32mI (46) boot.esp32: SPI Mode       : DIO[0m
[0;32mI (50) boot.esp32: SPI Flash Size : 4MB[0m
[0;32mI (55) boot: Enabling RNG early entropy source...[0m
[0;32mI (60) boot: Partition Table:[0m
[0;32mI (64) boot: ## Label            Usage          Type ST Offset   Length[0m
[0;32mI (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000[0m
[0;32mI (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000[0m
[0;32mI (86) boot:  2 factory          factory app      00 00 00010000 00100000[0m
[0;32mI (94) boot: End of partition table[0m
[0;32mI (98) boot_comm: chip revision: 1, min. application chip revision: 0[0m
[0;32mI (105) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05d08 ( 23816) map[0m
[0;32mI (123) esp_image: segment 1: paddr=0x00015d30 vaddr=0x3ffb0000 size=0x02088 (  8328) load[0m
[0;32mI (127) esp_image: segment 2: paddr=0x00017dc0 vaddr=0x40080000 size=0x00404 (  1028) load[0m
[0;32mI (132) esp_image: segment 3: paddr=0x000181cc vaddr=0x40080404 size=0x07e4c ( 32332) load[0m
[0;32mI (155) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x13004 ( 77828) map[0m
[0;32mI (185) esp_image: segment 5: paddr=0x0003302c vaddr=0x40088250 size=0x01ce4 (  7396) load[0m
[0;32mI (194) boot: Loaded app from partition at offset 0x10000[0m
[0;32mI (194) boot: Disabling RNG early entropy source...[0m
[0;32mI (197) cpu_start: Pro cpu up.[0m
[0;32mI (200) cpu_start: Application information:[0m
[0;32mI (205) cpu_start: Project name:     hello-world[0m
[0;32mI (210) cpu_start: App version:      1[0m
[0;32mI (215) cpu_start: Compile time:     Jun  2 2021 21:16:26[0m
[0;32mI (221) cpu_start: ELF file SHA256:  6581f62cd8ca8d27...[0m
[0;32mI (227) cpu_start: ESP-IDF:          v4.2.1-dirty[0m
[0;32mI (232) cpu_start: Starting app cpu, entry point is 0x400815e4[0m
[0;32mI (224) cpu_start: App cpu up.[0m
[0;32mI (243) heap_init: Initializing. RAM available for dynamic allocation:[0m
[0;32mI (250) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[0m
[0;32mI (256) heap_init: At 3FFB28C8 len 0002D738 (181 KiB): DRAM[0m
[0;32mI (262) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[0m
[0;32mI (268) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[0m
[0;32mI (275) heap_init: At 40089F34 len 000160CC (88 KiB): IRAM[0m
[0;32mI (281) cpu_start: Pro cpu start user code[0m
[0;32mI (299) spi_flash: detected chip: generic[0m
[0;32mI (300) spi_flash: flash io: dio[0m
[0;32mI (300) cpu_start: Starting scheduler on PRO CPU.[0m
[0;32mI (0) cpu_start: Starting scheduler on APP CPU.[0m
Hello world!
This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
Free heap: 299900
Restarting in 10 seconds...
<think>好的,我现在需要帮助用户解决关于ESP32编译环境配置的问题。首先,用户提到了几个引用,我需要仔细看看这些引用内容,确保回答准确。 根据引用[2],用户提到在Windows下使用Eclipse搭建环境,需要安装Python 3.8、Git、MSYS2环境和ESP-IDF工具链。这可能涉及到步骤的详细说明。引用[4]指向了乐鑫官方的文档,应该是最权威的指南,需要参考其中的步骤。另外,引用[3]提到了VSCode的配置,包括设置COM口、设备目标等,这可能也是用户关心的部分。 用户的问题是如何设置和选择ESP32编译环境。首先,我应该分步骤说明,可能包括环境准备、工具安装、配置步骤以及常见问题解决。比如,安装MSYS2、配置工具链、设置IDE(如Eclipse或VSCode)、编译和烧录步骤等。需要确保覆盖用户提到的不同方法,如Eclipse和VSCode,并指出官方文档的重要性。 另外,用户提供的引用中有提到错误处理,比如头文件无法跳转的问题,这可能涉及到路径配置或环境变量设置。在回答中需要提醒用户注意这些点,可能引用[1]中的问题,建议检查包含路径是否正确配置。 还要生成相关问题,可能包括环境配置中的常见错误、不同操作系统的配置差异、如何选择适合的IDE等。需要确保问题与用户需求相关,并且能够帮助他们进一步解决问题。 最后,要确保回答结构清晰,步骤详细,同时引用正确的来源,比如引用[2]和[4]中的安装步骤,引用[3]的VSCode配置,以及引用[1]的问题解决方法。可能还需要强调按照官方文档操作的重要性,避免配置错误。</think>### ESP32编译环境配置方法 ESP32编译环境配置主要依赖乐鑫官方提供的工具链和开发框架(ESP-IDF),以下是**Windows系统下的配置步骤**: --- #### **一、基础环境准备** 1. **安装必要软件** - **Python 3.8+**:用于ESP-IDF的脚本支持[^2]。 - **Git**:用于代码仓库管理[^2]。 - **MSYS2环境**:提供类Unix命令行工具链(如`make`、`gcc`)[^4]。 2. **下载工具链** 从乐鑫官网获取预编译的MSYS2环境包(如`esp32_win32_msys2_environment_and_toolchain-20181001`)并解压到无空格路径。 --- #### **二、配置ESP-IDF开发框架** 1. **获取ESP-IDF** 通过Git克隆官方仓库(建议选择稳定版本): ```bash git clone -b v4.4 --recursive https://github.com/espressif/esp-idf.git ``` 2. **设置环境变量** 在MSYS2终端中运行以下命令,将ESP-IDF路径添加到系统环境变量: ```bash export IDF_PATH=/path/to/esp-idf ``` --- #### **三、IDE集成配置** ##### **方法1:Eclipse配置** 1. **安装Eclipse C/C++插件** 在Eclipse中安装`CDT`插件以支持C/C++开发[^2]。 2. **配置项目路径** 在项目属性中设置`Include Paths`,确保头文件可正确跳转(避免引用错误[^1])。 ##### **方法2:VSCode配置** 1. **安装ESP-IDF插件** 在VSCode中搜索并安装乐鑫官方插件`Espressif IDF`。 2. **配置开发板参数** 连接ESP32开发板后,设置对应的`COM口`、`Device Target`和`Flash Size`[^3]。 3. **编译与烧录** 通过插件直接执行`Build Project`和`Flash`命令。 --- #### **四、验证配置** 1. **编译示例工程** 运行`idf.py build`命令,确认无报错。 2. **烧录程序** 使用`idf.py -p COMX flash`将程序写入开发板(`COMX`需替换为实际端口号)。 --- #### **常见问题解决** - **头文件无法跳转**:检查IDE的`browse.path`是否包含ESP-IDF路径[^1]。 - **工具链兼容性**:确保Python和ESP-IDF版本匹配(如Python 3.8对应ESP-IDF v3.3.1)。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值