eps32s2开发环境搭建

文档名称:esp32s2开发环境搭建.doc

文档版本:V1.0

创建时间:2020-10-31

最后修改:2020-10-31

esp-idf版本:release/v4.2

环境:ubuntu20.04 LTS-server

作者:zhouyun

联系方式:celticzy@163.com

官方参考文档:https://docs.espressif.com/projects/esp-idf/zh_CN/stable/index.html

一、下载工具链

git clone -b release/v4.2 --recursive https://github.com/espressif/esp-idf.git

选择4.2版本的原因是支持esp32s2。

另外,不要在windows下下载再传输至linux主机上,因为windows的换行符为\r\n,而linux为\n,在执行脚本的时候会报错,即使使用sed命令修改, windows下载的文件不具有执行属性,还得一个个去添加执行属性,挺麻烦的,所以建议从linux直接git下载

Git下载速度很慢,为了避免下载失败,可以多开几个终端同时下载,最后基本上总会有下载完整的,大约4个小时后,下载完成。如果需要release/v4.2版本esp-idf的百度网盘下载链接,请联系作者邮箱celticzy@163.com

二、安装工具链

进入ESP-IDF目录,直接执行intall.sh即可,日志如下

zhouyun@zhyubntserver:~/esp/esp-idf-4.2$ ls
CMakeLists.txt    README.md             add_path.sh  export.bat   install.bat   make
CONTRIBUTING.rst  README_CN.md          components   export.fish  install.fish  requirements.txt
Kconfig           SUPPORT_POLICY.md     docs         export.ps1   install.ps1   sdkconfig.rename
LICENSE           SUPPORT_POLICY_CN.md  examples     export.sh    install.sh    tools


zhouyun@zhyubntserver:~/esp/esp-idf-4.2$ ./install.sh
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, xtensa-esp32s2-elf, esp32ulp-elf, esp32s2ulp-elf, openocd-esp32
Installing xtensa-esp32-elf@esp-2020r3-8.4.0
Downloading xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz to /home/zhouyun/.espressif/dist/xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz.tmp
Done
Extracting /home/zhouyun/.espressif/dist/xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz to /home/zhouyun/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0
Installing xtensa-esp32s2-elf@esp-2020r3-8.4.0
Downloading xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz to /home/zhouyun/.espressif/dist/xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz.tmp
Done
Extracting /home/zhouyun/.espressif/dist/xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz to /home/zhouyun/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0
Skipping esp32ulp-elf@2.28.51-esp-20191205 (already installed)
Skipping esp32s2ulp-elf@2.28.51-esp-20191205 (already installed)
Installing openocd-esp32@v0.10.0-esp32-20200709
Downloading openocd-esp32-linux64-0.10.0-esp32-20200709.tar.gz to /home/zhouyun/.espressif/dist/openocd-esp32-linux64-0.10.0-esp32-20200709.tar.gz.tmp
Done
Extracting /home/zhouyun/.espressif/dist/openocd-esp32-linux64-0.10.0-esp32-20200709.tar.gz to /home/zhouyun/.espressif/tools/openocd-esp32/v0.10.0-esp32-20200709
Installing Python environment and packages
Creating a new Python environment in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env
created virtual environment CPython3.8.5.final.0-64 in 1755ms
  creator CPython3Posix(dest=/home/zhouyun/.espressif/python_env/idf4.2_py3.8_env, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/zhouyun/.local/share/virtualenv)
    added seed packages: pip==20.2.4, setuptools==50.3.2, wheel==0.35.1
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Installing Python packages from /home/zhouyun/esp/esp-idf-4.2/requirements.txt
Ignoring None: markers 'sys_platform == "win32"' don't match your environment
Requirement already satisfied: setuptools>=21 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 4)) (50.3.2)
Collecting click>=5.0
  Using cached click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting pyserial>=3.0
  Using cached pyserial-3.4-py2.py3-none-any.whl (193 kB)
Processing /home/zhouyun/.cache/pip/wheels/8e/70/28/3d6ccd6e315f65f245da085482a2e1c7d14b90b30f239e2cf4/future-0.18.2-py3-none-any.whl
Collecting cryptography>=2.1.4
  Using cached cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl (2.6 MB)
Collecting pyparsing<2.4.0,>=2.0.3
  Using cached pyparsing-2.3.1-py2.py3-none-any.whl (61 kB)
