天天看點

esp32編譯環境配置

文章目錄

    • 1. 初步配置開發環境
    • 2.編譯時遇到問題
    • 3.分步配置編譯環境
    • 4.環境變量配置
    • 5.完成編譯(部分日志)
    • 6.開發闆燒錄
      • 6.1開發闆原生序列槽log
      • 6.2 燒錄開發闆固件

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

    esp32編譯環境配置
    下面是我的安裝日志,安裝完成後提示需要執行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 [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected]_64eb9ff-8.4.0 (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (already installed)
Skipping [email protected] (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' ([email protected]: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 '[email protected]: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 '[email protected]: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)安裝時已經安裝好了

    esp32編譯環境配置

4.環境變量配置

esp32編譯環境配置

bin path配置

esp32編譯環境配置

到了這裡我以為可以編譯了,結果在執行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問題
           
esp32編譯環境配置

一開始按着這個文檔嘗試解決,結果最後提示包丢失或損壞。沒轍

https://blog.csdn.net/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...