index.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. ***********
  2. Get Started
  3. ***********
  4. This document is intended to help users set up the software environment for developement of applications using hardware based on the Espressif ESP32. Through a simple example we would like to illustrate how to use ESP-IDF (Espressif IoT Development Framework), including the menu based configuration, compiling the ESP-IDF and firmware download to ESP32 boards.
  5. Introduction
  6. ============
  7. ESP32 integrates Wi-Fi (2.4 GHz band) and Bluetooth 4.2 solutions on a single chip, along with dual high performance cores, Ultra Low Power co-processor and several peripherals. Powered by 40 nm technology, ESP32 provides a robust, highly integrated platform to meet the continuous demands for efficient power usage, compact design, security, high performance, and reliability.
  8. Espressif provides the basic hardware and software resources that help application developers to build their ideas around the ESP32 series hardware. The software development framework by Espressif is intended for rapidly developing Internet-of-Things (IoT) applications, with Wi-Fi, Bluetooth, power management and several other system features.
  9. What You Need
  10. =============
  11. To develop applications for ESP32 you need:
  12. * **PC** loaded with either Windows, Linux or Mac operating system
  13. * **Toolchain** to build the **Application** for ESP32
  14. * **ESP-IDF** that essentially contains API for ESP32 and scripts to operate the **Toolchain**
  15. * A text editor to write programs (**Projects**) in C, e.g. `Eclipse <https://www.eclipse.org/>`_
  16. * The **ESP32** board itself and a **USB cable** to connect it to the **PC**
  17. .. figure:: ../_static/what-you-need.png
  18. :align: center
  19. :alt: Development of applications for ESP32
  20. :figclass: align-center
  21. Development of applications for ESP32
  22. Preparation of development environment consists of three steps:
  23. 1. Setup of **Toolchain**
  24. 2. Getting of **ESP-IDF** from GitHub
  25. 3. Installation and configuration of **Eclipse**
  26. You may skip the last step, if you prefer to use different editor.
  27. Having environment set up, you are ready to start the most interesting part - the application development. This process may be summarized in four steps:
  28. 1. Configuration of a **Project** and writing the code
  29. 2. Compilation of the **Project** and linking it to build an **Application**
  30. 3. Flashing (uploading) of the **Application** to **ESP32**
  31. 4. Monitoring / debugging of the **Application**
  32. See instructions below that will walk you through these steps.
  33. Guides
  34. ======
  35. If you have one of ESP32 development boards listed below, click on provided links to get you up and running.
  36. .. toctree::
  37. :maxdepth: 1
  38. ESP32 DevKitC <get-started-devkitc>
  39. ESP-WROVER-KIT <get-started-wrover-kit>
  40. ESP32-PICO-KIT <get-started-pico-kit>
  41. If you have different board, move to sections below.
  42. .. _get-started-setup-toolchain:
  43. Setup Toolchain
  44. ===============
  45. The quickest way to start development with ESP32 is by installing a prebuilt toolchain. Pick up your OS below and follow provided instructions.
  46. .. toctree::
  47. :hidden:
  48. Windows <windows-setup>
  49. Linux <linux-setup>
  50. MacOS <macos-setup>
  51. +-------------------+-------------------+-------------------+
  52. | |windows-logo| | |linux-logo| | |macos-logo| |
  53. +-------------------+-------------------+-------------------+
  54. | `Windows`_ | `Linux`_ | `Mac OS`_ |
  55. +-------------------+-------------------+-------------------+
  56. .. |windows-logo| image:: ../_static/windows-logo.png
  57. :target: ../get-started/windows-setup.html
  58. .. |linux-logo| image:: ../_static/linux-logo.png
  59. :target: ../get-started/linux-setup.html
  60. .. |macos-logo| image:: ../_static/macos-logo.png
  61. :target: ../get-started/macos-setup.html
  62. .. _Windows: ../get-started/windows-setup.html
  63. .. _Linux: ../get-started/linux-setup.html
  64. .. _Mac OS: ../get-started/macos-setup.html
  65. .. note::
  66. We are using ``~/esp`` directory to install the prebuilt toolchain, ESP-IDF and sample applications. You can use different directory, but need to adjust respective commands.
  67. Depending on your experience and preferences, instead of using a prebuilt toolchain, you may want to customize your environment. To set up the system your own way go to section :ref:`get-started-customized-setup`.
  68. Once you are done with setting up the toolchain then go to section :ref:`get-started-get-esp-idf`.
  69. .. _get-started-get-esp-idf:
  70. Get ESP-IDF
  71. ===========
  72. .. highlight:: bash
  73. Besides the toolchain (that contains programs to compile and build the application), you also need ESP32 specific API / libraries. They are provided by Espressif in `ESP-IDF repository <https://github.com/espressif/esp-idf>`_. To get it, open terminal, navigate to the directory you want to put ESP-IDF, and clone it using ``git clone`` command::
  74. cd ~/esp
  75. git clone --recursive https://github.com/espressif/esp-idf.git
  76. ESP-IDF will be downloaded into ``~/esp/esp-idf``.
  77. .. note::
  78. Do not miss the ``--recursive`` option. If you have already cloned ESP-IDF without this option, run another command to get all the submodules::
  79. cd ~/esp/esp-idf
  80. git submodule update --init
  81. .. note::
  82. While cloning submodules on **Windows** platform, the ``git clone`` command may print some output starting ``': not a valid identifier...``. This is a `known issue <https://github.com/espressif/esp-idf/issues/11>`_ but the git clone still succeeds without any problems.
  83. .. _get-started-setup-path:
  84. Setup Path to ESP-IDF
  85. =====================
  86. The toolchain programs access ESP-IDF using ``IDF_PATH`` environment variable. This variable should be set up on your PC, otherwise projects will not build. Setting may be done manually, each time PC is restarted. Another option is to set up it permanently by defining ``IDF_PATH`` in user profile. To do so, follow instructions specific to :ref:`Windows <add-idf_path-to-profile-windows>` , :ref:`Linux and MacOS <add-idf_path-to-profile-linux-macos>` in section :doc:`add-idf_path-to-profile`.
  87. .. _get-started-start-project:
  88. Start a Project
  89. ===============
  90. Now you are ready to prepare your application for ESP32. To start off quickly, we will use :example:`get-started/hello_world` project from :idf:`examples` directory in IDF.
  91. Copy :example:`get-started/hello_world` to ``~/esp`` directory::
  92. cd ~/esp
  93. cp -r $IDF_PATH/examples/get-started/hello_world .
  94. You can also find a range of example projects under the :idf:`examples` directory in ESP-IDF. These example project directories can be copied in the same way as presented above, to begin your own projects.
  95. .. important::
  96. The esp-idf build system does not support spaces in paths to esp-idf or to projects.
  97. .. _get-started-connect:
  98. Connect
  99. =======
  100. You are almost there. To be able to proceed further, connect ESP32 board to PC, check under what serial port the board is visible and verify if serial communication works. If you are not sure how to do it, check instructions in section :doc:`establish-serial-connection`. Note the port number, as it will be required in the next step.
  101. .. _get-started-configure:
  102. Configure
  103. =========
  104. Being in terminal window, go to directory of ``hello_world`` application by typing ``cd ~/esp/hello_world``. Then start project configuration utility ``menuconfig``::
  105. cd ~/esp/hello_world
  106. make menuconfig
  107. If previous steps have been done correctly, the following menu will be displayed:
  108. .. figure:: ../_static/project-configuration.png
  109. :align: center
  110. :alt: Project configuration - Home window
  111. :figclass: align-center
  112. Project configuration - Home window
  113. 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 application by selecting ``< Exit >``.
  114. .. note::
  115. On Windows, serial ports have names like COM1. On MacOS, they start with ``/dev/cu.``. On Linux, they start with ``/dev/tty``.
  116. (See :doc:`establish-serial-connection` for full details.)
  117. Here are couple of tips on navigation and use of ``menuconfig``:
  118. * Use up & down arrow keys to navigate the menu.
  119. * Use Enter key to go into a submenu, Escape key to go out or to exit.
  120. * Type ``?`` to see a help screen. Enter key exits the help screen.
  121. * Use Space key, or ``Y`` and ``N`` keys to enable (Yes) and disable (No) configuration items with checkboxes "``[*]``"
  122. * Pressing ``?`` while highlighting a configuration item displays help about that item.
  123. * Type ``/`` to search the configuration items.
  124. .. note::
  125. If you are **Arch Linux** user, navigate to ``SDK tool configuration`` and change the name of ``Python 2 interpreter`` from ``python`` to ``python2``.
  126. .. note::
  127. Most ESP32 development boards have a 40MHz crystal installed. However, some boards use a 26MHz crystal. If your board uses a 26MHz crystal, or you get garbage output from serial port after code upload, adjust the :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` option in menuconfig.
  128. .. _get-started-build-flash:
  129. Build and Flash
  130. ===============
  131. Now you can build and flash the application. Run::
  132. make flash
  133. This will compile the application and all the ESP-IDF components, generate bootloader, partition table, and application binaries, and flash these binaries to your ESP32 board.
  134. .. highlight:: none
  135. ::
  136. esptool.py v2.0-beta2
  137. Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
  138. esptool.py v2.0-beta2
  139. Connecting........___
  140. Uploading stub...
  141. Running stub...
  142. Stub running...
  143. Changing baud rate to 921600
  144. Changed.
  145. Attaching SPI flash...
  146. Configuring flash size...
  147. Auto-detected Flash size: 4MB
  148. Flash params set to 0x0220
  149. Compressed 11616 bytes to 6695...
  150. Wrote 11616 bytes (6695 compressed) at 0x00001000 in 0.1 seconds (effective 920.5 kbit/s)...
  151. Hash of data verified.
  152. Compressed 408096 bytes to 171625...
  153. Wrote 408096 bytes (171625 compressed) at 0x00010000 in 3.9 seconds (effective 847.3 kbit/s)...
  154. Hash of data verified.
  155. Compressed 3072 bytes to 82...
  156. Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 8297.4 kbit/s)...
  157. Hash of data verified.
  158. Leaving...
  159. Hard resetting...
  160. If there are no issues, at the end of build process, you should see messages describing progress of loading process. Finally, the end module will be reset and "hello_world" application will start.
  161. If you'd like to use the Eclipse IDE instead of running ``make``, check out the :doc:`Eclipse guide <eclipse-setup>`.
  162. .. _get-started-build-monitor:
  163. Monitor
  164. =======
  165. To see if "hello_world" application is indeed running, type ``make monitor``. This command is launching :doc:`IDF Monitor <idf-monitor>` application::
  166. $ make monitor
  167. MONITOR
  168. --- idf_monitor on /dev/ttyUSB0 115200 ---
  169. --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
  170. ets Jun 8 2016 00:22:57
  171. rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  172. ets Jun 8 2016 00:22:57
  173. ...
  174. Several lines below, after start up and diagnostic log, you should see "Hello world!" printed out by the application. ::
  175. ...
  176. Hello world!
  177. Restarting in 10 seconds...
  178. I (211) cpu_start: Starting scheduler on APP CPU.
  179. Restarting in 9 seconds...
  180. Restarting in 8 seconds...
  181. Restarting in 7 seconds...
  182. To exit monitor use shortcut ``Ctrl+]``. To execute ``make flash`` and ``make monitor`` in one shoot type ``make flash monitor``. Check section :doc:`IDF Monitor <idf-monitor>` for handy shortcuts and more details on using this application.
  183. That's all what you need to get started with ESP32!
  184. Now you are ready to try some other :idf:`examples`, or go right to developing your own applications.
  185. Updating ESP-IDF
  186. ================
  187. After some time of using ESP-IDF, you may want to update it to take advantage of new features or bug fixes. The simplest way to do so is by deleting existing ``esp-idf`` folder and cloning it again, exactly as when doing initial installation described in sections :ref:`get-started-get-esp-idf`.
  188. Another solution is to update only what has changed. This method is useful if you have slow connection to the GiHub. To do the update run the following commands::
  189. cd ~/esp/esp-idf
  190. git pull
  191. git submodule update --init --recursive
  192. The ``git pull`` command is fetching and merging changes from ESP-IDF repository on GitHub. Then ``git submodule update --init --recursive`` is updating existing submodules or getting a fresh copy of new ones. On GitHub the submodules are represented as links to other repositories and require this additional command to get them onto your PC.
  193. If you would like to use specific release of ESP-IDF, e.g. `v2.1`, run::
  194. cd ~/esp
  195. git clone https://github.com/espressif/esp-idf.git esp-idf-v2.1
  196. cd esp-idf-v2.1/
  197. git checkout v2.1
  198. git submodule update --init --recursive
  199. After that remember to :doc:`add-idf_path-to-profile`, so the toolchain scripts know where to find the ESP-IDF in it's release specific location.
  200. Related Documents
  201. =================
  202. .. toctree::
  203. :maxdepth: 1
  204. add-idf_path-to-profile
  205. establish-serial-connection
  206. make-project
  207. eclipse-setup
  208. idf-monitor
  209. toolchain-setup-scratch