Collecting pyelftools>=0.22
  Using cached pyelftools-0.27-py2.py3-none-any.whl (151 kB)
Collecting gdbgui==0.13.2.0
  Downloading gdbgui-0.13.2.0-py3-none-any.whl (878 kB)
     |████████████████████████████████| 878 kB 12 kB/s
Collecting pygdbmi<=0.9.0.2
  Downloading pygdbmi-0.9.0.2-py3-none-any.whl (16 kB)
Collecting reedsolo==1.5.3
  Downloading reedsolo-1.5.3.tar.gz (271 kB)
     |████████████████████████████████| 271 kB 17 kB/s
Collecting bitstring>=3.1.6
  Downloading bitstring-3.1.7.tar.gz (195 kB)
     |████████████████████████████████| 195 kB 20 kB/s
Collecting six>=1.4.1
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting cffi!=1.11.3,>=1.8
  Using cached cffi-1.14.3-cp38-cp38-manylinux1_x86_64.whl (410 kB)
Collecting gevent<2.0,>=1.2.2
  Downloading gevent-1.5.0-cp38-cp38-manylinux2010_x86_64.whl (5.9 MB)
     |████████████████████████████████| 5.9 MB 14 kB/s
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask-compress/
Collecting Flask-Compress<2.0,>=1.4.0
  Downloading Flask-Compress-1.7.0.tar.gz (9.3 kB)
Collecting Flask-SocketIO<3.0,>=2.9
  Downloading Flask_SocketIO-2.9.6-py2.py3-none-any.whl (16 kB)
Collecting Pygments<3.0,>=2.2.0
  Downloading Pygments-2.7.2-py3-none-any.whl (948 kB)
     |████████████████████████████████| 948 kB 23 kB/s
Collecting Flask<1.0,>=0.12.2
  Downloading Flask-0.12.5-py2.py3-none-any.whl (81 kB)
     |████████████████████████████████| 81 kB 14 kB/s
Collecting pycparser
  Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting greenlet>=0.4.14; platform_python_implementation == "CPython"
  Downloading greenlet-0.4.17-cp38-cp38-manylinux1_x86_64.whl (48 kB)
     |████████████████████████████████| 48 kB 9.0 kB/s
Collecting brotli
  Downloading Brotli-1.0.9-cp38-cp38-manylinux1_x86_64.whl (357 kB)
     |████████████████████████████████| 357 kB 14 kB/s
Collecting python-socketio>=1.6.1
  Downloading python_socketio-4.6.0-py2.py3-none-any.whl (51 kB)
     |████████████████████████████████| 51 kB 13 kB/s
Collecting itsdangerous>=0.21
  Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting Werkzeug<1.0,>=0.7
  Downloading Werkzeug-0.16.1-py2.py3-none-any.whl (327 kB)
     |████████████████████████████████| 327 kB 8.8 kB/s
Collecting Jinja2>=2.4
  Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 25 kB/s
Collecting python-engineio>=3.13.0
  Downloading python_engineio-3.13.2-py2.py3-none-any.whl (50 kB)
     |████████████████████████████████| 50 kB 22 kB/s
Collecting MarkupSafe>=0.23
  Downloading MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl (32 kB)
Building wheels for collected packages: reedsolo, bitstring, Flask-Compress
  Building wheel for reedsolo (setup.py) ... done
  Created wheel for reedsolo: filename=reedsolo-1.5.3-py3-none-any.whl size=28907 sha256=c07771f77f7bfc396853974fcae222877a41348abcf4865e9b75a0f9f458a155
  Stored in directory: /home/zhouyun/.cache/pip/wheels/30/ec/0a/3e7bc9fcbb56fe85e157a0e235bbe90238c3f831d5631b0b09
  Building wheel for bitstring (setup.py) ... done
  Created wheel for bitstring: filename=bitstring-3.1.7-py3-none-any.whl size=37948 sha256=174eb400125a14b4f327e62a2bc8127478b5d68e955aae6002062d59630f7a2d
  Stored in directory: /home/zhouyun/.cache/pip/wheels/6c/2f/25/52effb6e8c69461de76989c5996e836583fa7bbbc7cd539af1
  Building wheel for Flask-Compress (setup.py) ... done
  Created wheel for Flask-Compress: filename=Flask_Compress-1.7.0-py3-none-any.whl size=6833 sha256=a6414d21e08594631cf2176d40f522b0f4b57da017e8c748624aa2578240a93d
  Stored in directory: /home/zhouyun/.cache/pip/wheels/60/70/c6/506dddfa28078faea4fed05e486defbaa433038f800440742f
