forked from espressif/esp-idf
docs: updated CN translation for new get started
This commit is contained in:
@@ -214,13 +214,9 @@ Step 5. First Steps on ESP-IDF
|
||||
Tip: Updating ESP-IDF
|
||||
======================
|
||||
|
||||
<<<<<<< HEAD
|
||||
It is recommended to update ESP-IDF from time to time, as newer versions fix bugs and/or provide new features. Please note that each ESP-IDF major and minor release version has an associated support period, and when one release branch is approaching end of life (EOL), all users are encouraged to upgrade their projects to more recent ESP-IDF releases, to find out more about support periods, see ESP-IDF Versions.
|
||||
It is recommended to update ESP-IDF from time to time, as newer versions fix bugs and/or provide new features. Please note that each ESP-IDF major and minor release version has an associated support period, and when one release branch is approaching end of life (EOL), all users are encouraged to upgrade their projects to more recent ESP-IDF releases, to find out more about support periods, see :doc:`ESP-IDF Versions <../versions>`.
|
||||
|
||||
The simplest way to do the update is to delete the existing ``esp-idf`` folder and clone it again, as if performing the initial installation described in :ref:`get-started-get-esp-idf`.
|
||||
=======
|
||||
You should update ESP-IDF from time to time, as newer versions fix bugs and provide new features. The simplest way to do the update is to delete the existing ``esp-idf`` folder and clone it again, as if performing the initial installation described in :ref:`get-started-get-esp-idf`.
|
||||
>>>>>>> [Docs] New getting started based on the ide and os selection
|
||||
|
||||
Another solution is to update only what has changed. :ref:`The update procedure depends on the version of ESP-IDF you are using <updating>`.
|
||||
|
||||
|
@@ -8,10 +8,12 @@ Now you have all requirements to start using ESP-IDF, the next topic will guide
|
||||
|
||||
This guide will help you on the first steps using ESP-IDF. By following this guide you will able to start a new project, connect the {IDF_TARGET_NAME}, change the project configuration, build, flash, and monitor the project.
|
||||
|
||||
.. note:: If you haven't yet installed the ESP-IDF, please go to :ref:`get-started-step-by-step` and follow the instruction in oder to get all the software needed to use this guide.
|
||||
.. note::
|
||||
|
||||
If you haven't yet installed the ESP-IDF, please go to :ref:`get-started-step-by-step` and follow the instruction in oder to get all the software needed to use this guide.
|
||||
|
||||
Start a Project
|
||||
===============
|
||||
===================
|
||||
|
||||
Now you are ready to prepare your application for {IDF_TARGET_NAME}. You can start with :example:`get-started/hello_world` project from :idf:`examples` directory in IDF.
|
||||
|
||||
@@ -79,7 +81,7 @@ Linux/macOS
|
||||
idf.py set-target {IDF_TARGET_PATH_NAME}
|
||||
idf.py menuconfig
|
||||
|
||||
Setting the target with ``idf.py set-target {IDF_TARGET_PATH_NAME}`` should be done once, after opening a new project. If the project contains some existing builds and configuration, they will be cleared and initialized. The target may be saved in environment variable to skip this step at all. See :ref:`selecting-idf-target` for additional information.
|
||||
Setting the target with ``idf.py set-target {IDF_TARGET_PATH_NAME}`` should be done once after opening a new project. If the project contains some existing builds and configurations, they will be cleared and initialized. The target may be saved in the environment variable to skip this step at all. See :ref:`selecting-idf-target` for additional information.
|
||||
|
||||
If the previous steps have been done correctly, the following menu appears:
|
||||
|
||||
@@ -135,6 +137,7 @@ This command will compile the application and all ESP-IDF components, then it wi
|
||||
|
||||
If there are no errors, the build will finish by generating the firmware binary .bin files.
|
||||
|
||||
|
||||
Flash onto the Device
|
||||
=====================
|
||||
|
||||
@@ -171,7 +174,7 @@ In general, you should have no problems with the `official esp-idf development b
|
||||
|
||||
Depending on the kind of hardware you have, it may also be possible to manually put your {IDF_TARGET_NAME} board into Firmware Download mode (reset).
|
||||
|
||||
- For development boards produced by Espressif, this information can be found in the respective getting started guides or user guides. For example, to manually reset an esp-idf development board, hold down the **Boot** button (``{IDF_TARGET_STRAP_GPIO}``) and press the **EN** button (``CHIP_PU``).
|
||||
- For development boards produced by Espressif, this information can be found in the respective getting started guides or user guides. For example, to manually reset an ESP-IDF development board, hold down the **Boot** button (``{IDF_TARGET_STRAP_GPIO}``) and press the **EN** button (``CHIP_PU``).
|
||||
- For other types of hardware, try pulling ``{IDF_TARGET_STRAP_GPIO}`` down.
|
||||
|
||||
Normal Operation
|
||||
|
@@ -52,17 +52,18 @@ This is the documentation for Espressif IoT Development Framework (`esp-idf <htt
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
Get Started <get-started/index>
|
||||
API Reference <api-reference/index>
|
||||
H/W Reference <hw-reference/index>
|
||||
API Guides <api-guides/index>
|
||||
ESP-IDF 5.0 Migration Guides <migration-guides/index>
|
||||
Libraries and Frameworks <libraries-and-frameworks/index>
|
||||
Contribute <contribute/index>
|
||||
Versions <versions>
|
||||
Resources <resources>
|
||||
Copyrights <COPYRIGHT>
|
||||
About <about>
|
||||
语言/Languages <languages>
|
||||
get-started/index
|
||||
get-started/start-project
|
||||
api-reference/index
|
||||
hw-reference/index
|
||||
api-guides/index
|
||||
migration-guides/index
|
||||
libraries-and-frameworks/index
|
||||
contribute/index
|
||||
versions
|
||||
resources
|
||||
COPYRIGHT
|
||||
about
|
||||
languages
|
||||
|
||||
* :ref:`genindex`
|
||||
|
@@ -2,13 +2,6 @@
|
||||
快速入门
|
||||
***********
|
||||
|
||||
{IDF_TARGET_CORE_NUM:default="2", esp32s2="1", esp32c3="1"}
|
||||
|
||||
{IDF_TARGET_FEATURES:default="WiFi/BT/BLE, silicon revision 1, 2MB external flash", esp32="WiFi/BT/BLE, silicon revision 1, 2MB external flash", esp32s2="WiFi, silicon revision 0, 2MB external flash", esp32s3="This is esp32s3 chip with 2 CPU core(s), WiFi/BLE, silicon revision 0, 2MB external flash", esp32c3="WiFi/BLE, silicon revision 0, 2MB external flash"}
|
||||
|
||||
{IDF_TARGET_HEAP_SIZE:default="298968", esp32="298968", esp32s2="253900", esp32s3="390684", esp32c3="337332"}
|
||||
|
||||
|
||||
:link_to_translation:`en:[English]`
|
||||
|
||||
.. 请保证 README.md 文件与该文件保持同步
|
||||
@@ -62,41 +55,19 @@
|
||||
|
||||
乐鑫为用户提供完整的软、硬件资源,进行 {IDF_TARGET_NAME} 硬件设备的开发。其中,乐鑫的软件开发环境 ESP-IDF 旨在协助用户快速开发物联网 (IoT) 应用,可满足用户对 Wi-Fi、蓝牙、低功耗等方面的要求。
|
||||
|
||||
|
||||
准备工作
|
||||
=============
|
||||
|
||||
硬件:
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
* 一款 **{IDF_TARGET_NAME}** 开发板
|
||||
* **USB 数据线** (A 转 Micro-B)
|
||||
* 电脑(Windows、Linux 或 Mac OS)
|
||||
* 电脑(Windows、Linux 或 macOS)
|
||||
|
||||
软件:
|
||||
.. note:: 目前一些开发板使用的是 USB Type C 接口。请确保使用合适的数据线来连接开发板!
|
||||
|
||||
您可以选择下载并手动安装以下软件:
|
||||
|
||||
* 设置 **工具链**,用于编译 {IDF_TARGET_NAME} 代码;
|
||||
* **编译构建工具** —— CMake 和 Ninja 编译构建工具,用于编译 {IDF_TARGET_NAME} **应用程序**;
|
||||
* 获取 **ESP-IDF** 软件开发框架。该框架已经基本包含 {IDF_TARGET_NAME} 使用的 API(软件库和源代码)和运行 **工具链** 的脚本;
|
||||
|
||||
或者,您也可以通过以下集成开发环境 (IDE) 中的官方插件完成安装流程:
|
||||
|
||||
* `Eclipse 插件 <https://github.com/espressif/idf-eclipse-plugin>`_ (`安装 <https://github.com/espressif/idf-eclipse-plugin#installing-idf-plugin-using-update-site-url>`__)
|
||||
* `VS Code 插件 <https://github.com/espressif/vscode-esp-idf-extension>`_ (`安装 <https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md>`__)
|
||||
|
||||
.. figure:: ../../_static/what-you-need.png
|
||||
:align: center
|
||||
:alt: {IDF_TARGET_NAME} 应用程序开发
|
||||
:figclass: align-center
|
||||
|
||||
{IDF_TARGET_NAME} 应用程序开发
|
||||
|
||||
|
||||
开发板简介
|
||||
===========================
|
||||
|
||||
请点击下方连接,了解有关开发板的详细信息。
|
||||
以下是 {IDF_TARGET_NAME} 官方开发板,点击链接可了解更多硬件信息。
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
@@ -139,692 +110,59 @@
|
||||
ESP32-S3-DevKitC-1 <../hw-reference/esp32s3/user-guide-devkitc-1>
|
||||
ESP32-S3-DevKitM-1 <../hw-reference/esp32s3/user-guide-devkitm-1>
|
||||
|
||||
|
||||
.. _get-started-step-by-step:
|
||||
|
||||
详细安装步骤
|
||||
=========================
|
||||
|
||||
请根据下方详细步骤,完成安装过程。
|
||||
|
||||
设置开发环境
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* :ref:`get-started-get-prerequisites` (:doc:`Windows <windows-setup>` 、:doc:`Linux <linux-macos-setup>` 和 :doc:`macOS <linux-macos-setup>`)
|
||||
* :ref:`get-started-get-esp-idf`
|
||||
* :ref:`get-started-set-up-tools`
|
||||
* :ref:`get-started-set-up-env`
|
||||
|
||||
创建您的第一个工程
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* :ref:`get-started-start-project`
|
||||
* :ref:`get-started-connect`
|
||||
* :ref:`get-started-configure`
|
||||
* :ref:`get-started-build`
|
||||
* :ref:`get-started-flash`
|
||||
* :ref:`get-started-build-monitor`
|
||||
|
||||
|
||||
.. _get-started-get-prerequisites:
|
||||
|
||||
第一步:安装准备
|
||||
=============================
|
||||
软件:
|
||||
~~~~~~~~
|
||||
|
||||
在正式开始创建工程前,请先完成工具的安装,具体步骤见下:
|
||||
如需在 **{IDF_TARGET_NAME}** 上使用 ESP-IDF,请安装以下软件:
|
||||
|
||||
* 设置 **工具链**,用于编译 {IDF_TARGET_NAME} 代码;
|
||||
* **编译构建工具** —— CMake 和 Ninja 编译构建工具,用于编译 {IDF_TARGET_NAME} **应用程序**;
|
||||
* 获取 **ESP-IDF** 软件开发框架。该框架已经基本包含 {IDF_TARGET_NAME} 使用的 API(软件库和源代码)和运行 **工具链** 的脚本;
|
||||
|
||||
.. figure:: ../../_static/what-you-need.png
|
||||
:align: center
|
||||
:alt: Development of applications for {IDF_TARGET_NAME}
|
||||
:figclass: align-center
|
||||
|
||||
.. _get-started-step-by-step:
|
||||
.. _get-started-how-to-get-esp-idf:
|
||||
|
||||
安装
|
||||
============
|
||||
|
||||
我们提供以下方法帮助安装所有需要的软件,可根据需要选择其中之一。
|
||||
|
||||
IDE
|
||||
~~~~~~
|
||||
|
||||
.. note:: 建议您通过自己喜欢的集成开发环境 (IDE) 安装 ESP-IDF。
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
Eclipse Plugin <../get-started/eclipse-setup>
|
||||
VSCode Extension <../get-started/vscode-setup>
|
||||
|
||||
手动安装
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
请根据您的操作系统选择对应的手动安装流程。
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
Windows Installer <../get-started/windows-setup>
|
||||
Linux and macOS <../get-started/linux-macos-setup>
|
||||
|
||||
编译第一个工程
|
||||
===================
|
||||
|
||||
如果您已经安装好 ESP-IDF 且没有使用集成开发环境 (IDE),请在命令提示行中按照 :ref:`get-started-first-steps` 编译第一个工程。
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
Windows <windows-setup>
|
||||
macOS <linux-macos-setup>
|
||||
Linux <linux-macos-setup>
|
||||
|
||||
+-------------------+-------------------+-------------------+
|
||||
| |windows-logo| | |linux-logo| | |macos-logo| |
|
||||
+-------------------+-------------------+-------------------+
|
||||
| `Windows`_ | `Linux`_ | `macOS`_ |
|
||||
+-------------------+-------------------+-------------------+
|
||||
|
||||
.. |windows-logo| image:: ../../_static/windows-logo.png
|
||||
:target: ../get-started/windows-setup.html
|
||||
|
||||
.. |linux-logo| image:: ../../_static/linux-logo.png
|
||||
:target: ../get-started/linux-macos-setup.html
|
||||
|
||||
.. |macos-logo| image:: ../../_static/macos-logo.png
|
||||
:target: ../get-started/linux-macos-setup.html
|
||||
|
||||
.. _Windows: ../get-started/windows-setup.html
|
||||
.. _Linux: ../get-started/linux-macos-setup.html
|
||||
.. _macOS: ../get-started/linux-macos-setup.html
|
||||
|
||||
.. note::
|
||||
|
||||
在本文档中,Linux 和 macOS 操作系统中 ESP-IDF 的默认安装路径为 ``~/esp``;Windows 操作系统中的默认安装路径为 ``%userprofile%\esp``。您也可以将 ESP-IDF 安装在任何其他路径下,但请注意在使用命令行时进行相应替换。注意,ESP-IDF 不支持带有空格的路径。
|
||||
|
||||
.. _get-started-get-esp-idf:
|
||||
|
||||
第二步:获取 ESP-IDF
|
||||
=================================
|
||||
|
||||
在围绕 {IDF_TARGET_NAME} 构建应用程序之前,请先获取乐鑫提供的软件库文件 `ESP-IDF 仓库 <https://github.com/espressif/esp-idf>`_。
|
||||
|
||||
获取 ESP-IDF 的本地副本:打开终端,切换到您要保存 ESP-IDF 的工作目录,使用 ``git clone`` 命令克隆远程仓库。针对不同操作系统的详细步骤,请见下文。
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
打开终端,后运行以下命令:
|
||||
|
||||
.. include-build-file:: inc/git-clone-bash.inc
|
||||
|
||||
ESP-IDF 将下载至 ``~/esp/esp-idf``。
|
||||
|
||||
请前往 :doc:`/versions`,查看 ESP-IDF 不同版本的具体适用场景。
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
除了安装必要工具外,第一步中介绍的 :ref:`get-started-windows-tools-installer` 也能同时下载 ESP-IDF 本地副本。
|
||||
|
||||
请前往 :doc:`/versions`,查看 ESP-IDF 不同版本的具体适用场景。
|
||||
|
||||
除了使用 ESP-IDF 工具安装器,您也可以参考 :ref:`指南 <get-started-windows-tools-installer>` 手动下载 ESP-IDF。
|
||||
|
||||
.. _get-started-set-up-tools:
|
||||
|
||||
第三步:设置工具
|
||||
=================================
|
||||
|
||||
除了 ESP-IDF 本身,您还需要安装 ESP-IDF 使用的各种工具,比如编译器、调试器、Python 包等。
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
请根据第一步中对 Windows (:ref:`get-started-windows-tools-installer`) 的介绍,安装所有必需工具。
|
||||
|
||||
除了使用 ESP-IDF 工具安装器,您也可以通过 **命令提示符** 窗口手动安装这些工具。具体步骤见下:
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp\esp-idf
|
||||
install.bat {IDF_TARGET_PATH_NAME}
|
||||
|
||||
或使用 Windows PowerShell
|
||||
|
||||
.. code-block:: powershell
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
./install.ps1 {IDF_TARGET_PATH_NAME}
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
./install.sh {IDF_TARGET_PATH_NAME}
|
||||
|
||||
或使用 Fish shell
|
||||
|
||||
.. code-block:: fish
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
./install.fish {IDF_TARGET_PATH_NAME}
|
||||
|
||||
.. note::
|
||||
通过一次性指定多个目标,可为多个目标芯片同时安装工具,如运行 ``./install.sh esp32,esp32c3,esp32s3``。
|
||||
通过运行 ``./install.sh`` 或 ``./install.sh all`` 可一次性为所有支持的目标芯片安装工具。
|
||||
|
||||
下载工具备选方案
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
ESP-IDF 工具安装器会下载 Github 发布版本中附带的一些工具,如果访问 Github 较为缓慢,则可以设置一个环境变量,实现优先选择 Espressif 的下载服务器进行 Github 资源下载。
|
||||
|
||||
.. 注解:: 该设置只影响从 Github 发布版本中下载的单个工具,它并不会改变访问任何 Git 仓库的 URL。
|
||||
|
||||
Windows 操作系统
|
||||
-----------------
|
||||
|
||||
如果希望在运行 ESP-IDF 工具安装器时优先选择 Espressif 下载服务器,请在 **Select Components** 窗口中的 **Optimization** 部分勾选 **Use Espressif download mirror instead of GitHub** 选项。
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
--------------------------
|
||||
|
||||
要在安装工具时优先选择 Espressif 下载服务器,请在运行 ``install.sh`` 时使用以下命令:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets"
|
||||
./install.sh
|
||||
|
||||
自定义工具安装路径
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
本步骤中介绍的脚本将 ESP-IDF 所需的编译工具默认安装在用户的根目录中,即 Linux 和 macOS 系统中的 ``$HOME/.espressif`` 和 Windows 系统的 ``%USERPROFILE%\.espressif``。此外,您可以将工具安装到其他目录中,但请在运行安装脚本前,重新设置环境变量 ``IDF_TOOLS_PATH``。注意,请确保您的用户已经具备了读写该路径的权限。
|
||||
|
||||
如果修改了 ``IDF_TOOLS_PATH`` 变量,请确保该变量在每次执行安装脚本 (``install.bat``、``install.ps1`` 或 ``install.sh``) 和导出脚本 (``export.bat``、``export.ps1`` 或 ``export.sh``) 均保持一致。
|
||||
|
||||
.. _get-started-set-up-env:
|
||||
|
||||
|
||||
第四步:设置环境变量
|
||||
=======================================
|
||||
|
||||
此时,您刚刚安装的工具尚未添加至 PATH 环境变量,无法通过“命令窗口”使用这些工具。因此,必须设置一些环境变量,这可以通过 ESP-IDF 提供的另一个脚本完成。
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Windows 安装器(:ref:`get-started-windows-tools-installer` )可在“开始”菜单创建一个 "ESP-IDF Command Prompt" 快捷方式。该快捷方式可以打开命令提示符窗口,并设置所有环境变量。您可以点击该快捷方式,然后继续下一步。
|
||||
|
||||
此外,如果您希望在当下命令提示符窗口使用 ESP-IDF,请使用下方代码:
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
%userprofile%\esp\esp-idf\export.bat
|
||||
|
||||
或使用 Windows PowerShell
|
||||
|
||||
.. code-block:: powershell
|
||||
|
||||
.$HOME/esp/esp-idf/export.ps1
|
||||
|
||||
.. _get-started-export:
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
请在需要运行 ESP-IDF 的终端窗口运行以下命令:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
. $HOME/esp/esp-idf/export.sh
|
||||
|
||||
对于 fish shell(仅支持 fish 3.0.0 及以上版本),请运行以下命令:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
. $HOME/esp/esp-idf/export.fish
|
||||
|
||||
注意,命令开始的 "." 与路径之间应有一个空格!
|
||||
|
||||
如果您需要经常运行 ESP-IDF,您可以为执行 ``export.sh`` 创建一个别名,具体步骤如下:
|
||||
|
||||
1. 复制并粘贴以下命令到 shell 配置文件中(``.profile``, ``.bashrc``, ``.zprofile`` 等)
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
alias get_idf='. $HOME/esp/esp-idf/export.sh'
|
||||
|
||||
2. 通过重启终端窗口或运行 ``source [path to profile]``,如 ``source ~/.bashrc`` 来刷新配置文件。
|
||||
|
||||
现在您可以在任何终端窗口中运行 ``get_idf`` 来设置或刷新 esp-idf 环境。
|
||||
|
||||
这里不建议您直接将 ``export.sh`` 添加到 shell 的配置文件。因为这会导致在每个终端会话中都激活 IDF 虚拟环境(包括无需使用 IDF 的情况),从而破坏使用虚拟环境的目的,并可能影响其他软件的使用。
|
||||
|
||||
.. _get-started-start-project:
|
||||
|
||||
第五步:开始创建工程
|
||||
========================================
|
||||
|
||||
现在,您可以开始准备开发 {IDF_TARGET_NAME} 应用程序了。您可以从 ESP-IDF 中 :idf:`examples` 目录下的 :example:`get-started/hello_world` 工程开始。
|
||||
|
||||
将 :example:`get-started/hello_world` 工程复制至您本地的 ``~/esp`` 目录下:
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp
|
||||
cp -r $IDF_PATH/examples/get-started/hello_world .
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp
|
||||
xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world
|
||||
|
||||
ESP-IDF 的 :idf:`examples` 目录下有一系列示例工程,都可以按照上面的方法进行创建。您可以按照上述方法复制并运行其中的任何示例,也可以直接编译示例,无需进行复制。
|
||||
|
||||
.. important::
|
||||
|
||||
ESP-IDF 编译系统不支持带有空格的路径。
|
||||
|
||||
.. _get-started-connect:
|
||||
|
||||
第六步:连接设备
|
||||
==========================================
|
||||
|
||||
现在,请将您的 {IDF_TARGET_NAME} 开发板连接到 PC,并查看开发板使用的串口。
|
||||
|
||||
通常,串口在不同操作系统下显示的名称有所不同:
|
||||
|
||||
- **Windows 操作系统:** ``COM1`` 等
|
||||
- **Linux 操作系统:** 以 ``/dev/tty`` 开始
|
||||
- **macOS 操作系统:** 以 ``/dev/cu.`` 开始
|
||||
|
||||
有关如何查看串口名称的详细信息,请见 :doc:`establish-serial-connection`。
|
||||
|
||||
.. note::
|
||||
|
||||
请记住串口名,您会在下面的步骤中用到。
|
||||
|
||||
|
||||
.. _get-started-configure:
|
||||
|
||||
第七步:配置
|
||||
=========================
|
||||
|
||||
请进入 :ref:`get-started-start-project` 中提到的 ``hello_world`` 目录,并运行工程配置工具 ``menuconfig``。
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/hello_world
|
||||
idf.py set-target {IDF_TARGET_PATH_NAME}
|
||||
idf.py menuconfig
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp\hello_world
|
||||
idf.py set-target {IDF_TARGET_PATH_NAME}
|
||||
idf.py menuconfig
|
||||
|
||||
打开一个新项目后,应首先设置“目标”芯片 ``idf.py set-target {IDF_TARGET_PATH_NAME}``。注意,此操作将清除并初始化项目之前的编译和配置(如有)。 您也可以直接将“目标”配置为环境变量(此时可跳过该步骤)。更多信息,请见 :ref:`selecting-idf-target`。
|
||||
|
||||
如果之前的步骤都正确,则会显示下面的菜单:
|
||||
|
||||
.. figure:: ../../_static/project-configuration.png
|
||||
:align: center
|
||||
:alt: 工程配置 — 主窗口
|
||||
:figclass: align-center
|
||||
|
||||
工程配置 — 主窗口
|
||||
|
||||
您可以通过此菜单设置项目的具体变量,包括 Wi-Fi 网络名称、密码和处理器速度等. ``hello_world`` 示例项目会以默认配置运行,因此可以跳过使用 ``menuconfig`` 进行项目配置这一步骤。
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. attention::
|
||||
|
||||
如果您使用的是 ESP32-DevKitC(板载 ESP32-SOLO-1 模组)或 ESP32-DevKitM-1(板载 ESP32-MINI-1(1U) 模组),请在烧写示例程序前,前往 ``menuconfig`` 中使能单核模式(:ref:`CONFIG_FREERTOS_UNICORE`)。
|
||||
|
||||
.. 注解::
|
||||
|
||||
您终端窗口中显示出的菜单颜色可能会与上图不同。您可以通过选项 ``--style`` 来改变外观。更多信息,请运行 ``idf.py menuconfig --help`` 命令。
|
||||
|
||||
.. _get-started-build:
|
||||
|
||||
第八步:编译工程
|
||||
=========================
|
||||
|
||||
请使用以下命令,编译烧录工程:
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
idf.py build
|
||||
|
||||
运行以上命令可以编译应用程序和所有 ESP-IDF 组件,接着生成 bootloader、分区表和应用程序二进制文件。
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
$ idf.py build
|
||||
Running cmake in directory /path/to/hello_world/build
|
||||
Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"...
|
||||
Warn about uninitialized values.
|
||||
-- Found Git:/usr/bin/git (found version "2.17.0")
|
||||
-- Building empty aws_iot component due to configuration
|
||||
-- Component names: ...
|
||||
-- Component paths: ...
|
||||
|
||||
... (more lines of build system output)
|
||||
|
||||
[527/527] Generating hello_world.bin
|
||||
esptool.py v2.3.1
|
||||
|
||||
Project build complete. To flash, run this command:
|
||||
../../../components/esptool_py/esptool/esptool.py -p (PORT) -b 921600 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x10000 build/hello_world.bin build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin
|
||||
or run 'idf.py -p PORT flash'
|
||||
|
||||
如果一切正常,编译完成后将生成 .bin 文件。
|
||||
|
||||
|
||||
.. _get-started-flash:
|
||||
|
||||
第九步:烧录到设备
|
||||
=============================
|
||||
|
||||
请使用以下命令,将刚刚生成的二进制文件 (bootloader.bin, partition-table.bin 和 hello_world.bin) 烧录至您的 {IDF_TARGET_NAME} 开发板:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
idf.py -p PORT [-b BAUD] flash
|
||||
|
||||
请将 PORT 替换为 {IDF_TARGET_NAME} 开发板的串口名称,具体可见 :ref:`get-started-connect`。
|
||||
|
||||
您还可以将 BAUD 替换为您希望的烧录波特率。默认波特率为 ``460800``。
|
||||
|
||||
更多有关 idf.py 参数的详情,请见 :ref:`idf.py`。
|
||||
|
||||
.. note::
|
||||
|
||||
勾选 ``flash`` 选项将自动编译并烧录工程,因此无需再运行 ``idf.py build``。
|
||||
|
||||
|
||||
烧录过程中可能遇到的问题
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
{IDF_TARGET_STRAP_GPIO:default="GPIO0", esp32="GPIO0", esp32s2="GPIO0", esp32s3="GPIO0", esp32c3="GPIO9"}
|
||||
|
||||
如果在运行给定命令时出现如“连接失败”这样的错误,原因之一则可能是运行 ``esptool.py`` 出现错误。``esptool.py`` 是构建系统调用的程序,用于重置芯片、与 ROM 引导加载器交互以及烧录固件的工具。解决该问题的一个简单的方法就是按照以下步骤进行手动复位。如果问题仍未解决,请参考 `Troubleshooting <https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html#bootloader-won-t-respond>`_ 获取更多信息。
|
||||
|
||||
``esptool.py`` 通过使 USB 转串口转接器芯片(如 FTDI 或 CP210x)的 DTR 和 RTS 控制线生效来自动复位 {IDF_TARGET_NAME}(请参考 :doc:`establish-serial-connection` 获取更多详细信息)。DTR 和 RTS 控制线又连接到 {IDF_TARGET_NAME} 的 ``{IDF_TARGET_STRAP_GPIO}`` 和 ``CHIP_PU`` (EN) 管脚上,因此 DTR 和 RTS 的电压电平变化会使 {IDF_TARGET_NAME} 进入固件下载模式。相关示例可查看 ESP32 DevKitC 开发板的 `原理图 <https://dl.espressif.com/dl/schematics/esp32_devkitc_v4-sch-20180607a.pdf>`_。
|
||||
|
||||
一般来说,使用官方的 esp-idf 开发板不会出现问题。但是,``esptool.py`` 在以下情况下不能自动重置硬件。
|
||||
|
||||
- 您的硬件没有连接到 ``{IDF_TARGET_STRAP_GPIO}`` 和 ``CIHP_PU`` 的 DTR 和 RTS 控制线。
|
||||
- DTR 和 RTS 控制线的配置方式不同
|
||||
- 根本没有这样的串行控制线路
|
||||
|
||||
根据您硬件的种类,也可以将您 {IDF_TARGET_NAME} 开发板手动设置成固件下载模式(复位)。
|
||||
|
||||
- 对于 Espressif 的开发板,您可以参考对应开发板的入门指南或用户指南。例如,可以通过按住 **Boot** 按钮 (``{IDF_TARGET_STRAP_GPIO}``) 再按住 **EN** 按钮(``CHIP_PU``) 来手动复位 esp-idf 开发板。
|
||||
- 对于其他类型的硬件,可以尝试将 ``{IDF_TARGET_STRAP_GPIO}`` 拉低。
|
||||
|
||||
|
||||
常规操作
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
在烧录过程中,您会看到类似如下的输出日志:
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py --chip esp32 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 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 ESP32D0WDQ6 (revision 0)
|
||||
Features: WiFi, BT, Dual Core, Coding Scheme None
|
||||
Crystal is 40MHz
|
||||
MAC: 24:0a:c4:05:b9:14
|
||||
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 5962.8 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 26096 bytes to 15408...
|
||||
Writing at 0x00001000... (100 %)
|
||||
Wrote 26096 bytes (15408 compressed) at 0x00001000 in 0.4 seconds (effective 546.7 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 147104 bytes to 77364...
|
||||
Writing at 0x00010000... (20 %)
|
||||
Writing at 0x00014000... (40 %)
|
||||
Writing at 0x00018000... (60 %)
|
||||
Writing at 0x0001c000... (80 %)
|
||||
Writing at 0x00020000... (100 %)
|
||||
Wrote 147104 bytes (77364 compressed) at 0x00010000 in 1.9 seconds (effective 615.5 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
.. only:: esp32s2
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py --chip esp32s2 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 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
|
||||
Crystal is 40MHz
|
||||
MAC: 18:fe:34:72:50:e3
|
||||
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 3851.6 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 22592 bytes to 13483...
|
||||
Writing at 0x00001000... (100 %)
|
||||
Wrote 22592 bytes (13483 compressed) at 0x00001000 in 0.3 seconds (effective 595.1 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 140048 bytes to 70298...
|
||||
Writing at 0x00010000... (20 %)
|
||||
Writing at 0x00014000... (40 %)
|
||||
Writing at 0x00018000... (60 %)
|
||||
Writing at 0x0001c000... (80 %)
|
||||
Writing at 0x00020000... (100 %)
|
||||
Wrote 140048 bytes (70298 compressed) at 0x00010000 in 1.7 seconds (effective 662.5 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
.. only:: esp32s3
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py esp32s3 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin
|
||||
esptool.py v3.2-dev
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting....
|
||||
Chip is ESP32-S3
|
||||
Features: WiFi, BLE
|
||||
Crystal is 40MHz
|
||||
MAC: 7c:df:a1:e0:00:64
|
||||
Uploading stub...
|
||||
Running stub...
|
||||
Stub running...
|
||||
Changing baud rate to 460800
|
||||
Changed.
|
||||
Configuring flash size...
|
||||
Flash will be erased from 0x00000000 to 0x00004fff...
|
||||
Flash will be erased from 0x00010000 to 0x00039fff...
|
||||
Flash will be erased from 0x00008000 to 0x00008fff...
|
||||
Compressed 18896 bytes to 11758...
|
||||
Writing at 0x00000000... (100 %)
|
||||
Wrote 18896 bytes (11758 compressed) at 0x00000000 in 0.5 seconds (effective 279.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 168208 bytes to 88178...
|
||||
Writing at 0x00010000... (16 %)
|
||||
Writing at 0x0001a80f... (33 %)
|
||||
Writing at 0x000201f1... (50 %)
|
||||
Writing at 0x00025dcf... (66 %)
|
||||
Writing at 0x0002d0be... (83 %)
|
||||
Writing at 0x00036c07... (100 %)
|
||||
Wrote 168208 bytes (88178 compressed) at 0x00010000 in 2.4 seconds (effective 569.2 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 3072 bytes to 103...
|
||||
Writing at 0x00008000... (100 %)
|
||||
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 478.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
|
||||
.. only:: esp32c3
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py --chip esp32c3 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin
|
||||
esptool.py v3.0
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting....
|
||||
Chip is ESP32-C3
|
||||
Features: Wi-Fi
|
||||
Crystal is 40MHz
|
||||
MAC: 7c:df:a1:40:02:a4
|
||||
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 4238.1 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 18960 bytes to 11311...
|
||||
Writing at 0x00000000... (100 %)
|
||||
Wrote 18960 bytes (11311 compressed) at 0x00000000 in 0.3 seconds (effective 584.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 145520 bytes to 71984...
|
||||
Writing at 0x00010000... (20 %)
|
||||
Writing at 0x00014000... (40 %)
|
||||
Writing at 0x00018000... (60 %)
|
||||
Writing at 0x0001c000... (80 %)
|
||||
Writing at 0x00020000... (100 %)
|
||||
Wrote 145520 bytes (71984 compressed) at 0x00010000 in 2.3 seconds (effective 504.4 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
|
||||
如果一切顺利,烧录完成后,开发板将会复位,应用程序 "hello_world" 开始运行。
|
||||
|
||||
如果您希望使用 Eclipse 或是 VS Code IDE,而非 ``idf.py``,请参考 :doc:`Eclipse 指南 <eclipse-setup>`,以及 :doc:`VS Code 指南 <vscode-setup>`。
|
||||
|
||||
|
||||
.. _get-started-build-monitor:
|
||||
|
||||
第十步:监视器
|
||||
===============
|
||||
|
||||
您可以使用 ``idf.py -p PORT monitor`` 命令,监视 “hello_world” 工程的运行情况。注意,不要忘记将 PORT 替换为您的串口名称。
|
||||
|
||||
运行该命令后,:doc:`IDF 监视器 <../api-guides/tools/idf-monitor>` 应用程序将启动:::
|
||||
|
||||
$ idf.py -p /dev/ttyUSB0 monitor
|
||||
Running idf_monitor in directory [...]/esp/hello_world/build
|
||||
Executing "python [...]/esp-idf/tools/idf_monitor.py -b 115200 [...]/esp/hello_world/build/hello_world.elf"...
|
||||
--- idf_monitor on /dev/ttyUSB0 115200 ---
|
||||
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
ets Jun 8 2016 00:22:57
|
||||
...
|
||||
|
||||
此时,您就可以在启动日志和诊断日志之后,看到打印的 “Hello world!” 了。
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
Hello world!
|
||||
Restarting in 10 seconds...
|
||||
This is {IDF_TARGET_PATH_NAME} chip with {IDF_TARGET_CORE_NUM} CPU core(s), {IDF_TARGET_FEATURES}
|
||||
Minimum free heap size: {IDF_TARGET_HEAP_SIZE} bytes
|
||||
Restarting in 9 seconds...
|
||||
Restarting in 8 seconds...
|
||||
Restarting in 7 seconds...
|
||||
|
||||
您可使用快捷键 ``Ctrl+]``,退出 IDF 监视器。
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
如果 IDF 监视器在烧录后很快发生错误,或打印信息全是乱码(如下),很有可能是因为您的开发板采用了 26 MHz 晶振,而 ESP-IDF 默认支持大多数开发板使用的 40 MHz 晶振。
|
||||
|
||||
.. figure:: ../../_static/get-started-garbled-output.png
|
||||
:align: center
|
||||
:alt: 乱码输出
|
||||
:figclass: align-center
|
||||
|
||||
此时,您可以:
|
||||
|
||||
1. 退出监视器。
|
||||
2. 打开 :ref:`menuconfig <get-started-configure>`。
|
||||
3. 进入 ``Component config`` --> ``ESP32-specific`` --> ``Main XTAL frequency`` 进行配置,将 :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` 设置为 26 MHz。
|
||||
4. 然后,请重新 :ref:`编译和烧录 <get-started-flash>` 应用程序。
|
||||
|
||||
.. note::
|
||||
|
||||
您也可以运行以下命令,一次性执行构建、烧录和监视过程:
|
||||
|
||||
``idf.py -p PORT flash monitor``
|
||||
|
||||
.. only:: esp32s3
|
||||
|
||||
.. note::
|
||||
|
||||
如果带有八线 flash 的开发板在二级引导加载程序之前复位,请参考 :ref:`八线 flash 错误处理 <flash-psram-error>`。
|
||||
|
||||
此外,
|
||||
|
||||
- 请前往 :doc:`IDF 监视器 <../api-guides/tools/idf-monitor>`,了解更多使用 IDF 监视器的快捷键和其他详情。
|
||||
- 请前往 :ref:`idf.py`,查看更多 ``idf.py`` 命令和选项。
|
||||
|
||||
**恭喜,您已完成 {IDF_TARGET_NAME} 的入门学习!**
|
||||
|
||||
现在,您可以尝试一些其他 :idf:`examples`,或者直接开发自己的应用程序。
|
||||
|
||||
.. 重要::
|
||||
|
||||
一些示例程序不支持 {IDF_TARGET_NAME},因为 {IDF_TARGET_NAME} 中不包含所需的硬件。
|
||||
|
||||
在编译示例程序前请查看 README 文件中 ``Supported Targets`` 表格。如果表格中包含 {IDF_TARGET_NAME}, 或者不存在这个表格,那么即表示 {IDF_TARGET_NAME} 支持这个示例程序。
|
||||
|
||||
|
||||
更新 ESP-IDF
|
||||
================
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
Windows Installer <windows-setup>
|
||||
Linux <linux-macos-setup>
|
||||
macOS <linux-macos-setup>
|
||||
|
||||
乐鑫会不时推出更新版本的 ESP-IDF,修复 bug 或提供新的功能。因此,您在使用时,也应注意更新您本地的版本。最简单的方法是:直接删除您本地的 ``esp-idf`` 文件夹,然后按照 :ref:`get-started-get-esp-idf` 中的指示,重新完成克隆。
|
||||
|
||||
此外,您可以仅更新变更部分。具体方式,请前往 :ref:`更新 <updating>` 章节查看。
|
||||
|
||||
注意,更新完成后,请再次运行安装脚本,以防新版 ESP-IDF 所需的工具也有所更新。具体请参考 :ref:`get-started-set-up-tools`。
|
||||
|
||||
一旦重新安装好工具,请使用导出脚本更新环境,具体请参考 :ref:`get-started-set-up-env`。
|
||||
|
||||
相关文档
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
establish-serial-connection
|
||||
eclipse-setup
|
||||
vscode-setup
|
||||
../api-guides/tools/idf-monitor
|
||||
|
||||
.. _Stable version: https://docs.espressif.com/projects/esp-idf/zh_CN/stable/
|
||||
.. _Releases page: https://github.com/espressif/esp-idf/releases
|
||||
Manual <linux-macos-setup>
|
||||
|
@@ -1,13 +1,36 @@
|
||||
*********************************************
|
||||
Linux 平台工具链的标准设置
|
||||
Linux 和 macOS 平台工具链的标准设置
|
||||
*********************************************
|
||||
|
||||
:link_to_translation:`en:[English]`
|
||||
|
||||
安装准备
|
||||
=====================
|
||||
详细安装步骤
|
||||
=========================
|
||||
|
||||
编译 ESP-IDF 需要以下软件包。请根据使用的系统,选择合适的安装命令,如下所示:
|
||||
请根据下方详细步骤,完成安装过程。
|
||||
|
||||
设置开发环境
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
以下是为 {IDF_TARGET_NAME} 设置 ESP-IDF 的具体步骤。
|
||||
|
||||
* :ref:`get-started-prerequisites`
|
||||
* :ref:`get-started-get-esp-idf`
|
||||
* :ref:`get-started-set-up-tools`
|
||||
* :ref:`get-started-set-up-env`
|
||||
* :ref:`get-started-start-a-project`
|
||||
|
||||
.. _get-started-prerequisites:
|
||||
|
||||
第一步:安装准备
|
||||
=============================
|
||||
|
||||
为了在 {IDF_TARGET_NAME} 中使用 ESP-IDF,需要根据操作系统安装一些软件包。以下安装指南可协助您安装 Linux 和 macOS 的系统上所有需要的软件包。
|
||||
|
||||
Linux 用户
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
编译 ESP-IDF 需要以下软件包。请根据使用的 Linux 发行版本,选择合适的安装命令。
|
||||
|
||||
- Ubuntu 和 Debian::
|
||||
|
||||
@@ -25,25 +48,200 @@ Linux 平台工具链的标准设置
|
||||
|
||||
.. note::
|
||||
- 使用 ESP-IDF 需要 CMake 3.5 或以上版本。较早的 Linux 发行版可能需要升级自身的软件源仓库,或开启 backports 套件库,或安装 "cmake3" 软件包(不是安装 "cmake")。
|
||||
- 如果上述列表中,并没有您使用的系统,请参考您所用系统的相关文档,查看安装软件包所用的命令。
|
||||
- 如果上述列表中没有您使用的系统,请参考您所用系统的相关文档,查看安装软件包所用的命令。
|
||||
|
||||
其他提示
|
||||
===============
|
||||
macOS 用户
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
权限问题 /dev/ttyUSB0
|
||||
------------------------------------------------------------
|
||||
ESP-IDF 将使用 macOS 上默认安装的 Python 版本。
|
||||
|
||||
使用某些 Linux 版本向 {IDF_TARGET_NAME} 烧录固件时,可能会出现 ``Failed to open port /dev/ttyUSB0`` 错误消息。此时可以将用户添加至 :ref:`Linux Dialout 组<linux-dialout-group>`。
|
||||
- 安装 pip::
|
||||
|
||||
兼容的 Python 版本
|
||||
sudo easy_install pip
|
||||
|
||||
- 安装 CMake 和 Ninja 编译工具:
|
||||
|
||||
- 若有 HomeBrew_,您可以运行::
|
||||
|
||||
brew install cmake ninja dfu-util
|
||||
|
||||
- 若有 MacPorts_,您可以运行::
|
||||
|
||||
sudo port install cmake ninja dfu-util
|
||||
|
||||
- 若以上均不适用,请访问 CMake_ 和 Ninja_ 主页,查询有关 macOS 平台的下载安装问题。
|
||||
|
||||
- 强烈建议同时安装 ccache_ 以获得更快的编译速度。如有 HomeBrew_,可通过 MacPorts_ 上的 ``brew install ccache`` 或 ``sudo port install ccache`` 完成安装。
|
||||
|
||||
.. note::
|
||||
如您在上述任何步骤中遇到以下错误::
|
||||
|
||||
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
|
||||
|
||||
则必须安装 XCode 命令行工具,可运行 ``xcode-select --install`` 命令进行安装。
|
||||
|
||||
安装 Python 3
|
||||
---------------------------------------------
|
||||
|
||||
`Catalina 10.15 发布说明`_ 中表示不推荐使用 Python 2.7 版本,在未来的 macOS 版本中也不会默认包含 Python 2.7。执行以下命令来检查您当前使用的 Python 版本::
|
||||
|
||||
python --version
|
||||
|
||||
如果输出结果是 ``Python 2.7.17``,则代表您的默认解析器是 Python 2.7。这时需要您运行以下命令检查电脑上是否已经安装过 Python 3::
|
||||
|
||||
python3 --version
|
||||
|
||||
如果运行上述命令出现错误,则代表电脑上没有安装 Python 3。
|
||||
|
||||
请根据以下步骤安装 Python 3:
|
||||
|
||||
- 使用 HomeBrew_ 进行安装的方法如下::
|
||||
|
||||
brew install python3
|
||||
|
||||
- 使用 MacPorts_ 进行安装的方法如下::
|
||||
|
||||
sudo port install python38
|
||||
|
||||
.. _get-started-get-esp-idf:
|
||||
|
||||
第二步:获取 ESP-IDF
|
||||
=================================
|
||||
|
||||
ESP-IDF 支持 Python 3.7 及以上版本,建议升级操作系统到最新版本从而更新 Python。也可选择从 `sources <https://www.python.org/downloads/>`_ 安装最新版 Python,或使用 Python 管理系统如 `pyenv <https://github.com/pyenv/pyenv>`_ 对版本进行升级管理。
|
||||
在围绕 {IDF_TARGET_NAME} 构建应用程序之前,请先获取乐鑫提供的软件库文件 `ESP-IDF 仓库 <https://github.com/espressif/esp-idf>`_。
|
||||
|
||||
后续步骤
|
||||
==========
|
||||
获取 ESP-IDF 的本地副本:打开终端,切换到您要保存 ESP-IDF 的工作目录,使用 ``git clone`` 命令克隆远程仓库。针对不同操作系统的详细步骤,请见下文。
|
||||
|
||||
继续设置开发环境,请前往 :ref:`get-started-get-esp-idf` 章节。
|
||||
打开终端,运行以下命令:
|
||||
|
||||
.. include-build-file:: inc/git-clone-bash.inc
|
||||
|
||||
ESP-IDF 将下载至 ``~/esp/esp-idf``。
|
||||
|
||||
请前往 :doc:`/versions`,查看 ESP-IDF 不同版本的具体适用场景。
|
||||
|
||||
.. _get-started-set-up-tools:
|
||||
|
||||
第三步:设置工具
|
||||
=================================
|
||||
|
||||
除了 ESP-IDF 本身,您还需要安装 ESP-IDF 使用的各种工具,比如编译器、调试器、Python 包等。
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
./install.sh {IDF_TARGET_PATH_NAME}
|
||||
|
||||
或使用 Fish shell:
|
||||
|
||||
.. code-block:: fish
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
./install.fish {IDF_TARGET_PATH_NAME}
|
||||
|
||||
.. note::
|
||||
通过一次性指定多个目标,可为多个目标芯片同时安装工具,如运行 ``./install.sh esp32,esp32c3,esp32s3``。
|
||||
通过运行 ``./install.sh`` 或 ``./install.sh all`` 可一次性为所有支持的目标芯片安装工具。
|
||||
|
||||
下载工具备选方案
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
ESP-IDF 工具安装器会下载 Github 发布版本中附带的一些工具,如果访问 Github 较为缓慢,可以设置一个环境变量,从而优先选择 Espressif 的下载服务器进行 Github 资源下载。
|
||||
|
||||
.. 注解:: 该设置只影响从 Github 发布版本中下载的单个工具,它并不会改变访问任何 Git 仓库的 URL。
|
||||
|
||||
要在安装工具时优先选择 Espressif 下载服务器,请在运行 ``install.sh`` 时使用以下命令:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/esp-idf
|
||||
export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets"
|
||||
./install.sh
|
||||
|
||||
自定义工具安装路径
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
本步骤中介绍的脚本将 ESP-IDF 所需的编译工具默认安装在用户的根目录中,即 Linux 系统中的 ``$HOME/.espressif`` 目录。您可以选择将工具安装到其他目录中,但请在运行安装脚本前,重新设置环境变量 ``IDF_TOOLS_PATH``。注意,请确保您的用户账号已经具备了读写该路径的权限。
|
||||
|
||||
如果修改了 ``IDF_TOOLS_PATH`` 变量,请确保该变量在每次执行安装脚本 (``install.bat``、``install.ps1`` 或 ``install.sh``) 和导出脚本 (``export.bat``、``export.ps1`` 或 ``export.sh``) 均保持一致。
|
||||
|
||||
.. _get-started-set-up-env:
|
||||
|
||||
第四步:设置环境变量
|
||||
=======================================
|
||||
|
||||
此时,您刚刚安装的工具尚未添加至 PATH 环境变量,无法通过“命令窗口”使用这些工具。因此,必须设置一些环境变量。这可以通过 ESP-IDF 提供的另一个脚本进行设置。
|
||||
|
||||
请在需要运行 ESP-IDF 的终端窗口运行以下命令:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
. $HOME/esp/esp-idf/export.sh
|
||||
|
||||
对于 fish shell(仅支持 fish 3.0.0 及以上版本),请运行以下命令:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
. $HOME/esp/esp-idf/export.fish
|
||||
|
||||
注意,命令开始的 "." 与路径之间应有一个空格!
|
||||
|
||||
如果您需要经常运行 ESP-IDF,您可以为执行 ``export.sh`` 创建一个别名,具体步骤如下:
|
||||
|
||||
1. 复制并粘贴以下命令到 shell 配置文件中(``.profile``、``.bashrc``、``.zprofile`` 等)
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
alias get_idf='. $HOME/esp/esp-idf/export.sh'
|
||||
|
||||
2. 通过重启终端窗口或运行 ``source [path to profile]``,如 ``source ~/.bashrc`` 来刷新配置文件。
|
||||
|
||||
现在您可以在任何终端窗口中运行 ``get_idf`` 来设置或刷新 esp-idf 环境。
|
||||
|
||||
不建议直接将 ``export.sh`` 添加到 shell 的配置文件。这样做会导致在每个终端会话中都激活 IDF 虚拟环境(包括无需使用 IDF 的会话)。这违背了使用虚拟环境的目的,还可能影响其他软件的使用。
|
||||
|
||||
.. _get-started-start-a-project:
|
||||
.. _get-started-build:
|
||||
.. _get-started-configure:
|
||||
.. _get-started-connect:
|
||||
.. _get-started-first-steps:
|
||||
|
||||
第五步:开始使用 ESP-IDF 吧
|
||||
========================================
|
||||
|
||||
.. include:: start-project.rst
|
||||
|
||||
建议:更新 ESP-IDF
|
||||
======================
|
||||
|
||||
乐鑫会不时推出新版本的 ESP-IDF,修复 bug 或提供新的功能。请注意,EESP-IDF 的每个主要版本和次要版本都有相应的支持期限。支持期限满后,版本停止更新维护,用户可将项目升级到最新的 ESP-IDF 版本。更多关于支持期限的信息,请参考 :doc:`ESP-IDF 版本 <../versions>`。
|
||||
|
||||
因此,您在使用时,也应注意更新您本地的版本。最简单的方法是:直接删除您本地的 ``esp-idf`` 文件夹,然后按照 :ref:`get-started-get-esp-idf` 中的指示,重新完成克隆。
|
||||
|
||||
另一种方法是仅更新变更的部分。具体方式,请前往 :ref:`更新 ESP-IDF <updating>` 章节查看。具体更新步骤会根据您使用的 ESP-IDF 版本有所不同。
|
||||
|
||||
注意,更新完成后,请再次运行安装脚本,以防新版 ESP-IDF 所需的工具也有所更新。具体请参考 :ref:`get-started-set-up-tools`。
|
||||
|
||||
一旦重新安装好工具,请使用导出脚本更新环境,具体请参考 :ref:`get-started-set-up-env`。
|
||||
|
||||
相关文档
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
establish-serial-connection
|
||||
eclipse-setup
|
||||
vscode-setup
|
||||
../api-guides/tools/idf-monitor
|
||||
|
||||
.. _Stable version: https://docs.espressif.com/projects/esp-idf/en/stable/
|
||||
.. _Releases page: https://github.com/espressif/esp-idf/releases
|
||||
.. _AUR: https://wiki.archlinux.org/index.php/Arch_User_Repository
|
||||
.. _First Steps on ESP-IDF: ../get-started/first-steps.html
|
||||
.. _cmake: https://cmake.org/
|
||||
.. _ninja: https://ninja-build.org/
|
||||
.. _ccache: https://ccache.samba.org/
|
||||
.. _homebrew: https://brew.sh/
|
||||
.. _MacPorts: https://www.macports.org/install.php
|
||||
.. _Catalina 10.15 发布说明: https://developer.apple.com/documentation/macos-release-notes/macos-catalina-10_15-release-notes
|
||||
|
@@ -1,3 +1,437 @@
|
||||
************************
|
||||
First Steps with ESP-IDF
|
||||
************************
|
||||
{IDF_TARGET_CORE_NUM:default="2", esp32s2="1", esp32c3="1"}
|
||||
|
||||
{IDF_TARGET_FEATURES:default="WiFi/BT/BLE, silicon revision 1, 2MB external flash", esp32="WiFi/BT/BLE, silicon revision 1, 2MB external flash", esp32s2="WiFi, silicon revision 0, 2MB external flash", esp32s3="This is esp32s3 chip with 2 CPU core(s), WiFi/BLE, silicon revision 0, 2MB external flash", esp32c3="WiFi/BLE, silicon revision 0, 2MB external flash"}
|
||||
|
||||
{IDF_TARGET_HEAP_SIZE:default="298968", esp32="298968", esp32s2="253900", esp32s3="390684", esp32c3="337332"}
|
||||
|
||||
现在您已经具备了使用 ESP-IDF 的所有条件,接下来将介绍如何开始您的第一个工程。
|
||||
|
||||
本指南将帮助您完成使用 ESP-IDF 的第一步。按照本指南,您将能够创建第一个工程、连接 {IDF_TARGET_NAME}、改变工程的配置,构建、烧录并监控该工程。
|
||||
|
||||
.. note::
|
||||
|
||||
如果您还没有安装 ESP-IDF,请前往 :ref:`get-started-step-by-step` 并按照说明操作,以获得使用本指南所需的所有软件。
|
||||
|
||||
开始创建工程
|
||||
================
|
||||
|
||||
现在,您可以开始准备开发 {IDF_TARGET_NAME} 应用程序了。您可以从 ESP-IDF 中 :idf:`examples` 目录下的 :example:`get-started/hello_world` 工程开始。
|
||||
|
||||
.. important::
|
||||
|
||||
ESP-IDF 编译系统不支持 ESP-IDF 路径或其工程路径中带有空格。
|
||||
|
||||
将 :example:`get-started/hello_world` 工程复制至您本地的 ``~/esp`` 目录下:
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp
|
||||
xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp
|
||||
cp -r $IDF_PATH/examples/get-started/hello_world .
|
||||
|
||||
.. note:: ESP-IDF 的 :idf:`examples` 目录下有一系列示例工程,您可以按照上述方法复制并运行其中的任何示例,也可以直接编译示例,无需进行复制。
|
||||
|
||||
连接设备
|
||||
==============
|
||||
|
||||
现在,请将您的 {IDF_TARGET_NAME} 开发板连接到 PC,并查看开发板使用的串口。
|
||||
|
||||
通常,串口在不同操作系统下显示的名称有所不同:
|
||||
|
||||
- **Windows 操作系统:** ``COM1`` 等
|
||||
- **Linux 操作系统:** 以 ``/dev/tty`` 开始
|
||||
- **macOS 操作系统:** 以 ``/dev/cu.`` 开始
|
||||
|
||||
有关如何查看串口名称的详细信息,请见 :doc:`establish-serial-connection`。
|
||||
|
||||
.. note::
|
||||
|
||||
请记住串口名,您会在后续步骤中使用。
|
||||
|
||||
配置工程
|
||||
=============
|
||||
|
||||
请进入 ``hello_world`` 目录,设置 {IDF_TARGET_NAME} 为目标芯片,然后运行工程配置工具 ``menuconfig``。
|
||||
|
||||
Windows 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp\hello_world
|
||||
idf.py set-target {IDF_TARGET_PATH_NAME}
|
||||
idf.py menuconfig
|
||||
|
||||
Linux 和 macOS 操作系统
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/hello_world
|
||||
idf.py set-target {IDF_TARGET_PATH_NAME}
|
||||
idf.py menuconfig
|
||||
|
||||
打开一个新工程后,应首先使用 ``idf.py set-target {IDF_TARGET_PATH_NAME}`` 设置“目标”芯片。注意,此操作将清除并初始化项目之前的编译和配置(如有)。 您也可以直接将“目标”配置为环境变量(此时可跳过该步骤)。更多信息,请见 :ref:`selecting-idf-target`。
|
||||
|
||||
如果之前的步骤都正确,则会显示下面的菜单:
|
||||
|
||||
.. figure:: ../../_static/project-configuration.png
|
||||
:align: center
|
||||
:alt: 工程配置 — 主窗口
|
||||
:figclass: align-center
|
||||
|
||||
工程配置 — 主窗口
|
||||
|
||||
您可以通过此菜单设置项目的具体变量,包括 Wi-Fi 网络名称、密码和处理器速度等。``hello_world`` 示例项目会以默认配置运行,因此可以跳过使用 ``menuconfig`` 进行项目配置这一步骤。
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. attention::
|
||||
|
||||
如果您使用的是 ESP32-DevKitC(板载 ESP32-SOLO-1 模组)或 ESP32-DevKitM-1(板载 ESP32-MINI-1(1U) 模组),请在烧写示例程序前,前往 ``menuconfig`` 中使能单核模式(:ref:`CONFIG_FREERTOS_UNICORE`)。
|
||||
|
||||
.. note::
|
||||
|
||||
您终端窗口中显示出的菜单颜色可能会与上图不同。您可以通过选项 ``--style`` 来改变外观。请运行 ``idf.py menuconfig --help`` 命令,获取更多信息。
|
||||
|
||||
编译工程
|
||||
=========================
|
||||
|
||||
请使用以下命令,编译烧录工程:
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
idf.py build
|
||||
|
||||
运行以上命令可以编译应用程序和所有 ESP-IDF 组件,接着生成引导加载程序、分区表和应用程序二进制文件。
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
$ idf.py build
|
||||
Running cmake in directory /path/to/hello_world/build
|
||||
Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"...
|
||||
Warn about uninitialized values.
|
||||
-- Found Git: /usr/bin/git (found version "2.17.0")
|
||||
-- Building empty aws_iot component due to configuration
|
||||
-- Component names: ...
|
||||
-- Component paths: ...
|
||||
|
||||
... (more lines of build system output)
|
||||
|
||||
[527/527] Generating hello_world.bin
|
||||
esptool.py v2.3.1
|
||||
|
||||
Project build complete. To flash, run this command:
|
||||
../../../components/esptool_py/esptool/esptool.py -p (PORT) -b 921600 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x10000 build/hello_world.bin build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin
|
||||
or run 'idf.py -p PORT flash'
|
||||
|
||||
如果一切正常,编译完成后将生成 .bin 文件。
|
||||
|
||||
|
||||
烧录到设备
|
||||
=============================
|
||||
|
||||
请使用以下命令,将刚刚生成的二进制文件 (bootloader.bin、partition-table.bin 和 hello_world.bin) 烧录至您的 {IDF_TARGET_NAME} 开发板:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
idf.py -p PORT [-b BAUD] flash
|
||||
|
||||
请将 PORT 替换为 {IDF_TARGET_NAME} 开发板的串口名称。
|
||||
|
||||
您还可以将 BAUD 替换为您希望的烧录波特率。默认波特率为 ``460800``。
|
||||
|
||||
更多有关 idf.py 参数的详情,请见 :ref:`idf.py`。
|
||||
|
||||
.. note::
|
||||
|
||||
勾选 ``flash`` 选项将自动编译并烧录工程,因此无需再运行 ``idf.py build``。
|
||||
|
||||
烧录过程中可能遇到的问题
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
{IDF_TARGET_STRAP_GPIO:default="GPIO0", esp32="GPIO0", esp32s2="GPIO0", esp32s3="GPIO0", esp32c3="GPIO9"}
|
||||
|
||||
如果在运行给定命令时出现如“连接失败”这样的错误,造成该错误的原因之一可能是运行 ``esptool.py`` 时出现错误。``esptool.py`` 是构建系统调用的程序,用于重置芯片、与 ROM 引导加载器交互以及烧录固件的工具。可以按照以下步骤进行手动复位,轻松解决该问题。如果问题仍未解决,请参考 `Troubleshooting <https://github.com/espressif/esptool#bootloader-wont-respond>`_. 获取更多信息。
|
||||
|
||||
``esptool.py`` 通过使 USB 转串口转接器芯片(如 FTDI 或 CP210x)的 DTR 和 RTS 控制线生效来自动复位 {IDF_TARGET_NAME}(请参考 :doc:`establish-serial-connection` 获取更多详细信息)。DTR 和 RTS 控制线又连接到 {IDF_TARGET_NAME} 的 ``{IDF_TARGET_STRAP_GPIO}`` 和 ``CHIP_PU`` (EN) 管脚上,因此 DTR 和 RTS 的电压电平变化会使 {IDF_TARGET_NAME} 进入固件下载模式。相关示例可查看 ESP32 DevKitC 开发板的 `原理图 <https://dl.espressif.com/dl/schematics/esp32_devkitc_v4-sch-20180607a.pdf>`_。
|
||||
|
||||
一般来说,使用官方的 ESP-IDF 开发板不会出现问题。但是,``esptool.py`` 在以下情况下不能自动重置硬件。
|
||||
|
||||
- 您的硬件没有连接到 ``{IDF_TARGET_STRAP_GPIO}`` 和 ``CIHP_PU`` 的 DTR 和 RTS 控制线。
|
||||
- DTR 和 RTS 控制线的配置方式不同
|
||||
- 根本没有这样的串行控制线路
|
||||
|
||||
根据您硬件的种类,也可以将您 {IDF_TARGET_NAME} 开发板手动设置成固件下载模式(复位)。
|
||||
|
||||
- 对于 Espressif 的开发板,您可以参考对应开发板的入门指南或用户指南。例如,可以通过按住 **Boot** 按钮 (``{IDF_TARGET_STRAP_GPIO}``) 再按住 **EN** 按钮(``CHIP_PU``) 来手动复位 ESP-IDF 开发板。
|
||||
- 对于其他类型的硬件,可以尝试将 ``{IDF_TARGET_STRAP_GPIO}`` 拉低。
|
||||
|
||||
常规操作
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
在烧录过程中,您会看到类似如下的输出日志:
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py --chip esp32 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 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 ESP32D0WDQ6 (revision 0)
|
||||
Features: WiFi, BT, Dual Core, Coding Scheme None
|
||||
Crystal is 40MHz
|
||||
MAC: 24:0a:c4:05:b9:14
|
||||
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 5962.8 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 26096 bytes to 15408...
|
||||
Writing at 0x00001000... (100 %)
|
||||
Wrote 26096 bytes (15408 compressed) at 0x00001000 in 0.4 seconds (effective 546.7 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 147104 bytes to 77364...
|
||||
Writing at 0x00010000... (20 %)
|
||||
Writing at 0x00014000... (40 %)
|
||||
Writing at 0x00018000... (60 %)
|
||||
Writing at 0x0001c000... (80 %)
|
||||
Writing at 0x00020000... (100 %)
|
||||
Wrote 147104 bytes (77364 compressed) at 0x00010000 in 1.9 seconds (effective 615.5 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
.. only:: esp32s2
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py --chip esp32s2 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 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
|
||||
Crystal is 40MHz
|
||||
MAC: 18:fe:34:72:50:e3
|
||||
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 3851.6 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 22592 bytes to 13483...
|
||||
Writing at 0x00001000... (100 %)
|
||||
Wrote 22592 bytes (13483 compressed) at 0x00001000 in 0.3 seconds (effective 595.1 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 140048 bytes to 70298...
|
||||
Writing at 0x00010000... (20 %)
|
||||
Writing at 0x00014000... (40 %)
|
||||
Writing at 0x00018000... (60 %)
|
||||
Writing at 0x0001c000... (80 %)
|
||||
Writing at 0x00020000... (100 %)
|
||||
Wrote 140048 bytes (70298 compressed) at 0x00010000 in 1.7 seconds (effective 662.5 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
.. only:: esp32s3
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py esp32s3 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin
|
||||
esptool.py v3.2-dev
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting....
|
||||
Chip is ESP32-S3
|
||||
Features: WiFi, BLE
|
||||
Crystal is 40MHz
|
||||
MAC: 7c:df:a1:e0:00:64
|
||||
Uploading stub...
|
||||
Running stub...
|
||||
Stub running...
|
||||
Changing baud rate to 460800
|
||||
Changed.
|
||||
Configuring flash size...
|
||||
Flash will be erased from 0x00000000 to 0x00004fff...
|
||||
Flash will be erased from 0x00010000 to 0x00039fff...
|
||||
Flash will be erased from 0x00008000 to 0x00008fff...
|
||||
Compressed 18896 bytes to 11758...
|
||||
Writing at 0x00000000... (100 %)
|
||||
Wrote 18896 bytes (11758 compressed) at 0x00000000 in 0.5 seconds (effective 279.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 168208 bytes to 88178...
|
||||
Writing at 0x00010000... (16 %)
|
||||
Writing at 0x0001a80f... (33 %)
|
||||
Writing at 0x000201f1... (50 %)
|
||||
Writing at 0x00025dcf... (66 %)
|
||||
Writing at 0x0002d0be... (83 %)
|
||||
Writing at 0x00036c07... (100 %)
|
||||
Wrote 168208 bytes (88178 compressed) at 0x00010000 in 2.4 seconds (effective 569.2 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 3072 bytes to 103...
|
||||
Writing at 0x00008000... (100 %)
|
||||
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 478.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
|
||||
.. only:: esp32c3
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
esptool.py --chip esp32c3 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin
|
||||
esptool.py v3.0
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting....
|
||||
Chip is ESP32-C3
|
||||
Features: Wi-Fi
|
||||
Crystal is 40MHz
|
||||
MAC: 7c:df:a1:40:02:a4
|
||||
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 4238.1 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 18960 bytes to 11311...
|
||||
Writing at 0x00000000... (100 %)
|
||||
Wrote 18960 bytes (11311 compressed) at 0x00000000 in 0.3 seconds (effective 584.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 145520 bytes to 71984...
|
||||
Writing at 0x00010000... (20 %)
|
||||
Writing at 0x00014000... (40 %)
|
||||
Writing at 0x00018000... (60 %)
|
||||
Writing at 0x0001c000... (80 %)
|
||||
Writing at 0x00020000... (100 %)
|
||||
Wrote 145520 bytes (71984 compressed) at 0x00010000 in 2.3 seconds (effective 504.4 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
Done
|
||||
|
||||
|
||||
如果一切顺利,烧录完成后,开发板将会复位,应用程序 "hello_world" 开始运行。
|
||||
|
||||
如果您希望使用 Eclipse 或是 VS Code IDE,而非 ``idf.py``,请参考 :doc:`Eclipse 指南 <eclipse-setup>`,以及 :doc:`VS Code 指南 <vscode-setup>`。
|
||||
|
||||
监视输出
|
||||
===============
|
||||
|
||||
您可以使用 ``idf.py -p PORT monitor`` 命令,监视 “hello_world” 工程的运行情况。注意,不要忘记将 PORT 替换为您的串口名称。
|
||||
|
||||
运行该命令后,:doc:`IDF 监视器 <../api-guides/tools/idf-monitor>` 应用程序将启动:::
|
||||
|
||||
$ idf.py -p <PORT> monitor
|
||||
Running idf_monitor in directory [...]/esp/hello_world/build
|
||||
Executing "python [...]/esp-idf/tools/idf_monitor.py -b 115200 [...]/esp/hello_world/build/hello_world.elf"...
|
||||
--- idf_monitor on <PORT> 115200 ---
|
||||
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
ets Jun 8 2016 00:22:57
|
||||
...
|
||||
|
||||
此时,您就可以在启动日志和诊断日志之后,看到打印的 “Hello world!” 了。
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
...
|
||||
Hello world!
|
||||
Restarting in 10 seconds...
|
||||
This is {IDF_TARGET_PATH_NAME} chip with {IDF_TARGET_CORE_NUM} CPU core(s), {IDF_TARGET_FEATURES}
|
||||
Minimum free heap size: {IDF_TARGET_HEAP_SIZE} bytes
|
||||
Restarting in 9 seconds...
|
||||
Restarting in 8 seconds...
|
||||
Restarting in 7 seconds...
|
||||
|
||||
您可使用快捷键 ``Ctrl+]``,退出 IDF 监视器。
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
如果 IDF 监视器在烧录后很快发生错误,或打印信息全是乱码(如下),很有可能是因为您的开发板采用了 26 MHz 晶振,而 ESP-IDF 默认支持大多数开发板使用的 40 MHz 晶振。
|
||||
|
||||
.. figure:: ../../_static/get-started-garbled-output.png
|
||||
:align: center
|
||||
:alt: 乱码输出
|
||||
:figclass: align-center
|
||||
|
||||
此时,您可以:
|
||||
|
||||
1. 退出监视器。
|
||||
2. 返回 `menuconfig`。
|
||||
3. 进入 ``Component config`` --> ``ESP32-specific`` --> ``Main XTAL frequency`` 进行配置,将 :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` 设置为 26 MHz。
|
||||
4. 重新 `编译和烧录` 应用程序。
|
||||
|
||||
.. note::
|
||||
|
||||
您也可以运行以下命令,一次性执行构建、烧录和监视过程:
|
||||
|
||||
``idf.py -p PORT flash monitor``
|
||||
|
||||
此外,
|
||||
|
||||
- 请前往 :doc:`IDF 监视器 <../api-guides/tools/idf-monitor>`,了解更多使用 IDF 监视器的快捷键和其他详情。
|
||||
- 请前往 :ref:`idf.py`,查看更多 ``idf.py`` 命令和选项。
|
||||
|
||||
**恭喜,您已完成 {IDF_TARGET_NAME} 的入门学习!**
|
||||
|
||||
现在,您可以尝试一些其他 :idf:`examples`,或者直接开发自己的应用程序。
|
||||
|
||||
.. 重要::
|
||||
|
||||
一些示例程序不支持 {IDF_TARGET_NAME},因为 {IDF_TARGET_NAME} 中不包含所需的硬件。
|
||||
|
||||
在编译示例程序前请查看 README 文件中 ``Supported Targets`` 表格。如果表格中包含 {IDF_TARGET_NAME}, 或者不存在这个表格,那么即表示 {IDF_TARGET_NAME} 支持这个示例程序。
|
||||
|
||||
|
||||
其他提示
|
||||
===============
|
||||
|
||||
权限问题 /dev/ttyUSB0
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
使用某些 Linux 版本向 {IDF_TARGET_NAME} 烧录固件时,可能会出现 ``Failed to open port /dev/ttyUSB0`` 错误消息。此时可以将用户添加至 :ref:`Linux Dialout 组<linux-dialout-group>`。
|
||||
|
||||
兼容的 Python 版本
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
ESP-IDF 支持 Python 3.6 及以上版本,建议升级操作系统到最新版本从而更新 Python。也可选择从 `sources <https://www.python.org/downloads/>`_ 安装最新版 Python,或使用 Python 管理系统如 `pyenv <https://github.com/pyenv/pyenv>`_ 对版本进行升级管理。
|
||||
|
@@ -24,17 +24,27 @@ ESP-IDF 需要安装一些必备工具,才能围绕 {IDF_TARGET_NAME} 构建
|
||||
ESP-IDF 工具安装器
|
||||
=======================
|
||||
|
||||
安装 ESP-IDF 必备工具最简易的方式是从 https://dl.espressif.com/dl/esp-idf/?idf=4.4 中下载 ESP-IDF 工具安装器。
|
||||
安装 ESP-IDF 必备工具最简易的方式是下载一个 ESP-IDF 工具安装器。
|
||||
|
||||
+-------------------+--------------------------------+
|
||||
| |download-logo| | `Windows Installer Download`_ |
|
||||
+-------------------+--------------------------------+
|
||||
|
||||
.. |download-logo| image:: ../../_static/logo_windows_install.png
|
||||
:target: https://dl.espressif.com/dl/esp-idf/?idf=4.4
|
||||
|
||||
.. _Windows Installer Download: https://dl.espressif.com/dl/esp-idf/?idf=4.4
|
||||
|
||||
|
||||
在线安装与离线安装的区别
|
||||
-----------------------------------------
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
在线安装程序非常小,可以安装 ESP-IDF 的所有版本。在安装过程中,安装程序只下载必要的依赖文件,包括 `Git For Windows`_ 安装器。在线安装程序会将下载的文件存储在缓存目录 ``%userprofile%/espressif`` 中。
|
||||
|
||||
离线安装程序不需要任何网络连接。安装程序中包含了所有需要的依赖文件,包括 `Git For Windows`_ 安装器。
|
||||
|
||||
安装内容
|
||||
------------
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
安装程序会安装以下组件:
|
||||
|
||||
@@ -47,7 +57,7 @@ ESP-IDF 工具安装器
|
||||
安装程序允许将程序下载到现有的 ESP-IDF 目录。推荐将 ESP-IDF 下载到 ``%userprofile%\Desktop\esp-idf`` 目录下,其中 ``%userprofile%`` 代表家目录。
|
||||
|
||||
启动 ESP-IDF 环境
|
||||
------------------
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
安装结束时,如果勾选了 ``Run ESP-IDF PowerShell Environment`` 或 ``Run ESP-IDF Command Prompt (cmd.exe)``,安装程序会在选定的提示符窗口启动 ESP-IDF。
|
||||
|
||||
@@ -96,10 +106,10 @@ ESP-IDF 工具安装器可在“开始”菜单中,创建一个打开 ESP-IDF
|
||||
|
||||
2. 或者,您可以运行 ``cmd.exe``,并切换至您希望使用的 ESP-IDF 目录,然后运行 ``export.bat``。注意,这种方法要求 ``PATH`` 中存在 Python 和 Git。如果您在使用时遇到有关“找不到 Python 或 Git”的错误信息,请使用第一种方法。
|
||||
|
||||
后续步骤
|
||||
============
|
||||
开始使用 ESP-IDF
|
||||
========================
|
||||
|
||||
当 ESP-IDF 工具安装器安装成功后,开发环境设置也到此结束。后续开发步骤,请前往 :ref:`get-started-start-project` 查看。
|
||||
.. include:: start-project.rst
|
||||
|
||||
相关文档
|
||||
=================
|
||||
@@ -110,8 +120,12 @@ ESP-IDF 工具安装器可在“开始”菜单中,创建一个打开 ESP-IDF
|
||||
:maxdepth: 1
|
||||
|
||||
windows-setup-update
|
||||
establish-serial-connection
|
||||
eclipse-setup
|
||||
vscode-setup
|
||||
../api-guides/tools/idf-monitor
|
||||
|
||||
|
||||
.. _MSYS2: https://www.msys2.org/
|
||||
.. _CMake: https://cmake.org/download/
|
||||
.. _Ninja: https://ninja-build.org/
|
||||
.. _Python: https://www.python.org/downloads/windows/
|
||||
|
@@ -6,7 +6,7 @@ ESP-IDF 编程指南
|
||||
|
||||
.. warning::
|
||||
|
||||
The function API documentation is excluded from the preview. Add docs_full label to the MR to generate the complete documentation.
|
||||
快速预览中不包括 API 函数文档。如需生成完整的文档,请在 MR 中添加 docs_full 标签。
|
||||
|
||||
这里是乐鑫 IoT 开发框架 (`esp-idf <https://github.com/espressif/esp-idf>`_) 的文档中心。ESP-IDF 是 `ESP32、ESP32-S 和 ESP32-C <https://www.espressif.com/en/products/hardware/socs>`_ 系列芯片的官方开发框架。
|
||||
|
||||
@@ -53,18 +53,18 @@ ESP-IDF 编程指南
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
快速入门 <get-started/index>
|
||||
Start a Project <get-started/start-project>
|
||||
API 参考 <api-reference/index>
|
||||
H/W 参考 <hw-reference/index>
|
||||
API 指南 <api-guides/index>
|
||||
ESP-IDF 5.0 迁移指南 <migration-guides/index>
|
||||
Libraries and Frameworks <libraries-and-frameworks/index>
|
||||
贡献代码 <contribute/index>
|
||||
版本 <versions>
|
||||
相关资源 <resources>
|
||||
版权 <COPYRIGHT>
|
||||
关于 <about>
|
||||
Languages/语言 <languages>
|
||||
get-started/index
|
||||
get-started/start-project
|
||||
api-reference/index
|
||||
hw-reference/index
|
||||
api-guides/index
|
||||
migration-guides/index
|
||||
libraries-and-frameworks/index
|
||||
contribute/index
|
||||
versions
|
||||
resources
|
||||
COPYRIGHT
|
||||
about
|
||||
languages
|
||||
|
||||
* :ref:`genindex`
|
||||
|
Reference in New Issue
Block a user