1.Update 8 English cmake files

2.Provide Chinese translation to these 8 cmake files
This commit is contained in:
liying 2018-11-06 12:02:21 +08:00
parent 7d465a5487
commit 08ef71b386
17 changed files with 1051 additions and 10 deletions

View file

@ -1,6 +1,8 @@
Add IDF_PATH & idf.py PATH to User Profile (CMake)
==================================================
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
To use the CMake-based build system and the idf.py tool, two modifications need to be made to system environment variables:
@ -59,7 +61,7 @@ Run the following command to check if ``IDF_PATH`` is set::
The path previously entered in ``~/.profile`` file (or set manually) should be printed out.
To verify idf.py is now on the ``PATH``, you can run the following::
To verify ``idf.py`` is now on the ``PATH``, you can run the following::
which idf.py

View file

@ -2,6 +2,8 @@
Get Started (CMake)
*******************
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
.. include:: ../cmake-pending-features.rst

View file

@ -66,7 +66,7 @@ Build the toolchain::
./ct-ng build
chmod -R u+w builds/xtensa-esp32-elf
Toolchain will be built in ``~/esp/crosstool-NG/builds/xtensa-esp32-elf``. Follow :ref:`instructions for standard setup <setup-linux-toolchain-add-it-to-path-cmake>` to add the toolchain to your ``PATH``.
Toolchain will be built in ``~/esp/crosstool-NG/builds/xtensa-esp32-elf``. Follow `instructions for standard setup <setup-linux-toolchain-add-it-to-path-cmake>`_ to add the toolchain to your ``PATH``.
Next Steps

View file

@ -2,6 +2,8 @@
Standard Setup of Toolchain for Linux (CMake)
*********************************************
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
Install Prerequisites

View file

@ -2,6 +2,8 @@
Setup Toolchain for Mac OS from Scratch (CMake)
***********************************************
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
Package Manager

View file

@ -2,6 +2,8 @@
Standard Setup of Toolchain for Mac OS (CMake)
**********************************************
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
Install Prerequisites

View file

@ -4,6 +4,8 @@
Customized Setup of Toolchain (CMake)
*************************************
:link_to_translation:`zh_CN:[中文]`
Instead of downloading binary toolchain from Espressif website (see :ref:`get-started-setup-toolchain-cmake`) you may build the toolchain yourself.
If you can't think of a reason why you need to build it yourself, then probably it's better to stick with the binary version. However, here are some of the reasons why you might want to compile it from source:

View file

@ -2,6 +2,8 @@
Setup Windows Toolchain from Scratch (CMake)
********************************************
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
This is a step-by-step alternative to running the :doc:`ESP-IDF Tools Installer <windows-setup>` for the CMake-based build system. Installing all of the tools by hand allows more control over the process, and also provides the information for advanced users to customize the install.

View file

@ -2,6 +2,8 @@
Standard Setup of Toolchain for Windows (CMake)
***********************************************
:link_to_translation:`zh_CN:[中文]`
.. include:: ../cmake-warning.rst
.. note::

View file