Successfully built reedsolo bitstring Flask-Compress
Installing collected packages: click, pyserial, future, six, pycparser, cffi, cryptography, pyparsing, pyelftools, greenlet, gevent, itsdangerous, Werkzeug, MarkupSafe, Jinja2, Flask, brotli, Flask-Compress, python-engineio, python-socketio, Flask-SocketIO, Pygments, pygdbmi, gdbgui, reedsolo, bitstring
Successfully installed Flask-0.12.5 Flask-Compress-1.7.0 Flask-SocketIO-2.9.6 Jinja2-2.11.2 MarkupSafe-1.1.1 Pygments-2.7.2 Werkzeug-0.16.1 bitstring-3.1.7 brotli-1.0.9 cffi-1.14.3 click-7.1.2 cryptography-3.2.1 future-0.18.2 gdbgui-0.13.2.0 gevent-1.5.0 greenlet-0.4.17 itsdangerous-1.1.0 pycparser-2.20 pyelftools-0.27 pygdbmi-0.9.0.2 pyparsing-2.3.1 pyserial-3.4 python-engineio-3.13.2 python-socketio-4.6.0 reedsolo-1.5.3 six-1.15.0
All done! You can now run:

  . ./export.sh






zhouyun@zhyubntserver:~/esp/esp-idf-4.2$ ./install.sh
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, xtensa-esp32s2-elf, esp32ulp-elf, esp32s2ulp-elf, openocd-esp32
Skipping xtensa-esp32-elf@esp-2020r3-8.4.0 (already installed)
Skipping xtensa-esp32s2-elf@esp-2020r3-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 openocd-esp32@v0.10.0-esp32-20200709 (already installed)
Installing Python environment and packages
Installing Python packages from /home/zhouyun/esp/esp-idf-4.2/requirements.txt
Ignoring None: markers 'sys_platform == "win32"' don't match your environment
Requirement already satisfied: setuptools>=21 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 4)) (50.3.2)
Requirement already satisfied: click>=5.0 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 8)) (7.1.2)
Requirement already satisfied: pyserial>=3.0 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 9)) (3.4)
Requirement already satisfied: future>=0.15.2 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 10)) (0.18.2)
Requirement already satisfied: cryptography>=2.1.4 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 11)) (3.2.1)
Requirement already satisfied: pyparsing<2.4.0,>=2.0.3 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 12)) (2.3.1)
Requirement already satisfied: pyelftools>=0.22 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 13)) (0.27)
Requirement already satisfied: gdbgui==0.13.2.0 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (0.13.2.0)
Requirement already satisfied: pygdbmi<=0.9.0.2 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 17)) (0.9.0.2)
Requirement already satisfied: reedsolo==1.5.3 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 19)) (1.5.3)
Requirement already satisfied: bitstring>=3.1.6 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from -r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 20)) (3.1.7)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from cryptography>=2.1.4->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 11)) (1.14.3)
Requirement already satisfied: six>=1.4.1 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from cryptography>=2.1.4->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 11)) (1.15.0)
Requirement already satisfied: gevent<2.0,>=1.2.2 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (1.5.0)
Requirement already satisfied: Pygments<3.0,>=2.2.0 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (2.7.2)
Requirement already satisfied: Flask<1.0,>=0.12.2 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (0.12.5)
Requirement already satisfied: Flask-Compress<2.0,>=1.4.0 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (1.7.0)
Requirement already satisfied: Flask-SocketIO<3.0,>=2.9 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (2.9.6)
Requirement already satisfied: pycparser in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.1.4->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 11)) (2.20)
Requirement already satisfied: greenlet>=0.4.14; platform_python_implementation == "CPython" in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from gevent<2.0,>=1.2.2->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (0.4.17)
Requirement already satisfied: itsdangerous>=0.21 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from Flask<1.0,>=0.12.2->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (1.1.0)
Requirement already satisfied: Werkzeug<1.0,>=0.7 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from Flask<1.0,>=0.12.2->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (0.16.1)
Requirement already satisfied: Jinja2>=2.4 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from Flask<1.0,>=0.12.2->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (2.11.2)
Requirement already satisfied: brotli in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from Flask-Compress<2.0,>=1.4.0->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (1.0.9)
Requirement already satisfied: python-socketio>=1.6.1 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from Flask-SocketIO<3.0,>=2.9->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (4.6.0)
Requirement already satisfied: MarkupSafe>=0.23 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from Jinja2>=2.4->Flask<1.0,>=0.12.2->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (1.1.1)
Requirement already satisfied: python-engineio>=3.13.0 in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages (from python-socketio>=1.6.1->Flask-SocketIO<3.0,>=2.9->gdbgui==0.13.2.0->-r /home/zhouyun/esp/esp-idf-4.2/requirements.txt (line 14)) (3.13.2)
All done! You can now run:

. ./export.sh

如果安装失败,大部分情况是下载工具链失败,查看具体的日志,主动从官方github网站上去下载相关文件,放到 ~/.espressif/dist目录,并重新执行intall.sh可即可,可能需要要手动下载的工具链如下:

zhouyun@zhyubntserver:~$ ll ~/.espressif/dist/
total 354548
drwxrwxr-x 2 zhouyun zhouyun     4096 Oct 31 00:03 ./
drwxrwxr-x 5 zhouyun zhouyun     4096 Oct 30 14:34 ../
-rw-rw-r-- 1 zhouyun zhouyun  8254018 Oct 30 13:54 binutils-esp32s2ulp-linux-amd64-2.28.51-esp-20191205.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun  8248656 Oct 30 13:38 binutils-esp32ulp-linux-amd64-2.28.51-esp-20191205.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun  1680363 Oct 30 14:26 openocd-esp32-linux64-0.10.0-esp32-20191114.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun  1729401 Oct 31 00:03 openocd-esp32-linux64-0.10.0-esp32-20200709.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun 85520229 Oct 30 13:21 xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun 85731226 Oct 31 00:03 xtensa-esp32-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun 85796525 Oct 30 13:21 xtensa-esp32s2-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz
-rw-rw-r-- 1 zhouyun zhouyun 86069526 Oct 31 00:03 xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz

三、导出环境变量

执行export.sh即可

zhouyun@zhyubntserver:~/esp/esp-idf-4.2$ . export.sh
Setting IDF_PATH to '/home/zhouyun/esp/esp-idf-4.2'
Adding ESP-IDF tools to PATH...
Using Python interpreter in /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/bin/python
Checking if Python packages are up to date...
Python requirements from /home/zhouyun/esp/esp-idf-4.2/requirements.txt are satisfied.
Added the following directories to PATH:
  /home/zhouyun/esp/esp-idf-4.2/components/esptool_py/esptool
  /home/zhouyun/esp/esp-idf-4.2/components/espcoredump
  /home/zhouyun/esp/esp-idf-4.2/components/partition_table
  /home/zhouyun/esp/esp-idf-4.2/components/app_update
  /home/zhouyun/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin
  /home/zhouyun/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf/bin
  /home/zhouyun/.espressif/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin
  /home/zhouyun/.espressif/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin
  /home/zhouyun/.espressif/tools/openocd-esp32/v0.10.0-esp32-20200709/openocd-esp32/bin
  /home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/bin
  /home/zhouyun/esp/esp-idf-4.2/tools
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

四、配置、编译、下载、运行

复制“hello_world” 目录到想要保存的位置:

cp esp-idf-4.2/examples/get-started/hello_world/ . -r

然后进入hello_world目录:

cd hello_world/

另外,在配置、编译之前,要选择一下芯片,我这里是esp32s2:

idf.py set-target esp32s2

如果是esp32芯片,则对应执行即可

idf.py set-target esp32

然后配置工程,

idf.py menuconfig

编译

idf.py build

下载

idf.py -p /dev/ttyUSB0 flash

如果下载失败,可能原因有两个:
(1)目标芯片没有选择正确,idf.py 执行set-target 再重新menuconfig
(2)串口权限,当前用户没有对串口的读写权限,错误提示如下:

Serial port /dev/ttyUSB0
Traceback (most recent call last):
  File "/home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/zhouyun/esp/esp-idf-4.2/components/esptool_py/esptool/esptool.py", line 3682, in <module>
    _main()
  File "/home/zhouyun/esp/esp-idf-4.2/components/esptool_py/esptool/esptool.py", line 3675, in _main
    main()
  File "/home/zhouyun/esp/esp-idf-4.2/components/esptool_py/esptool/esptool.py", line 3329, in main
    esp = chip_class(each_port, initial_baud, args.trace)
  File "/home/zhouyun/esp/esp-idf-4.2/components/esptool_py/esptool/esptool.py", line 263, in __init__
    self._port = serial.serial_for_url(port)
  File "/home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages/serial/__init__.py", line 88, in serial_for_url
    instance.open()
  File "/home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/lib/python3.8/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
