start-project.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. {IDF_TARGET_CORE_NUM:default="2", esp32s2="1", esp32c3="1"}
  2. {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"}
  3. {IDF_TARGET_HEAP_SIZE:default="298968", esp32="298968", esp32s2="253900", esp32s3="390684", esp32c3="337332"}
  4. Now you have all requirements met, the next topic will guide you on how to start your first project.
  5. This guide will help you on the first steps using ESP-IDF. Follow this guide to start a new project on the {IDF_TARGET_NAME} and build, flash, and monitor the device output.
  6. .. note::
  7. 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.
  8. Start a Project
  9. ===================
  10. 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.
  11. .. important::
  12. The ESP-IDF build system does not support spaces in the paths to either ESP-IDF or to projects.
  13. Copy the project :example:`get-started/hello_world` to ``~/esp`` directory:
  14. Windows
  15. ~~~~~~~
  16. .. code-block:: batch
  17. cd %userprofile%\esp
  18. xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world
  19. Linux/macOS
  20. ~~~~~~~~~~~
  21. .. code-block:: bash
  22. cd ~/esp
  23. cp -r $IDF_PATH/examples/get-started/hello_world .
  24. .. note:: 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. It is also possible to build examples in-place, without copying them first.
  25. Connect Your Device
  26. ===================
  27. Now connect your {IDF_TARGET_NAME} board to the computer and check under what serial port the board is visible.
  28. Serial ports have the following patterns in their names:
  29. - **Windows**: names like ``COM1``
  30. - **Linux**: starting with ``/dev/tty``
  31. - **macOS**: starting with ``/dev/cu.``
  32. If you are not sure how to check the serial port name, please refer to :doc:`establish-serial-connection` for full details.
  33. .. note::
  34. Keep the port name handy as you will need it in the next steps.
  35. Configure your Project
  36. ======================
  37. Navigate to your ``hello_world`` directory, set {IDF_TARGET_NAME} chip as the target and run the project configuration utility ``menuconfig``.
  38. Windows
  39. ~~~~~~~
  40. .. code-block:: batch
  41. cd %userprofile%\esp\hello_world
  42. idf.py set-target {IDF_TARGET_PATH_NAME}
  43. idf.py menuconfig
  44. Linux/macOS
  45. ~~~~~~~~~~~
  46. .. code-block:: bash
  47. cd ~/esp/hello_world
  48. idf.py set-target {IDF_TARGET_PATH_NAME}
  49. idf.py menuconfig
  50. 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.
  51. If the previous steps have been done correctly, the following menu appears:
  52. .. figure:: ../../_static/project-configuration.png
  53. :align: center
  54. :alt: Project configuration - Home window
  55. :figclass: align-center
  56. Project configuration - Home window
  57. You are using this menu to set up project specific variables, e.g. Wi-Fi network name and password, the processor speed, etc. Setting up the project with menuconfig may be skipped for "hello_word". This example will run with default configuration.
  58. .. only:: esp32
  59. .. attention::
  60. If you use ESP32-DevKitC board with the **ESP32-SOLO-1** module, or ESP32-DevKitM-1 board with the **ESP32-MIN1-1(1U)** module, enable single core mode (:ref:`CONFIG_FREERTOS_UNICORE`) in menuconfig before flashing examples.
  61. .. note::
  62. The colors of the menu could be different in your terminal. You can change the appearance with the option ``--style``. Please run ``idf.py menuconfig --help`` for further information.
  63. Build the Project
  64. =================
  65. Build the project by running:
  66. .. code-block:: batch
  67. idf.py build
  68. This command will compile the application and all ESP-IDF components, then it will generate the bootloader, partition table, and application binaries.
  69. .. code-block:: none
  70. $ idf.py build
  71. Running cmake in directory /path/to/hello_world/build
  72. Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"...
  73. Warn about uninitialized values.
  74. -- Found Git: /usr/bin/git (found version "2.17.0")
  75. -- Building empty aws_iot component due to configuration
  76. -- Component names: ...
  77. -- Component paths: ...
  78. ... (more lines of build system output)
  79. [527/527] Generating hello_world.bin
  80. esptool.py v2.3.1
  81. Project build complete. To flash, run this command:
  82. ../../../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
  83. or run 'idf.py -p PORT flash'
  84. If there are no errors, the build will finish by generating the firmware binary .bin files.
  85. Flash onto the Device
  86. =====================
  87. Flash the binaries that you just built (bootloader.bin, partition-table.bin and hello_world.bin) onto your {IDF_TARGET_NAME} board by running:
  88. .. code-block:: bash
  89. idf.py -p PORT [-b BAUD] flash
  90. Replace PORT with your {IDF_TARGET_NAME} board's serial port name.
  91. You can also change the flasher baud rate by replacing BAUD with the baud rate you need. The default baud rate is ``460800``.
  92. For more information on idf.py arguments, see :ref:`idf.py`.
  93. .. note::
  94. The option ``flash`` automatically builds and flashes the project, so running ``idf.py build`` is not necessary.
  95. Encountered Issues While Flashing?
  96. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. {IDF_TARGET_STRAP_GPIO:default="GPIO0", esp32="GPIO0", esp32s2="GPIO0", esp32s3="GPIO0", esp32c3="GPIO9"}
  98. 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>`_.
  99. ``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 ``{IDF_TARGET_STRAP_GPIO}`` 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 <https://dl.espressif.com/dl/schematics/esp32_devkitc_v4-sch-20180607a.pdf>`_ for the ESP32 DevKitC development board.
  100. In general, you should have no problems with the `official esp-idf development boards <https://www.espressif.com/en/products/devkits>`_. However, ``esptool.py`` is not able to reset your hardware automatically in the following cases:
  101. - Your hardware does not have the DTR and RTS lines connected to ``{IDF_TARGET_STRAP_GPIO}`` and ``CHIP_PU``
  102. - The DTR and RTS lines are configured differently
  103. - There are no such serial control lines at all
  104. 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).
  105. - 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``).
  106. - For other types of hardware, try pulling ``{IDF_TARGET_STRAP_GPIO}`` down.
  107. Normal Operation
  108. ~~~~~~~~~~~~~~~~
  109. When flashing, you will see the output log similar to the following:
  110. .. only:: esp32
  111. .. code-block:: none
  112. ...
  113. 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
  114. esptool.py v3.0-dev
  115. Serial port /dev/ttyUSB0
  116. Connecting........_
  117. Chip is ESP32D0WDQ6 (revision 0)
  118. Features: WiFi, BT, Dual Core, Coding Scheme None
  119. Crystal is 40MHz
  120. MAC: 24:0a:c4:05:b9:14
  121. Uploading stub...
  122. Running stub...
  123. Stub running...
  124. Changing baud rate to 460800
  125. Changed.
  126. Configuring flash size...
  127. Compressed 3072 bytes to 103...
  128. Writing at 0x00008000... (100 %)
  129. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 5962.8 kbit/s)...
  130. Hash of data verified.
  131. Compressed 26096 bytes to 15408...
  132. Writing at 0x00001000... (100 %)
  133. Wrote 26096 bytes (15408 compressed) at 0x00001000 in 0.4 seconds (effective 546.7 kbit/s)...
  134. Hash of data verified.
  135. Compressed 147104 bytes to 77364...
  136. Writing at 0x00010000... (20 %)
  137. Writing at 0x00014000... (40 %)
  138. Writing at 0x00018000... (60 %)
  139. Writing at 0x0001c000... (80 %)
  140. Writing at 0x00020000... (100 %)
  141. Wrote 147104 bytes (77364 compressed) at 0x00010000 in 1.9 seconds (effective 615.5 kbit/s)...
  142. Hash of data verified.
  143. Leaving...
  144. Hard resetting via RTS pin...
  145. Done
  146. .. only:: esp32s2
  147. .. code-block:: none
  148. ...
  149. 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
  150. esptool.py v3.0-dev
  151. Serial port /dev/ttyUSB0
  152. Connecting....
  153. Chip is ESP32-S2
  154. Features: WiFi
  155. Crystal is 40MHz
  156. MAC: 18:fe:34:72:50:e3
  157. Uploading stub...
  158. Running stub...
  159. Stub running...
  160. Changing baud rate to 460800
  161. Changed.
  162. Configuring flash size...
  163. Compressed 3072 bytes to 103...
  164. Writing at 0x00008000... (100 %)
  165. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 3851.6 kbit/s)...
  166. Hash of data verified.
  167. Compressed 22592 bytes to 13483...
  168. Writing at 0x00001000... (100 %)
  169. Wrote 22592 bytes (13483 compressed) at 0x00001000 in 0.3 seconds (effective 595.1 kbit/s)...
  170. Hash of data verified.
  171. Compressed 140048 bytes to 70298...
  172. Writing at 0x00010000... (20 %)
  173. Writing at 0x00014000... (40 %)
  174. Writing at 0x00018000... (60 %)
  175. Writing at 0x0001c000... (80 %)
  176. Writing at 0x00020000... (100 %)
  177. Wrote 140048 bytes (70298 compressed) at 0x00010000 in 1.7 seconds (effective 662.5 kbit/s)...
  178. Hash of data verified.
  179. Leaving...
  180. Hard resetting via RTS pin...
  181. Done
  182. .. only:: esp32s3
  183. .. code-block:: none
  184. ...
  185. 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
  186. esptool.py v3.2-dev
  187. Serial port /dev/ttyUSB0
  188. Connecting....
  189. Chip is ESP32-S3
  190. Features: WiFi, BLE
  191. Crystal is 40MHz
  192. MAC: 7c:df:a1:e0:00:64
  193. Uploading stub...
  194. Running stub...
  195. Stub running...
  196. Changing baud rate to 460800
  197. Changed.
  198. Configuring flash size...
  199. Flash will be erased from 0x00000000 to 0x00004fff...
  200. Flash will be erased from 0x00010000 to 0x00039fff...
  201. Flash will be erased from 0x00008000 to 0x00008fff...
  202. Compressed 18896 bytes to 11758...
  203. Writing at 0x00000000... (100 %)
  204. Wrote 18896 bytes (11758 compressed) at 0x00000000 in 0.5 seconds (effective 279.9 kbit/s)...
  205. Hash of data verified.
  206. Compressed 168208 bytes to 88178...
  207. Writing at 0x00010000... (16 %)
  208. Writing at 0x0001a80f... (33 %)
  209. Writing at 0x000201f1... (50 %)
  210. Writing at 0x00025dcf... (66 %)
  211. Writing at 0x0002d0be... (83 %)
  212. Writing at 0x00036c07... (100 %)
  213. Wrote 168208 bytes (88178 compressed) at 0x00010000 in 2.4 seconds (effective 569.2 kbit/s)...
  214. Hash of data verified.
  215. Compressed 3072 bytes to 103...
  216. Writing at 0x00008000... (100 %)
  217. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 478.9 kbit/s)...
  218. Hash of data verified.
  219. Leaving...
  220. Hard resetting via RTS pin...
  221. Done
  222. .. only:: esp32c3
  223. .. code-block:: none
  224. ...
  225. 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
  226. esptool.py v3.0
  227. Serial port /dev/ttyUSB0
  228. Connecting....
  229. Chip is ESP32-C3
  230. Features: Wi-Fi
  231. Crystal is 40MHz
  232. MAC: 7c:df:a1:40:02:a4
  233. Uploading stub...
  234. Running stub...
  235. Stub running...
  236. Changing baud rate to 460800
  237. Changed.
  238. Configuring flash size...
  239. Compressed 3072 bytes to 103...
  240. Writing at 0x00008000... (100 %)
  241. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 4238.1 kbit/s)...
  242. Hash of data verified.
  243. Compressed 18960 bytes to 11311...
  244. Writing at 0x00000000... (100 %)
  245. Wrote 18960 bytes (11311 compressed) at 0x00000000 in 0.3 seconds (effective 584.9 kbit/s)...
  246. Hash of data verified.
  247. Compressed 145520 bytes to 71984...
  248. Writing at 0x00010000... (20 %)
  249. Writing at 0x00014000... (40 %)
  250. Writing at 0x00018000... (60 %)
  251. Writing at 0x0001c000... (80 %)
  252. Writing at 0x00020000... (100 %)
  253. Wrote 145520 bytes (71984 compressed) at 0x00010000 in 2.3 seconds (effective 504.4 kbit/s)...
  254. Hash of data verified.
  255. Leaving...
  256. Hard resetting via RTS pin...
  257. Done
  258. If there are no issues by the end of the flash process, the board will reboot and start up the “hello_world” application.
  259. If you'd like to use the Eclipse or VS Code IDE instead of running ``idf.py``, check out the :doc:`Eclipse guide <eclipse-setup>`, :doc:`VS Code guide <vscode-setup>`.
  260. Monitor the Output
  261. ==================
  262. To check if "hello_world" is indeed running, type ``idf.py -p PORT monitor`` (Do not forget to replace PORT with your serial port name).
  263. This command launches the :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` application::
  264. $ idf.py -p <PORT> monitor
  265. Running idf_monitor in directory [...]/esp/hello_world/build
  266. Executing "python [...]/esp-idf/tools/idf_monitor.py -b 115200 [...]/esp/hello_world/build/hello_world.elf"...
  267. --- idf_monitor on <PORT> 115200 ---
  268. --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
  269. ets Jun 8 2016 00:22:57
  270. rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  271. ets Jun 8 2016 00:22:57
  272. ...
  273. After startup and diagnostic logs scroll up, you should see "Hello world!" printed out by the application.
  274. .. code-block:: none
  275. ...
  276. Hello world!
  277. Restarting in 10 seconds...
  278. This is {IDF_TARGET_PATH_NAME} chip with {IDF_TARGET_CORE_NUM} CPU core(s), {IDF_TARGET_FEATURES}
  279. Minimum free heap size: {IDF_TARGET_HEAP_SIZE} bytes
  280. Restarting in 9 seconds...
  281. Restarting in 8 seconds...
  282. Restarting in 7 seconds...
  283. To exit IDF monitor use the shortcut ``Ctrl+]``.
  284. .. only:: esp32
  285. If IDF monitor fails shortly after the upload, or, if instead of the messages above, you see random garbage similar to what is given below, your board is likely using a 26 MHz crystal. Most development board designs use 40 MHz, so ESP-IDF uses this frequency as a default value.
  286. .. figure:: ../../_static/get-started-garbled-output.png
  287. :align: center
  288. :alt: Garbled output
  289. :figclass: align-center
  290. If you have such a problem, do the following:
  291. 1. Exit the monitor.
  292. 2. Go back to `menuconfig`.
  293. 3. Go to Component config --> ESP32-specific --> Main XTAL frequency, then change :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` to 26 MHz.
  294. 4. After that, `build and flash` the application again.
  295. .. note::
  296. You can combine building, flashing and monitoring into one step by running::
  297. idf.py -p PORT flash monitor
  298. See also:
  299. - :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` for handy shortcuts and more details on using IDF monitor.
  300. - :ref:`idf.py` for a full reference of ``idf.py`` commands and options.
  301. **That's all that you need to get started with {IDF_TARGET_NAME}!**
  302. Now you are ready to try some other :idf:`examples`, or go straight to developing your own applications.
  303. .. important::
  304. Some of examples do not support {IDF_TARGET_NAME} because required hardware is not included in {IDF_TARGET_NAME} so it cannot be supported.
  305. If building an example, please check the README file for the ``Supported Targets`` table. If this is present including {IDF_TARGET_NAME} target, or the table does not exist at all, the example will work on {IDF_TARGET_NAME}.
  306. Additional Tips
  307. ===============
  308. Permission issues /dev/ttyUSB0
  309. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  310. With some Linux distributions, you may get the ``Failed to open port /dev/ttyUSB0`` error message when flashing the {IDF_TARGET_NAME}. :ref:`This can be solved by adding the current user to the dialout group<linux-dialout-group>`.
  311. Python compatibility
  312. ~~~~~~~~~~~~~~~~~~~~
  313. ESP-IDF supports Python 3.7 or newer. It is recommended to upgrade your operating system to a recent version satisfying this requirement. Other options include the installation of Python from `sources <https://www.python.org/downloads/>`_ or the use of a Python version management system such as `pyenv <https://github.com/pyenv/pyenv>`_.