index.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. *****************************
  2. Get Started (Legacy GNU Make)
  3. *****************************
  4. :link_to_translation:`zh_CN:[中文]`
  5. .. include:: ../gnu-make-legacy.rst
  6. This document is intended to help you set up the software development environment for the hardware based on Espressif ESP32.
  7. After that, a simple example will show you how to use ESP-IDF (Espressif IoT Development Framework) for menu configuration, then for building and flashing firmware onto an ESP32 board.
  8. .. include-build-file:: inc/version-note.inc
  9. Introduction
  10. ============
  11. ESP32 is a system on a chip that integrates the following features:
  12. * Wi-Fi (2.4 GHz band)
  13. * Bluetooth
  14. * Dual high performance cores
  15. * Ultra Low Power co-processor
  16. * Several peripherals
  17. Powered by 40 nm technology, ESP32 provides a robust, highly integrated platform, which helps meet the continuous demands for efficient power usage, compact design, security, high performance, and reliability.
  18. Espressif provides basic hardware and software resources to help application developers realize their ideas using the ESP32 series hardware. The software development framework by Espressif is intended for development of Internet-of-Things (IoT) applications with Wi-Fi, Bluetooth, power management and several other system features.
  19. What You Need
  20. =============
  21. Hardware:
  22. * An **ESP32** board
  23. * **USB cable** - USB A / micro USB B
  24. * **Computer** running Windows, Linux, or macOS
  25. Software:
  26. * **Toolchain** to build the **Application** for ESP32
  27. * **ESP-IDF** that essentially contains API (software libraries and source code) for ESP32 and scripts to operate the **Toolchain**
  28. * **Text editor** to write programs (**Projects**) in C, e.g., `Eclipse <https://www.eclipse.org/>`_
  29. .. figure:: ../../_static/what-you-need.png
  30. :align: center
  31. :alt: Development of applications for ESP32
  32. :figclass: align-center
  33. Development of applications for ESP32
  34. Development Board Overviews
  35. ===========================
  36. If you have one of ESP32 development boards listed below, you can click on the link to learn more about its hardware.
  37. .. toctree::
  38. :maxdepth: 1
  39. ESP32-DevKitC <../hw-reference/esp32/get-started-devkitc>
  40. ESP-WROVER-KIT <../hw-reference/esp32/get-started-wrover-kit>
  41. ESP32-PICO-KIT <../hw-reference/esp32/get-started-pico-kit>
  42. ESP32-Ethernet-Kit <../hw-reference/esp32/get-started-ethernet-kit>
  43. ESP32-DevKit-S(-R) <../hw-reference/esp32/user-guide-devkits-r-v1.1>
  44. .. _get-started-step-by-step-legacy:
  45. Installation Step by Step
  46. =========================
  47. This is a detailed roadmap to walk you through the installation process.
  48. Setting up Development Environment
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. * :ref:`get-started-setup-toolchain-legacy` for :doc:`Windows <windows-setup>`, :doc:`Linux <linux-setup>` or :doc:`macOS <macos-setup>`
  51. * :ref:`get-started-get-esp-idf-legacy`
  52. * :ref:`get-started-setup-path-legacy`
  53. * :ref:`get-started-get-packages-legacy`
  54. Creating Your First Project
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. * :ref:`get-started-start-project-legacy`
  57. * :ref:`get-started-connect-legacy`
  58. * :ref:`get-started-configure-legacy`
  59. * :ref:`get-started-build-and-flash-legacy`
  60. * :ref:`get-started-monitor-legacy`
  61. .. _get-started-setup-toolchain-legacy:
  62. Step 1. Set up the Toolchain
  63. ============================
  64. The toolchain is a set of programs for compiling code and building applications.
  65. The quickest way to start development with ESP32 is by installing a prebuilt toolchain. Pick up your OS below and follow the provided instructions.
  66. .. toctree::
  67. :hidden:
  68. Windows <windows-setup>
  69. Linux <linux-setup>
  70. macOS <macos-setup>
  71. +-----------------+---------------+---------------+
  72. | |windows-logo| | |linux-logo| | |macos-logo| |
  73. +-----------------+---------------+---------------+
  74. | Windows_ | Linux_ | `macOS`_ |
  75. +-----------------+---------------+---------------+
  76. .. |windows-logo| image:: ../../_static/windows-logo.png
  77. :target: ../get-started-legacy/windows-setup.html
  78. .. |linux-logo| image:: ../../_static/linux-logo.png
  79. :target: ../get-started-legacy/linux-setup.html
  80. .. |macos-logo| image:: ../../_static/macos-logo.png
  81. :target: ../get-started-legacy/macos-setup.html
  82. .. _Windows: ../get-started-legacy/windows-setup.html
  83. .. _Linux: ../get-started-legacy/linux-setup.html
  84. .. _macOS: ../get-started-legacy/macos-setup.html
  85. .. note::
  86. This guide uses the directory ``~/esp`` on Linux and macOS or ``%userprofile%\esp`` on Windows as an installation folder for ESP-IDF. You can use any directory, but you will need to adjust paths for the commands respectively. Keep in mind that ESP-IDF does not support spaces in paths.
  87. Depending on your experience and preferences, you may want to customize your environment instead of using a prebuilt toolchain. To set up the system your own way go to Section :ref:`get-started-customized-setup-legacy`.
  88. .. _get-started-get-esp-idf-legacy:
  89. Step 2. Get ESP-IDF
  90. ===================
  91. Besides the toolchain, you also need ESP32-specific API (software libraries and source code). They are provided by Espressif in `ESP-IDF repository <https://github.com/espressif/esp-idf>`_.
  92. To get a local copy of ESP-IDF, navigate to your installation directory and clone the repository with ``git clone``.
  93. Open Terminal, and run the following commands:
  94. .. include-build-file:: inc/git-clone-bash.inc
  95. ESP-IDF will be downloaded into ``~/esp/esp-idf``.
  96. Consult :doc:`/versions` for information about which ESP-IDF version to use in a given situation.
  97. .. include-build-file:: inc/git-clone-notes.inc
  98. .. note::
  99. Do not miss the ``--recursive`` option. If you have already cloned ESP-IDF without this option, run another command to get all the submodules::
  100. cd esp-idf
  101. git submodule update --init
  102. .. _get-started-setup-path-legacy:
  103. Step 3. Set Environment Variables
  104. =================================
  105. The toolchain uses the environment variable ``IDF_PATH`` to access the ESP-IDF directory. This variable should be set up on your computer, otherwise projects will not build.
  106. These variables can be set temporarily (per session) or permanently. Please follow the instructions specific to :ref:`Windows <add-idf_path-to-profile-windows-legacy>` , :ref:`Linux and macOS <add-idf_path-to-profile-linux-macos-legacy>` in Section :doc:`add-idf_path-to-profile`.
  107. .. _get-started-get-packages-legacy:
  108. Step 4. Install the Required Python Packages
  109. ============================================
  110. The python packages required by ESP-IDF are located in ``IDF_PATH/requirements.txt``. You can install them by running::
  111. python -m pip install --user -r $IDF_PATH/requirements.txt
  112. .. note::
  113. Please check the version of the Python interpreter that you will be using with ESP-IDF. For this, run
  114. the command ``python --version`` and depending on the result, you might want to use ``python3``, ``python3.7``
  115. or similar instead of just ``python``, e.g.::
  116. python3 -m pip install --user -r $IDF_PATH/requirements.txt
  117. .. _get-started-start-project-legacy:
  118. Step 5. Start a Project
  119. =======================
  120. Now you are ready to prepare your application for ESP32. You can start with :example:`get-started/hello_world` project from :idf:`examples` directory in IDF.
  121. Copy :example:`get-started/hello_world` to the ``~/esp`` directory:
  122. Linux and macOS
  123. ~~~~~~~~~~~~~~~
  124. .. code-block:: bash
  125. cd ~/esp
  126. cp -r $IDF_PATH/examples/get-started/hello_world .
  127. Windows
  128. ~~~~~~~
  129. .. code-block:: batch
  130. cd %userprofile%\esp
  131. xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world
  132. There is a range of example projects in the :idf:`examples` directory in ESP-IDF. You can copy any project in the same way as presented above and run it.
  133. It is also possible to build examples in-place, without copying them first.
  134. .. important::
  135. The esp-idf build system does not support spaces in the paths to either esp-idf or to projects.
  136. .. _get-started-connect-legacy:
  137. Step 6. Connect Your Device
  138. ===========================
  139. Now connect your ESP32 board to the computer and check under what serial port the board is visible.
  140. Serial ports have the following patterns in their names:
  141. - **Windows**: names like ``COM1``
  142. - **Linux**: starting with ``/dev/tty``
  143. - **macOS**: starting with ``/dev/cu.``
  144. If you are not sure how to check the serial port name, please refer to :doc:`establish-serial-connection` for full details.
  145. .. note::
  146. Keep the port name handy as you will need it in the next steps.
  147. .. _get-started-configure-legacy:
  148. Step 7. Configure
  149. =================
  150. Navigate to your ``hello_world`` directory from :ref:`get-started-start-project-legacy` and run the project configuration utility ``menuconfig``.
  151. Linux and macOS
  152. ~~~~~~~~~~~~~~~
  153. .. code-block:: bash
  154. cd ~/esp/hello_world
  155. make menuconfig
  156. Windows
  157. ~~~~~~~
  158. .. code-block:: batch
  159. cd %userprofile%\esp\hello_world
  160. make menuconfig
  161. If the previous steps have been done correctly, the following menu appears:
  162. .. figure:: ../../_static/project-configuration.png
  163. :align: center
  164. :alt: Project configuration - Home window
  165. :figclass: align-center
  166. Project configuration - Home window
  167. In the menu, navigate to ``Serial flasher config`` > ``Default serial port`` to configure the serial port, where project will be loaded to. Confirm selection by pressing enter, save configuration by selecting ``< Save >`` and then exit ``menuconfig`` by selecting ``< Exit >``.
  168. To navigate and use ``menuconfig``, press the following keys:
  169. * Arrow keys for navigation
  170. * ``Enter`` to go into a submenu
  171. * ``Esc`` to go up one level or exit
  172. * ``?`` to see a help screen. Enter key exits the help screen
  173. * ``Space``, or ``Y`` and ``N`` keys to enable (Yes) and disable (No) configuration items with checkboxes "``[*]``"
  174. * ``?`` while highlighting a configuration item to display help about that item
  175. * ``/`` to find configuration items
  176. .. attention::
  177. If you use ESP32-DevKitC board with the **ESP32-SOLO-1** module, enable single core mode (:ref:`CONFIG_FREERTOS_UNICORE`) in menuconfig before flashing examples.
  178. .. _get-started-build-and-flash-legacy:
  179. Step 8. Build and Flash
  180. =======================
  181. Build and flash the project by running::
  182. make flash
  183. This command will compile the application and all ESP-IDF components, then it will generate the bootloader, partition table, and application binaries. After that, these binaries will be flashed onto your ESP32 board.
  184. Encountered Issues While Flashing?
  185. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186. If you run the given command and see errors such as "Failed to connect", there might be several reasons for this. One of the reasons might be issues encountered by ``esptool.py``, the utility that is called by the build system to reset the chip, interact with the ROM bootloader, and flash firmware. One simple solution to try is manual reset described below, and if it does not help you can find more details about possible issues in `Troubleshooting <https://github.com/espressif/esptool#bootloader-wont-respond>`_.
  187. ``esptool.py`` resets {IDF_TARGET_NAME} automatically by asserting DTR and RTS control lines of the USB to serial converter chip, i.e., FTDI or CP210x (for more information, see :doc:`establish-serial-connection`). The DTR and RTS control lines are in turn connected to ``GPIO0`` and ``CHIP_PU`` (EN) pins of {IDF_TARGET_NAME}, thus changes in the voltage levels of DTR and RTS will boot {IDF_TARGET_NAME} into Firmware Download mode. As an example, check the schematic for :ref:`esp-modules-and-boards-esp32-devkitc` development board.
  188. In general, you should have no problems with the official esp-idf development boards. However, ``esptool.py`` is not able to reset your hardware automatically in the following cases:
  189. - Your hardware does not have the DTR and RTS lines connected to ``GPIO0`` and ``CIHP_PU``
  190. - The DTR and RTS lines are configured differently
  191. - There are no such serial control lines at all
  192. 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).
  193. - 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 (``GPIO0``) and press the **EN** button (``CHIP_PU``).
  194. - For other types of hardware, try pulling ``GPIO0`` down.
  195. Normal Operation
  196. ~~~~~~~~~~~~~~~~
  197. If there are no issues by the end of the flash process, you will see the output log similar to the one given below. Then the board will reboot and start up the "hello_world" application.
  198. .. code-block:: bash
  199. esptool.py v3.0-dev
  200. Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
  201. esptool.py v3.0-dev
  202. Serial port /dev/cu.SLAB_USBtoUART
  203. Connecting........____
  204. Chip is ESP32D0WDQ6 (revision 1)
  205. Features: WiFi, BT, Dual Core, Coding Scheme None
  206. Crystal is 40MHz
  207. MAC: 30:ae:a4:15:21:b4
  208. Uploading stub...
  209. Running stub...
  210. Stub running...
  211. Configuring flash size...
  212. Auto-detected Flash size: 4MB
  213. Flash params set to 0x0220
  214. Compressed 26704 bytes to 15930...
  215. Wrote 26704 bytes (15930 compressed) at 0x00001000 in 1.4 seconds (effective 151.9 kbit/s)...
  216. Hash of data verified.
  217. Compressed 147984 bytes to 77738...
  218. Wrote 147984 bytes (77738 compressed) at 0x00010000 in 6.9 seconds (effective 172.7 kbit/s)...
  219. Hash of data verified.
  220. Compressed 3072 bytes to 103...
  221. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 1607.9 kbit/s)...
  222. Hash of data verified.
  223. Leaving...
  224. Hard resetting via RTS pin...
  225. If you'd like to use the Eclipse IDE instead of running ``make``, check out the :doc:`Eclipse guide <eclipse-setup>`.
  226. .. _get-started-monitor-legacy:
  227. Step 9. Monitor
  228. ===============
  229. To check if "hello_world" is indeed running, type ``make monitor``.
  230. This command launches the :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` application::
  231. $ make monitor
  232. MONITOR
  233. --- idf_monitor on /dev/ttyUSB0 115200 ---
  234. --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
  235. ets Jun 8 2016 00:22:57
  236. rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  237. ets Jun 8 2016 00:22:57
  238. ...
  239. After startup and diagnostic logs scroll up, you should see "Hello world!" printed out by the application.
  240. .. code-block:: bash
  241. ...
  242. Hello world!
  243. This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
  244. Restarting in 10 seconds...
  245. Restarting in 9 seconds...
  246. Restarting in 8 seconds...
  247. Restarting in 7 seconds...
  248. To exit IDF monitor use the shortcut ``Ctrl+]``.
  249. If IDF monitor fails shortly after the upload, or if instead of the messages above you see a random garbage similar to what is given below, your board is likely using a 26MHz crystal. Most development board designs use 40MHz, so ESP-IDF uses this frequency as a default value.
  250. .. figure:: ../../_static/get-started-garbled-output.png
  251. :align: center
  252. :alt: Garbled output
  253. :figclass: align-center
  254. If you have such a problem, do the following:
  255. 1. Exit the monitor.
  256. 2. Go back to :ref:`menuconfig <get-started-configure-legacy>`.
  257. 3. Go to Component config --> ESP32-specific --> Main XTAL frequency, then change :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` to 26MHz.
  258. 4. After that, :ref:`build and flash <get-started-build-and-flash-legacy>` the application again.
  259. .. note::
  260. You can combine building, flashing and monitoring into one step by running::
  261. make flash monitor
  262. See also :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` for handy shortcuts and more details on using IDF monitor.
  263. **That's all that you need to get started with ESP32!**
  264. Now you are ready to try some other :idf:`examples`, or go straight to developing your own applications.
  265. Environment Variables
  266. =====================
  267. Some environment variables can be specified whilst calling ``make`` allowing users to **override arguments without the need to reconfigure them using** ``make menuconfig``.
  268. +-----------------+--------------------------------------------------------------+
  269. | Variables | Description & Usage |
  270. +=================+==============================================================+
  271. | ``ESPPORT`` | Overrides the serial port used in ``flash`` and ``monitor``. |
  272. | | |
  273. | | Examples: ``make flash ESPPORT=/dev/ttyUSB1``, |
  274. | | ``make monitor ESPPORT=COM1`` |
  275. +-----------------+--------------------------------------------------------------+
  276. | ``ESPBAUD`` | Overrides the serial baud rate when flashing the ESP32. |
  277. | | |
  278. | | Example: ``make flash ESPBAUD=9600`` |
  279. +-----------------+--------------------------------------------------------------+
  280. | ``MONITORBAUD`` | Overrides the serial baud rate used when monitoring. |
  281. | | |
  282. | | Example: ``make monitor MONITORBAUD=9600`` |
  283. +-----------------+--------------------------------------------------------------+
  284. .. note::
  285. You can export environment variables (e.g. ``export ESPPORT=/dev/ttyUSB1``).
  286. All subsequent calls of ``make`` within the same terminal session will use
  287. the exported value given that the variable is not simultaneously overridden.
  288. Updating ESP-IDF
  289. ================
  290. 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-legacy`.
  291. If downloading to a new path, remember to :doc:`add-idf_path-to-profile` so that the toolchain scripts can find ESP-IDF in its release specific location.
  292. Another solution is to update only what has changed. :ref:`The update procedure depends on the version of ESP-IDF you are using <updating>`.
  293. Related Documents
  294. =================
  295. .. toctree::
  296. :maxdepth: 1
  297. add-idf_path-to-profile
  298. establish-serial-connection
  299. make-project
  300. eclipse-setup
  301. ../api-guides/tools/idf-monitor
  302. toolchain-setup-scratch
  303. .. Note: These two targets may be used from git-clone-notes.inc depending on version, don't remove
  304. .. _Stable version: https://docs.espressif.com/projects/esp-idf/en/stable/
  305. .. _Releases page: https://github.com/espressif/esp-idf/releases