@ -1 +1,75 @@
.. include:: ../../en/get-started-cmake/add-idf_path-to-profile.rst
在用户配置文件中添加 IDF_PATH 和 idf.py PATH (CMake)
==========================================================================================================
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
使用基于 CMake 的构建系统和 idf.py 工具,用户需修改两处系统环境变量:
- ``IDF_PATH`` 需设置为含有 ESP-IDF 目录的路径
- 系统 ``PATH`` 变量需包括含有 ``idf.py`` 工具 (属于 ESP-IDF 一部分)的目录
为确保系统重启后仍保存之前的变量设置,请参照以下说明将变量设置添加到用户配置文件中。
.. note:: 使用 IDE 工具的情况下,你可以选择在 IDE 项目环境中设置环境变量,而不使用如下命令行。
.. note:: 如果你从未用过 ``idf.py`` 命令行工具,而是直接运行 cmake 或通过 IDE 工具运行 cmake则无需设置 ``PATH`` 变量,只需设置 ``IDF_PATH`` 变量。不过,你也可以两个都设置。
.. note:: 如果你只用过 ``idf.py`` 命令行工具,从未直接运行 cmake 或通过 IDE 工具运行 cmake则无需设置 ``IDF_PATH`` 变量。``idf.py`` 会搜索自身包含的目录,如果没有发现 ``IDF_PATH``,则会自行进行有关设置。
.. _add-paths-to-profile-windows-cmake:
Windows 操作系统
-----------------------------------
在 Windows 10 操作系统下设置环境变量,用户应在开始菜单下搜索 "Edit Environment Variables"。
在较早版本的 Windows 操作系统下设置环境变量,用户应打开系统控制面板,选择“高级”,找到环境变量按钮。
你可以为本台电脑上的“所有用户”或“当前用户”设置环境变量,这取决于其他用户是否也需要使用 ESP-IDF。
- 点击 ``New...``(新建... 添加名为 ``IDF_PATH`` 的新系统变量,具体设置为包含 ESP-IDF 的目录,例如,``C:\Users\user-name\esp\esp-idf``
- 找到 ``Path`` 环境变量,双击进行编辑。在末尾添加 ``;%IDF_PATH%\tools``,这样你就可以通过 Windows 命令窗口运行 ``idf.py`` 等其他工具了。
如果你在安装 ESP32 开发的软件时,从 :ref:`get-started-setup-path-cmake` 小节跳到了这里,请返回 :ref:`get-started-start-project-cmake` 小节开始阅读。
.. _add-idf_path-to-profile-linux-macos-cmake:
Linux 和 MacOS 操作系统
------------------------------------
要设置 ``IDF_PATH``,并在 PATH 中添加 ``idf.py``,请将以下两行代码增加至你的 ``~/.profile`` 文件中::
export IDF_PATH=~/esp/esp-idf
export PATH="$PATH:$IDF_PATH/tools"
.. note::
``~/.profile`` 表示在你的电脑用户主目录中,后缀为 ``.profile`` 的文件。(``~`` 为 shell 中的缩写)。
请退出,并重新登录使更改生效。
.. note::
并非所有 shell 都使用 ``.profile``,但是如果同时存在 ``/bin/bash````.bash_profile``,请更新此配置文件。如果存在 ``zsh``,更新 ``.zprofile``。其他 shell 可能使用其他配置文件(详询有关 shell 的文档)。
运行以下命令来检查 ``IDF_PATH`` 设置是否正确::
printenv IDF_PATH
此处应打印出此前在 ``~/.profile`` 文件中输入(或手动设置)的路径。
为确认 ``idf.py`` 目前是否在 ``PATH`` 中,你可以运行以下命令::
which idf.py
这里,应打印出类似 ``${IDF_PATH}/tools/idf.py`` 的路径。
如果你不想进行有关 ``IDF_PATH````PATH`` 的修改设置,你可以在每次重启或退出后在终端中手动输入::
export IDF_PATH=~/esp/esp-idf
export PATH="$PATH:$IDF_PATH/tools"
如果你在安装 ESP32 开发的软件时,从 :ref:`get-started-setup-path-cmake` 小节跳到了这里,请返回 :ref:`get-started-start-project-cmake` 小节开始阅读。

View file

@ -1 +1,466 @@
.. include:: ../../en/get-started-cmake/index.rst
********************************
快速入门 (CMake)
********************************
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
.. include:: ../cmake-pending-features.rst
本文档旨在指导用户创建 ESP32 的软件环境。本文将通过一个简单的例子,说明 ESP-IDF (Espressif IoT Development Framework) 的使用方法,包括配置、编译、下载固件到开发板等步骤。
概述
============
ESP32 是一套 Wi-Fi (2.4 GHz) 和蓝牙 (4.2) 双模解决方案,集成了高性能的 CPU 内核、超低功耗协处理器和丰富的外设。ESP32 采用 40 nm 工艺制成,具有最佳的功耗性能、射频性能、稳定性、通用性和可靠性,适用于各种应用和不同功耗需求。
乐鑫为用户提供完整的软、硬件资源,支持 ESP32 设备的开发。我们的软件开发环境 ESP-IDF 能够帮助用户快速开发物联网 (IoT) 应用,满足用户对于 Wi-Fi、蓝牙、低功耗等性能的需求。
准备工作
====================
开发 ESP32 应用程序需要准备:
* **电脑**:安装 Windows、Linux 或者 Mac 操作系统
* **工具链**:用于编译 ESP32 代码
* **编译工具**:用于编译 ESP32 完整**应用程序**的 CMake 和 Ninja
* **ESP-IDF**:包含 ESP32 API 和用于操作 **工具链** 的脚本
* **文本编辑器**:编写 C 语言程序,例如 `Eclipse <https://www.eclipse.org/>`_
* **ESP32 开发板** 和将其连接到 **电脑** 的 **USB 线**
.. figure:: ../../_static/what-you-need-cmake.png
:align: center
:alt: Development of applications for ESP32
:figclass: align-center
开发应用程序
开发环境的准备工作包括以下两部分:
1. 设置 **工具链**
2. 从 GitHub 上获取 **ESP-IDF**
开发环境设置完成后,遵循以下步骤创建 ESP-IDF 应用程序:
1. 配置**工程** 并编写代码
2. 编译**工程** 并链接成一个**应用程序**
3. 通过 USB/串口连接,烧录(上传)预编译的**应用程序****ESP32**
4. 通过 USB/串口,监视/调试**应用程序**输出
开发板指南
========================
如果你有下列任一 ESP32 开发板,请点击对应的链接进行硬件设置:
.. toctree::
:maxdepth: 1
ESP32 DevKitC <get-started-devkitc>
ESP-WROVER-KIT <get-started-wrover-kit>
ESP32-PICO-KIT <get-started-pico-kit>
如果你使用其它开发板,请查看下面的内容。
.. _get-started-setup-toolchain-cmake:
设置工具链
======================
用 ESP32 进行开发最快的方法是安装预编译的工具链。请根据你的操作系,点击对应的链接,并按照链接中的指导进行安装。
.. toctree::
:hidden:
Windows <windows-setup>
Linux <linux-setup>
MacOS <macos-setup>
+-------------------+-------------------+-------------------+
| |windows-logo| | |linux-logo| | |macos-logo| |
+-------------------+-------------------+-------------------+
| `Windows`_ | `Linux`_ | `Mac OS`_ |
+-------------------+-------------------+-------------------+
.. |windows-logo| image:: ../../_static/windows-logo.png
:target: ../get-started-cmake/windows-setup.html
.. |linux-logo| image:: ../../_static/linux-logo.png
:target: ../get-started-cmake/linux-setup.html
.. |macos-logo| image:: ../../_static/macos-logo.png
:target: ../get-started-cmake/macos-setup.html
.. _Windows: ../get-started-cmake/windows-setup.html
.. _Linux: ../get-started-cmake/linux-setup.html
.. _Mac OS: ../get-started-cmake/macos-setup.html
.. note::
我们使用用户名主目录下的 ``esp`` 子目录Linux 和 MacOS 为 ``~/esp``Windows 为 ``%userprofile%\esp``)来进行一切有关 ESP-IDF 的安装操作。你也可以使用其他目录,但是需要注意调整相应的指令。
你可以安装预编译的工具链或者自定义你的环境,这完全取决于个人经验和偏好。如果你要自定义环境,请参考 :ref:`get-started-customized-setup-cmake`
工具链设置完成后,继续阅读 :ref:`get-started-get-esp-idf-cmake` 一节。
.. _get-started-get-esp-idf-cmake:
获取 ESP-IDF
==================
工具链(包括用于编译和构建应用程序的程序)安装完成后,你还需要 ESP32 相关的 API/库。你可在乐鑫提供的 `ESP-IDF 仓库 <https://github.com/espressif/esp-idf>`_ 中获取 API/库本地副本。打开终端,切换到你要存放 ESP-IDF 的目录,然后使用 ``git clone`` 命令克隆远程仓库。
Linux 和 MacOS
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: bash
mkdir -p ~/esp
cd ~/esp
git clone --branch feature/cmake --recursive https://github.com/espressif/esp-idf.git
ESP-IDF 将会被下载到 ``~/esp/esp-idf`` 目录下。
Windows Command Prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: batch
mkdir %userprofile%\esp
cd %userprofile%\esp
git clone --branch feature/cmake --recursive https://github.com/espressif/esp-idf.git
.. highlight:: bash
.. note::
注意这里有个 ``--recursive`` 选项。如果你克隆 ESP-IDF 时没有带这个选项,你还需要运行额外的命令来获取子模块::
cd esp-idf
git submodule update --init
.. note::
基于 CMake 的构建系统预览默认使用的 Git 分支是 ``feature/cmake``。如果你在克隆时没有带 ``--branch`` 选项,可通过以下命令行切换分支::
cd esp-idf
git checkout feature/cmake
.. _get-started-setup-path-cmake:
设置环境变量
===========================
ESP-IDF 的正常运行需要设置两个环境变量:
- ``IDF_PATH`` 应设置为 ESP-IDF 根目录的路径。
- ``PATH`` 应包括同一 ``IDF_PATH`` 目录下的 ``tools`` 目录路径。
你需在你的电脑中设置这两个变量,否则工程将不能编译。
你可以在每次 PC 重启时手动设置,你也可以在用户配置中进行永久设置,具体请参照 :doc:`add-idf_path-to-profile` 小节中的 :ref:`Windows <add-paths-to-profile-windows-cmake>`:ref:`Linux 和 MacOS <add-idf_path-to-profile-linux-macos-cmake>` 相关指导进行操作。
.. _get-started-start-project-cmake:
创建一个工程
======================
现在可以开始创建 ESP32 应用程序了。为了快速开始,我们这里以 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 Command Prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. 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-cmake:
连接
=======
还有几个步骤就完成了。在继续后续操作前,先将 ESP32 开发板连接到 PC然后检查串口号看看它能否正常通信。如果你不知道如何操作请查看 :doc:`establish-serial-connection` 中的相关指导。请注意一下端口号,我们在下一步中会用到。
.. _get-started-configure-cmake:
配置
=========
进入 ``hello_world`` 应用程序副本目录,运行 ``menuconfig`` 工程配置工具:
Linux 和 MacOS
~~~~~~~~~~~~~~~~~~~~~
.. code-block:: bash
cd ~/esp/hello_world
idf.py menuconfig
Windows Command Prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: batch
cd %userprofile%\esp\hello_world
idf.py menuconfig
.. note:: 如果你收到未发现 ``idf.py`` 的报错信息,查看是否如上 :ref:`get-started-setup-path-cmake` 所述将 ``tools`` 目录添加到你的路径中。如果 ``tools`` 目录中没有 ``idf.py``,查看 :ref:`get-started-get-esp-idf-cmake` 中 CMake 预览所处的分支是否正确。
.. note:: 对于 Windows 用户而言Python 2.7 安装器会尝试配置 Windows关联扩展名为 ``.py`` 的 Python 2 文件。如果单独安装的程序(如 Visual Studio Python 工具)关联到其他 Python 版本,``idf.py`` 可能无法运行(而仅是在 Visual Studio 中打开此文件)。你可以每次运行 ``C:\Python27\python idf.py`` 或更改 Windows 中有关``.py`` 文件的关联设置。
.. note:: 对于 Linux 用户而言,如果默认为 Python 3.x 版本,你需要运行 ``python2 idf.py``
如果之前的步骤都正确,则会显示下面的菜单:
.. figure:: ../../_static/project-configuration.png
:align: center
:alt: Project configuration - Home window
:figclass: align-center
工程配置 - 主窗口
下面是一些使用 ``menuconfig`` 的小技巧:
* 使用 up & down 组合键在菜单中上下移动
* 使用 Enter 键进入一个子菜单Escape 键进入上一层菜单或退出整个菜单
* 输入 ``?`` 查看帮助信息Enter 键退出帮助屏幕
* 使用空格键或 ``Y`` 和 ``N`` 键来使能 (Yes) 和禁止 (No) 带有复选框 "``[*]``" 的配置项
* 当光标在某个配置项上面高亮时,输入 ``?`` 可以直接查看该项的帮助信息
* 输入 ``/`` 搜索配置项
.. _get-started-build-cmake:
创建一个工程
==========================
.. highlight:: bash
现在可以编译工程了,执行指令::
idf.py build
这条命令会编译应用程序和所有的 ESP-IDF 组件,生成 bootloader、区分表和应用程序 bin 文件。
.. 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-cmake:
烧录到设备
==========================
现在可以将应用程序烧录到 ESP32 板子上,执行指令::
idf.py -p PORT flash
将端口改为 ESP32 板子的串口名称。Windows 平台的端口名称类似 ``COM1``,而 MacOS 则以 ``/dev/cu.`` 开头Linux 则是 ``/dev/tty``。详情请参照 :doc:`establish-serial-connection`
该步骤旨在将此前编译的 bin 文件烧录到 ESP32 板子上。
.. note:: 无需在 ``idf.py flash`` 之前运行 ``idf.py build``,烧录这一步会按照烧录前编写的要求(如有)自动编写工程。
.. code-block:: none
Running esptool.py in directory [...]/esp/hello_world
Executing "python [...]/esp-idf/components/esptool_py/esptool/esptool.py -b 460800 write_flash @flash_project_args"...
esptool.py -b 460800 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 bootloader/bootloader.bin 0x8000 partition_table/partition-table.bin 0x10000 hello-world.bin
esptool.py v2.3.1
Connecting....
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Compressed 22992 bytes to 13019...
Wrote 22992 bytes (13019 compressed) at 0x00001000 in 0.3 seconds (effective 558.9 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 82...
Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 5789.3 kbit/s)...
Hash of data verified.
Compressed 136672 bytes to 67544...
Wrote 136672 bytes (67544 compressed) at 0x00010000 in 1.9 seconds (effective 567.5 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
如果没有任何问题,在烧录的最后阶段,板子将会复位,应用程序 "hello_world" 开始运行。
.. (目前暂不支持)如果你想使用 Eclipse IDE 而不是运行 ``idf.py``,请参考 :doc:`Eclipse guide <eclipse-setup>`。
.. _get-started-build-monitor-cmake:
监视器
================
如果要查看 "hello_world" 程序是否真的在运行,输入命令 ``idf.py -p PORT monitor``。这个命令会启动 :doc:`IDF Monitor <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...
I (211) cpu_start: Starting scheduler on APP CPU.
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
要退出监视器,请使用快捷键 ``Ctrl+]``
.. note::
如果串口打印的不是上面显示的消息而是类似下面的乱码::
e<><65><EFBFBD>)(Xn@<40>y.!<21><>(<28>PW+)<29><>Hn9a؅/9<>!<21>t5<74><35>P<EFBFBD>~<7E>k<EFBFBD><6B>e<EFBFBD>ea<65>5<EFBFBD>jA
~zY<7A><59>Y(1<>,1<15><> e<><65><EFBFBD>)(Xn@<40>y.!Dr<44>zY(<28>jpi<70>|<7C>+z5Ymvp
或者监视器程序启动失败,那么可能你的开发板用的是 26 MHz 晶振,而大多数开发板用的是 40 MHz 晶振,并且 ESP-IDF 默认的也是这一数值。请退出监视器,回到 :ref:`menuconfig <get-started-configure-cmake>`,将 :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` 改为 26 MHz然后再次 :ref:`编写和烧录 <get-started-flash-cmake>` 程序。请在 ``idf.py menuconfig`` 的 Component config --> ESP32-specific --> Main XTAL frequency 中配置。
.. note::
你可以将编写、烧录和监视整合到一步当中,如下所示::
idf.py -p PORT flash monitor
有关监视器使用的快捷键和其他详情,请参阅 :doc:`IDF Monitor <idf-monitor>`
有关 ``idf.py`` 的全部命令和选项,请参阅 :ref:`idf.py`
你已完成 ESP32 的入门!
现在你可以尝试其他的示例工程 :idf:`examples`,或者直接开发自己的应用程序。
更新 ESP-IDF
=========================
ESP-IDF 使用一段时间后,你可能想要进行升级来获得新的性能或者对 bug 进行修复。最简单的更新方式是删除已有的 ``esp-idf`` 文件夹然后再克隆一个,即重复 :ref:`get-started-get-esp-idf-cmake` 小节中所述的初始安装即可。
另外一种方法是只更新有改动的部分,此方法适合连接 GitHub 比较缓慢的情况。你只需运行如下指令:
Linux 和 MacOS
~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: bash
cd ~/esp/esp-idf
git pull
git submodule update --init --recursive
Windows Command Prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: batch
cd %userprofile%\esp\esp-idf
git pull
git submodule update --init --recursive
``git pull`` 命令将获取和合并 GitHub 上对 ESP-IDF 仓库所做的更改。``git submodule update --init --recursive`` 命令会更新现有子模块或拷贝更新的子模块。GitHub 上的子模块是指向其他仓库的链接,需要以下额外命令将其指向你的电脑。
.. highlight:: bash
你还可以查看具体发布的 ESP-IDF 版本,如 `v2.1`
Linux 和 MacOS
~~~~~~~~~~~~~~~~~~~~
.. code-block:: bash
cd ~/esp
git clone https://github.com/espressif/esp-idf.git esp-idf-v2.1
cd esp-idf-v2.1/
git checkout v2.1
git submodule update --init --recursive
Windows Command Prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: batch
cd %userprofile%\esp
git clone https://github.com/espressif/esp-idf.git esp-idf-v2.1
cd esp-idf-v2.1/
git checkout v2.1
git submodule update --init --recursive
注意 :doc:`add-idf_path-to-profile`,这样工具链脚本就能够知道这一版本的 ESP-IDF 的具体位置。
.. note::
ESP-IDF 版本不同,其设置、必备要求或所需工具链版本也会有所不同。如果你有任何问题,请仔细对照快速入门文档查看你将使用版本的相应要求。
相关文档
=================
.. toctree::
:maxdepth: 1
add-idf_path-to-profile
establish-serial-connection
eclipse-setup
idf-monitor
toolchain-setup-scratch

View file

@ -1 +1,119 @@
.. include:: ../../en/get-started-cmake/linux-setup.rst
*******************************************************************
Linux 平台工具链的标准设置 (CMake)
*******************************************************************
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
安装前提
=====================
编译 ESP-IDF 需要以下软件包:
- CentOS 7::
sudo yum install git wget ncurses-devel flex bison gperf python pyserial cmake ninja-build ccache
- Ubuntu 和 Debian::
sudo apt-get install git wget libncurses-dev flex bison gperf python python-pip python-setuptools python-serial cmake ninja-build ccache
- Arch::
sudo pacman -S --needed gcc git make ncurses flex bison gperf python2-pyserial cmake ninja ccache
.. note::
使用 ESP-IDF 需要 CMake 3.5 或以上版本。较早版本的 Linux 可能需要升级才能向后移植仓库,或安装 "cmake3" 软件包,而不是安装 "cmake"。
工具链的设置
=========================
.. include:: /_build/inc/download-links.inc
Linux 版的 ESP32 工具链可以从 Espressif 的网站下载:
- 64 位 Linux
|download_link_linux64|
- 32 位 Linux
|download_link_linux32|
1. 下载完成后,将它解压到 ``~/esp`` 目录:
- for 64-bit Linux:
.. include:: /_build/inc/unpack-code-linux64.inc
- for 32-bit Linux:
.. include:: /_build/inc/unpack-code-linux32.inc
.. _setup-linux-toolchain-add-it-to-path-cmake:
2. 工具链将会被解压到 ``~/esp/xtensa-esp32-elf/`` 目录。
要使用工具链,你还需要在 ``~/.profile`` 文件中更新环境变量 ``PATH``。要使 ``xtensa-esp32-elf`` 在所有的终端会话中都有效,需要将下面这一行代码添加到你的 ``~/.profile`` 文件中:::
export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"
或者,你也可以给上面的命令创建一个别名。这样做的好处是,你仅在需要时才获取工具链,将下面这行代码添加到 ``~/.profile`` 文件中即可::
alias get_esp32='export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"'
然后,当你需要使用工具链时,在命令行输入 ``get_esp32``,然后工具链会自动添加到你的 ``PATH`` 中。
.. note::
如果将 ``/bin/bash`` 设置为登录 shell且同时存在 ``.bash_profile````.profile``,则更新 ``.bash_profile``
3. 退出并重新登录以使 ``.profile`` 更改生效。运行以下命令来检查 ``PATH`` 设置是否正确:::
printenv PATH
检查一下字符串的末尾是否包含类似的工具链的路径::
$ printenv PATH
/home/user-name/bin:/home/user-name/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/user-name/esp/xtensa-esp32-elf/bin
除了 ``/home/user-name``,应该有具体的安装的主路径。
权限问题 /dev/ttyUSB0
----------------------------------------------
使用某些 Linux 版本向 ESP32 烧写固件时,可能会出现 ``Failed to open port /dev/ttyUSB0`` 错误消息。此时,可以将当前用户增加至 :ref:` Linux Dialout 组 <linux-dialout-group-cmake>`
Arch Linux 用户
--------------------------------
在 Arch Linux 中运行预编译的 gdb (xtensa-esp32-elf-gdb) 需要 ncurses 5但是 Arch 使用的是 ncurses 6。
`AUR`_ 中存在向下兼容的库文件,可用于本地和 lib32 的配置:
- https://aur.archlinux.org/packages/ncurses5-compat-libs/
- https://aur.archlinux.org/packages/lib32-ncurses5-compat-libs/
在安装这些软件包之前,你可能需要将作者的公钥添加到你的密钥环中,具体见上方链接中的 "Comments" 部分的介绍。
或者,你也可以使用 crosstool-NG 编译一个链接到 ncurses 6 的 gdb。
后续步骤
================
后续开发环境设置,请参考 :ref:`get-started-get-esp-idf-cmake` 一节。
相关文档
=================
.. toctree::
:maxdepth: 1
linux-setup-scratch
.. _AUR: https://wiki.archlinux.org/index.php/Arch_User_Repository

View file

@ -1 +1,86 @@
.. include:: ../../en/get-started-cmake/macos-setup-scratch.rst
*********************************************************************
从零开始设置 Mac OS 环境下的工具链 (CMake)
*********************************************************************
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
软件包管理器
======================
从零开始设置工具链,你需要安装 MacPorts_ 或 homebrew_ 包管理器。或者,你也可以直接 :doc:`下载预编译的工具链 <macos-setup>`
MacPorts_ 需要安装完整的 XCode 软件,而 homebrew_ 只需要安装 XCode 命令行工具即可。
.. _homebrew: https://brew.sh/
.. _MacPorts: https://www.macports.org/install.php
准备工作
============================
- 安装 pip::
sudo easy_install pip
- 安装 pyserial::
sudo pip install pyserial
- 安装 CMake 和 Ninja 编译工具:
- 若使用 HomeBrew你可以运行::
brew install cmake ninja
- 若使用 MacPorts你可以运行::
sudo port install cmake ninja
从源代码编译工具链
========================================
- 相关安装:
- 对于 MacPorts::
sudo port install gsed gawk binutils gperf grep gettext wget libtool autoconf automake make
- 对于 homebrew::
brew install gnu-sed gawk binutils gperftools gettext wget help2man libtool autoconf automake make
创建一个文件系统镜像(区分大小写)::
hdiutil create ~/esp/crosstool.dmg -volname "ctng" -size 10g -fs "Case-sensitive HFS+"
挂载::
hdiutil mount ~/esp/crosstool.dmg
创建指向你工作目录的符号链接::
mkdir -p ~/esp
ln -s /Volumes/ctng ~/esp/ctng-volume
前往新创建的目录:::
cd ~/esp/ctng-volume
下载 ``crosstool-NG``,并开始编译:
.. include:: /_build/inc/scratch-build-code.inc
编译工具链:::
./ct-ng xtensa-esp32-elf
./ct-ng build
chmod -R u+w builds/xtensa-esp32-elf
编译后的工具链将保存在 ``~/esp/ctng-volume/crosstool-NG/builds/xtensa-esp32-elf``。根据 :ref:`Mac OS 下设置环境变量的标准方法 <setup-macos-toolchain-add-it-to-path-cmake>` 中的介绍,将工具链添加到 ``PATH`` 中。
后续步骤
=================
继续设置开发环境,请前往 :ref:`获取 ESP-IDF <get-started-get-esp-idf-cmake>` 章节。

View file

@ -1 +1,95 @@
.. include:: ../../en/get-started-cmake/macos-setup.rst
******************************************************************
在 Mac OS 上安装 ESP32 工具链 (CMake)
******************************************************************
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
安装准备
=====================
ESP-IDF 将使用 Mac OS 上默认安装的 Python 版本。
- 安装 pip::
sudo easy_install pip
- 安装 pyserial::
sudo pip install pyserial
- 安装 CMake 和 Ninja 编译工具:
- 若有 HomeBrew_你可以运行::
brew install cmake ninja
- 若有 MacPorts_你可以运行::
sudo port install cmake ninja
- 若以上均不适用,访问 CMake_ 和 Ninja_ 主页,查询有关 Mac OS 平台的下载安装问题。
- 强烈建议同时安装 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`` 进行安装。
安装工具链
======================
.. include:: /_build/inc/download-links.inc
下载 MacOS 版本的 ESP32 工具链,请前往乐鑫官网:
|download_link_osx|
完成下载后,请在 ``~/esp`` 目录下进行解压:
.. include:: /_build/inc/unpack-code-osx.inc
.. _setup-macos-toolchain-add-it-to-path-cmake:
此后,该工具链将解压至 ``~/esp/xtensa-esp32-elf/`` 目录。
为了开始使用工具链,你必须更新 ``~/.profile`` 文件中的 ``PATH`` 环境变量。为了让所有终端都可以使用 ``xtensa-esp32-elf``,请将下方命令增加至你的 ``~/.profile`` 文件:::
export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH
此外,你可以为以上命令增加一个别名。这样,你就可以仅在有需要时获取工具链。具体方式是在 ``~/.profile`` 文件中增加下方命令:::
alias get_esp32="export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH"
此时,你可以直接输入 ``get_esp32`` 命令,即可将工具链添加至你的 ``PATH``
注意,这里需要退出并重新登陆,``.profile`` 更改才会生效。
此外,你可以使用以下命令,验证 ``PATH`` 是否设置正确:::
printenv PATH
后续步骤
=================
前往 :ref:`get-started-get-esp-idf-cmake`,完成接下来的开发环境配置。
相关文档
=================
.. toctree::
:maxdepth: 1
macos-setup-scratch
.. _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

View file

@ -1 +1,27 @@
.. include:: ../../en/get-started-cmake/toolchain-setup-scratch.rst
.. _get-started-customized-setup-cmake:
*********************************************************
工具链自定义设置 (CMake)
*********************************************************
:link_to_translation:`en:[英文]`
除了从乐鑫官网(请见 :ref:`get-started-setup-toolchain-cmake`)下载二进制工具链外,你还可以自行编制工具链。
如果没有特别需求,建议直接使用我们提供的预编制二进制工具链。不过,你也可能也会由于以下原因,编制你自己的工具链:
- 需要定制工具链编制配置
- 使用其他 GCC 版本(如 4.8.5
- 需要破解 gcc、newlib 或 libstdc++
- 有相关兴趣或时间充裕
- 不信任从网站下载的 bin 文件
无论如何,如果你希望自行编制工具链,请查看以下文档:
.. toctree::
:maxdepth: 1
windows-setup-scratch
linux-setup-scratch
macos-setup-scratch

View file

@ -1 +1,92 @@
.. include:: ../../en/get-started-cmake/windows-setup-scratch.rst
******************************************************************
从零开始设置 Windows 环境下的工具链 (CMake)
******************************************************************
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
本文就如何运行基于 CMake 构建系统中的 :doc:`ESP-IDF 工具安装器 <windows-setup>` 进行逐步详细说明。手动安装所有工具能更好地控制整个安装流程,同时也方便高阶用户进行自定义安装。
使用 ESP-IDF 工具安装器对工具链及其他工具进行快速标准设置,请参照 :doc:`windows-setup`
.. note::
基于 GNU Make 的构建系统要求 Windows 兼容 `MSYS2`_ Unix。基于 CMake 的构建系统则无此要求。
工具
=====
cmake
^^^^^
下载最新发布的 Windows 平台稳定版 `CMake`_,并运行安装器。
当安装器询问安装选项时,选择 "Add CMake to the system PATH for all users"(为所有用户的系统路径添加 CMake或 "Add CMake to the system PATH for the current user"(为当前用户的系统路径添加 CMake
Ninja 编译工具
^^^^^^^^^^^^^^^^^^^^
.. note::
Ninja 目前仅为 64 位版本 Windows 提供 bin 文件。你也可以通过其他编译工具使用 CMake 和 ``idf.py``,如适用于 32 位 Windows 的 mingw-make但是目前暂无关于此工具的说明文档。
从(`下载页面 <ninja-dl>`_)下载最新发布的 Windows 平台稳定版 `ninja`_
适用于 Windows 平台的 Ninja 下载文件是一个 .zip 文件,包含一个 ``ninja.exe`` 文件。将其解压到目录,并 `添加到你的路径 <add-directory-windows-path>`_ (或者选择你的路径中已有的目录)。
Python 2.x
^^^^^^^^^^
下载并运行适用于 Windows 安装器的最新版 `Python`_ 2.7。
Python 安装的“自定义”那一步提供了一份选项列表,最后一个选项是 "Add python.exe to Path"(添加 python.exe 到路径中),更改该选项,选择 "Will be installed"(将会安装)。
Python 安装完成后,打开 Windows 开始菜单下的 Command Prompt并运行以下命令::
pip install pyserial
适用于 IDF 的 MConf
^^^^^^^^^^^^^^^^^^^^^^
`kconfig-frontends 发布页面 <mconf-idf>`_ 下载配置工具 mconf-idf。此为 ``mconf`` 配置工具,可针对 ESP-IDF 进行一些自定义操作。
你需将此工具解压到目录,然后 `添加到你的路径 <add-directory-windows-path>`_
工具链设置
===============
从 dl.espressif.com 下载预编译的 Windows 平台工具链:
https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip
解压压缩包文件到 ``C:\Program Files`` (或其他地址)。压缩包文件包含 ``xtensa-esp32-elf`` 目录。
然后,须将该目录下的子目录 ``bin`` `添加到你的路径 <add-directory-windows-path>`_。例如,``C:\Program Files\xtensa-esp32-elf\bin``
.. note::
如果你已安装 MSYS2 环境(适用 "GNU Make" 构建系统),你可以跳过下载那一步,直接添加目录 ``C:\msys32\opt\xtensa-esp32-elf\bin`` 到路径,因为 MSYS2 环境已包含工具链。
.. _add-directory-windows-path-cmake:
添加目录到路径
========================
添加任何新目录到你的 Windows Path 环境变量:
打开系统控制面板,找到环境变量对话框(对于 Windows 10则在高级系统设置中查找对话框
双击 ``Path`` 变量(选择用户或系统路径,这取决于你是否希望其他用户路径中也存在该目录)。在最后数值那里新添 ``;<new value>``
后续步骤
================
要继续设置开发环境,请参照 :ref:`get-started-get-esp-idf-cmake`
.. _ninja: https://ninja-build.org/
.. _Python: https://www.python.org/downloads/windows/
.. _MSYS2: https://msys2.github.io/

View file

@ -1 +1,73 @@
.. include:: ../../en/get-started-cmake/windows-setup.rst
**********************************************************
Windows 平台工具链的标准设置 (CMake)
**********************************************************
:link_to_translation:`en:[英文]`
.. include:: ../cmake-warning.rst
.. note::
基于 CMake 的构建系统仅支持 64 位版本 Windows。
引言
============
ESP-IDF 需要安装必要的工具,以编译 ESP32 固件包括Git交叉编译器以及 CMake 构建工具。本文将对这些工具一一说明。
在此入门指南中,我们通过命令提示符进行有关操作。不过,安装 ESP-IDF 后你还可以使用 :doc:`Eclipse <eclipse-setup>` 或支持 CMake 的图形化工具 IDE。
.. note::
基于 GNU Make 的构建系统要求 Windows 系统兼容 MSYS2_ Unix。基于 CMake 的构建系统则无此要求。
ESP-IDF 工具安装器
=======================
安装 ESP-IDF 必备工具最简易的方式是下载 ESP-IDF 工具安装器,地址如下:
https://dl.espressif.com/dl/esp-idf-tools-setup-1.1.exe
安装器会自动安装 ESP32 Xtensa gcc 工具链Ninja_ 编译工具,以及名为 mconf-idf_ 的配置工具。此外,如果你的电脑还未安装有关 CMake_ 和 Python_ 2.7 的安装器,它还可以下载和运行与之对应的安装器。
安装器默认更新 Windows ``Path`` 环境变量,因而上述工具也可在其他环境中运行。如果禁止该选项,则需自行设置 ESP-IDF 所使用的环境(终端或所选 IDE并配置正确的路径。
请注意,此安装器仅针对 ESP-IDF 工具包,并不包括 ESP-IDF。
安装 Git
==============
ESP-IDF 工具安装器并不会安装 Git因为快速入门指南默认你将以命令行的模式使用它。你可以通过 `Git For Windows`_ 下载和安装 Windows 平台的命令行 Git 工具(包括 "Git Bash" 终端)。
如果你想使用其他图形化 Git 客户端,如 `Github Desktop` 你可以自行安装,并在快速入门中阐释相应 Git 命令,以使用你所选的 Git 客户端。
使用终端
================
在快速入门指南接下来的步骤说明中,我们将使用终端命令提示符进行有关操作。你也可以使用任何其他形式的命令提示符:
- 比如Windows 开始菜单下内置的 Command Prompt。本文档中的所有 Windows 命令行指示均为 Windows Command Prompt 中所使用的 "batch" 命令。
- 你还可以使用 `Git for Windows`_ 中的 "Git Bash" 终端,其所使用的 "bash" 命令提示符语法与 Mac OS 或 Linux 的既定语法相同。安装此终端后,你可以在开始菜单下找到命令提示符窗口。
- 如果你已安装 MSYS2_通过 ESP-IDF 之前版本),你还可以使用 MSYS 终端。
后续步骤
==========
要继续设置开发环境,请参照 :ref:`get-started-get-esp-idf-cmake`
相关文档
=================
想要自定义安装流程的高阶用户可参照:
.. toctree::
:maxdepth: 1
windows-setup-scratch
.. _MSYS2: https://msys2.github.io/
.. _cmake: https://cmake.org/download/
.. _ninja: https://ninja-build.org/
.. _Python: https://www.python.org/downloads/windows/
.. _Git for Windows: https://gitforwindows.org/
.. _mconf-idf: https://github.com/espressif/kconfig-frontends/releases/
.. _Github Desktop: https://desktop.github.com/