CMake Error at run_cmd.cmake:14 (message):
  esptool.py failed
Call Stack (most recent call first):
  run_esptool.cmake:21 (include)


make[3]: *** [CMakeFiles/flash.dir/build.make:57: CMakeFiles/flash] Error 1
make[2]: *** [CMakeFiles/Makefile2:1949: CMakeFiles/flash.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1956: CMakeFiles/flash.dir/rule] Error 2
make: *** [Makefile:216: flash] Error 2
make failed with exit code 2

此时,增加串口的读写权限即可:

sudo chmod a=rw /dev/ttyUSB0

下载成功后的日志如下:

zhouyun@zhyubntserver:~/esp/hello_world$ idf.py -p /dev/ttyUSB0  flash
Executing action: flash
Running make in directory /home/zhouyun/esp/hello_world/build
Executing "make -j 10 flash"...
[  0%] Built target partition_table_bin
[  0%] Built target esp32s2_linker_script
[  0%] Built target _project_elf_src
[  0%] Built target custom_bundle
[  0%] Performing build step for 'bootloader'
[  0%] Built target __idf_ulp
[  1%] Built target __idf_esp_http_server
[  1%] Built target _project_elf_src
[  5%] Built target __idf_log
[  2%] Built target __idf_esp_http_client
[ 19%] Built target soc_esp32s2
[  3%] Built target __idf_tcp_transport
[ 68%] Built target __idf_soc
[  3%] Built target __idf_esp-tls
[ 70%] Built target __idf_micro-ecc
[  6%] Built target __idf_nghttp
[ 86%] Built target __idf_bootloader_support
[  6%] Built target __idf_app_trace
[ 94%] Built target __idf_efuse
[  7%] Built target __idf_cxx
[ 96%] Built target __idf_main
[  8%] Built target __idf_newlib
[ 99%] Built target bootloader.elf
[  9%] Built target __idf_freertos
[100%] Built target gen_project_binary
[100%] Built target app
[  9%] Built target __idf_esp_timer
[  9%] No install step for 'bootloader'
[ 10%] Built target __idf_esp_common
[ 10%] Completed 'bootloader'
[ 12%] Built target __idf_esp32s2
[ 13%] Built target bootloader
[ 13%] Built target __idf_espcoredump
[ 13%] Built target __idf_pthread
[ 16%] Built target __idf_driver
[ 17%] Built target __idf_esp_ringbuf
[ 18%] Built target __idf_heap
[ 18%] Built target __idf_log
[ 27%] Built target __idf_lwip
[ 29%] Built target __idf_esp_wifi
[ 30%] Built target __idf_nvs_flash
[ 39%] Built target __idf_wpa_supplicant
[ 39%] Built target __idf_esp_event
[ 40%] Built target __idf_esp_netif
[ 40%] Built target __idf_tcpip_adapter
[ 41%] Built target __idf_esp_eth
[ 41%] Built target __idf_vfs
[ 43%] Built target soc_esp32s2
[ 49%] Built target __idf_soc
[ 50%] Built target __idf_esp_system
[ 51%] Built target __idf_spi_flash
[ 51%] Built target __idf_esp_ipc
[ 51%] Built target __idf_app_update
[ 52%] Built target __idf_bootloader_support
[ 53%] Built target __idf_efuse
[ 61%] Built target mbedcrypto
[ 62%] Built target mbedx509
[ 63%] Built target mbedtls
[ 63%] Built target __idf_mbedtls
[ 64%] Built target __idf_xtensa
[ 64%] Built target __idf_json
[ 64%] Built target __idf_protobuf-c
[ 64%] Built target __idf_console
[ 64%] Built target __idf_esp_adc_cal
[ 64%] Built target __idf_esp_https_ota
[ 65%] Built target __idf_esp_gdbstub
[ 65%] Built target __idf_esp_hid
[ 66%] Built target __idf_cbor
[ 67%] Built target __idf_asio
[ 70%] Built target __idf_coap
[ 71%] Built target __idf_sdmmc
[ 71%] Built target __idf_jsmn
[ 71%] Built target __idf_esp_websocket_client
[ 72%] Built target __idf_expat
[ 73%] Built target __idf_wear_levelling
[ 73%] Built target __idf_mqtt
[ 75%] Built target __idf_openssl
[ 75%] Built target __idf_perfmon
[ 79%] Built target __idf_freemodbus
[ 82%] Built target __idf_unity
[ 83%] Built target __idf_spiffs
[ 94%] Built target __idf_libsodium
[ 95%] Built target __idf_protocomm
[ 95%] Built target __idf_esp_serial_slave_link
[ 96%] Built target __idf_mdns
[ 97%] Built target __idf_fatfs
[ 97%] Built target __idf_esp_local_ctrl
[ 98%] Built target __idf_wifi_provisioning
[ 99%] Built target __idf_main
[ 99%] Built target __ldgen_output_esp32s2.project.ld
[100%] Built target hello-world.elf
[100%] Built target gen_project_binary
[100%] Built target app
esptool.py --chip esp32s2 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x10000 hello-world.bin
esptool.py v3.0-dev
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S2
Features: WiFi, ADC and temperature sensor calibration in BLK2 of efuse
Crystal is 40MHz
MAC: 7c:df:a1:01:84:12
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 4048.8 kbit/s)...
Hash of data verified.
Compressed 20704 bytes to 12578...
Writing at 0x00001000... (100 %)
Wrote 20704 bytes (12578 compressed) at 0x00001000 in 0.3 seconds (effective 576.5 kbit/s)...
Hash of data verified.
Compressed 143232 bytes to 75179...
Writing at 0x00010000... (20 %)
Writing at 0x00014000... (40 %)
Writing at 0x00018000... (60 %)
Writing at 0x0001c000... (80 %)
Writing at 0x00020000... (100 %)
Wrote 143232 bytes (75179 compressed) at 0x00010000 in 1.8 seconds (effective 650.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
[100%] Built target flash
Done

查看运行情况:

idf.py -p /dev/ttyUSB0 monitor

可以看到hello_world已经运行起来了:

Executing action: monitor
Running idf_monitor in directory /home/zhouyun/esp/hello_world
Executing "/home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/bin/python /home/zhouyun/esp/esp-idf-4.2/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32s2-elf- /home/zhouyun/esp/hello_world/build/hello-world.elf -m '/home/zhouyun/.espressif/python_env/idf4.2_py3.8_env/bin/python' '/home/zhouyun/esp/esp-idf-4.2/tools/idf.py' '-p' '/dev/ttyUSB0'"...
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
 in 8 secon▒ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x4
load:0x3ffe6104,len:0x18a8
load:0x4004c000,len:0x1480
load:0x40050000,len:0x234c
entry 0x4004c2d0
I (46) boot: ESP-IDF v4.2-beta1-227-gf0e87c933 2nd stage bootloader
I (46) boot: compile time 01:05:03
I (46) boot: chip revision: 0
I (49) boot.esp32s2: SPI Speed      : 80MHz
I (54) boot.esp32s2: SPI Mode       : DIO
I (59) boot.esp32s2: SPI Flash Size : 4MB
I (63) boot: Enabling RNG early entropy source...
I (69) boot: Partition Table:
I (72) boot: ## Label            Usage          Type ST Offset   Length
I (80) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (87) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (95) boot:  2 factory          factory app      00 00 00010000 00100000
I (102) boot: End of partition table
I (106) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x050d0 ( 20688) map
I (120) esp_image: segment 1: paddr=0x000150f8 vaddr=0x3ffbcdc0 size=0x01d24 (  7460) load
I (126) esp_image: segment 2: paddr=0x00016e24 vaddr=0x40024000 size=0x00404 (  1028) load
0x40024000: _WindowOverflow4 at /home/zhouyun/esp/esp-idf-4.2/components/freertos/xtensa/xtensa_vectors.S:1730

I (133) esp_image: segment 3: paddr=0x00017230 vaddr=0x40024404 size=0x089b0 ( 35248) load
I (152) esp_image: segment 4: paddr=0x0001fbe8 vaddr=0x00000000 size=0x00430 (  1072)
I (152) esp_image: segment 5: paddr=0x00020020 vaddr=0x40080020 size=0x12f34 ( 77620) map
0x40080020: _stext at ??:?

I (181) boot: Loaded app from partition at offset 0x10000
I (181) boot: Disabling RNG early entropy source...
I (181) cache: Instruction cache        : size 8KB, 4Ways, cache line size 32Byte
I (189) cpu_start: Pro cpu up.
I (192) cpu_start: Application information:
I (197) cpu_start: Project name:     hello-world
I (203) cpu_start: App version:      1
I (207) cpu_start: Compile time:     Oct 31 2020 01:05:20
I (213) cpu_start: ELF file SHA256:  682925f761aa29e1...
I (219) cpu_start: ESP-IDF:          v4.2-beta1-227-gf0e87c933
I (226) cpu_start: Single core mode
I (230) heap_init: Initializing. RAM available for dynamic allocation:
I (237) heap_init: At 3FFBF2A8 len 0003CD58 (243 KiB): DRAM
I (243) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (249) cpu_start: Pro cpu start user code
I (308) spi_flash: detected chip: generic
I (309) spi_flash: flash io: dio
I (309) cpu_start: Starting scheduler on PRO CPU.
Hello world!
This is esp32s2 chip with 1 CPU cores, WiFi, silicon revision 0, 4MB external flash
Free heap: 249124
Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
Restarting now.
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40024f21
0x40024f21: esp_restart_noos_dig at /home/zhouyun/esp/esp-idf-4.2/components/esp_system/system_api.c:60 (discriminator 1)

SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x4
load:0x3ffe6104,len:0x18a8
load:0x4004c000,len:0x1480
load:0x40050000,len:0x234c
entry 0x4004c2d0
I (48) boot: ESP-IDF v4.2-beta1-227-gf0e87c933 2nd stage bootloader
I (48) boot: compile time 01:05:03
I (48) boot: chip revision: 0
I (52) boot.esp32s2: SPI Speed      : 80MHz
I (57) boot.esp32s2: SPI Mode       : DIO
I (61) boot.esp32s2: SPI Flash Size : 4MB
I (66) boot: Enabling RNG early entropy source...
I (71) boot: Partition Table:
I (75) boot: ## Label            Usage          Type ST Offset   Length
I (82) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (90) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (97) boot:  2 factory          factory app      00 00 00010000 00100000
I (105) boot: End of partition table
I (109) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x050d0 ( 20688) map
I (122) esp_image: segment 1: paddr=0x000150f8 vaddr=0x3ffbcdc0 size=0x01d24 (  7460) load
I (129) esp_image: segment 2: paddr=0x00016e24 vaddr=0x40024000 size=0x00404 (  1028) load
0x40024000: _WindowOverflow4 at /home/zhouyun/esp/esp-idf-4.2/components/freertos/xtensa/xtensa_vectors.S:1730

I (136) esp_image: segment 3: paddr=0x00017230 vaddr=0x40024404 size=0x089b0 ( 35248) load
I (154) esp_image: segment 4: paddr=0x0001fbe8 vaddr=0x00000000 size=0x00430 (  1072)
I (155) esp_image: segment 5: paddr=0x00020020 vaddr=0x40080020 size=0x12f34 ( 77620) map
0x40080020: _stext at ??:?

I (183) boot: Loaded app from partition at offset 0x10000
I (183) boot: Disabling RNG early entropy source...
I (184) cache: Instruction cache        : size 8KB, 4Ways, cache line size 32Byte
I (191) cpu_start: Pro cpu up.
I (195) cpu_start: Application information:
I (200) cpu_start: Project name:     hello-world
I (205) cpu_start: App version:      1
I (209) cpu_start: Compile time:     Oct 31 2020 01:05:20
I (216) cpu_start: ELF file SHA256:  682925f761aa29e1...
I (222) cpu_start: ESP-IDF:          v4.2-beta1-227-gf0e87c933
I (228) cpu_start: Single core mode
I (232) heap_init: Initializing. RAM available for dynamic allocation:
I (239) heap_init: At 3FFBF2A8 len 0003CD58 (243 KiB): DRAM
I (246) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (252) cpu_start: Pro cpu start user code
I (309) spi_flash: detected chip: generic
I (309) spi_flash: flash io: dio
I (309) cpu_start: Starting scheduler on PRO CPU.
Hello world!
This is esp32s2 chip with 1 CPU cores, WiFi, silicon revision 0, 4MB external flash
Free heap: 249124
Restarting in 10 seconds...

按下 CTRL + ] 即可退出串口monitor

至此,整个开发环境搭建完成。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值