start-project.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. {IDF_TARGET_CORE_NUM:default="2", esp32s2="1", esp32c3="1", esp32c2="1"}
  2. {IDF_TARGET_FEATURES:default="[NEEDS TO BE UPDATED]", 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", esp32c2="WiFi/BLE, silicon revision 0, 2MB external flash", esp32c3="WiFi/BLE, silicon revision 0, 2MB external flash"}
  3. {IDF_TARGET_HEAP_SIZE:default="[NEEDS TO BE UPDATED]", esp32="298968", esp32s2="253900", esp32s3="390684", esp32c2="203888", esp32c3="337332"}
  4. Build the Project
  5. =================
  6. Build the project by running:
  7. .. code-block:: batch
  8. idf.py build
  9. This command will compile the application and all ESP-IDF components, then it will generate the bootloader, partition table, and application binaries.
  10. .. code-block:: none
  11. $ idf.py build
  12. Running cmake in directory /path/to/hello_world/build
  13. Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"...
  14. Warn about uninitialized values.
  15. -- Found Git: /usr/bin/git (found version "2.17.0")
  16. -- Building empty aws_iot component due to configuration
  17. -- Component names: ...
  18. -- Component paths: ...
  19. ... (more lines of build system output)
  20. [527/527] Generating hello_world.bin
  21. esptool.py v2.3.1
  22. Project build complete. To flash, run this command:
  23. ../../../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
  24. or run 'idf.py -p PORT flash'
  25. If there are no errors, the build will finish by generating the firmware binary .bin files.
  26. Flash onto the Device
  27. =====================
  28. To flash the binaries that you just built for the {IDF_TARGET_NAME} in the previous step, you need to run the following command:
  29. .. code-block:: bash
  30. idf.py -p PORT flash
  31. Replace ``PORT`` with your {IDF_TARGET_NAME} board's USB port name. If the ``PORT`` is not defined, the :ref:`idf.py` will try to connect automatically using the available USB ports.
  32. For more information on ``idf.py`` arguments, see :ref:`idf.py`.
  33. .. note::
  34. The option ``flash`` automatically builds and flashes the project, so running ``idf.py build`` is not necessary.
  35. Encountered Issues While Flashing? See this :doc:`flashing-troubleshooting` page or :doc:`establish-serial-connection` for more detailed information.
  36. Normal Operation
  37. ~~~~~~~~~~~~~~~~
  38. When flashing, you will see the output log similar to the following:
  39. .. only:: esp32
  40. .. code-block:: none
  41. ...
  42. 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
  43. esptool.py v3.0-dev
  44. Serial port /dev/ttyUSB0
  45. Connecting........_
  46. Chip is ESP32D0WDQ6 (revision 0)
  47. Features: WiFi, BT, Dual Core, Coding Scheme None
  48. Crystal is 40MHz
  49. MAC: 24:0a:c4:05:b9:14
  50. Uploading stub...
  51. Running stub...
  52. Stub running...
  53. Changing baud rate to 460800
  54. Changed.
  55. Configuring flash size...
  56. Compressed 3072 bytes to 103...
  57. Writing at 0x00008000... (100 %)
  58. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 5962.8 kbit/s)...
  59. Hash of data verified.
  60. Compressed 26096 bytes to 15408...
  61. Writing at 0x00001000... (100 %)
  62. Wrote 26096 bytes (15408 compressed) at 0x00001000 in 0.4 seconds (effective 546.7 kbit/s)...
  63. Hash of data verified.
  64. Compressed 147104 bytes to 77364...
  65. Writing at 0x00010000... (20 %)
  66. Writing at 0x00014000... (40 %)
  67. Writing at 0x00018000... (60 %)
  68. Writing at 0x0001c000... (80 %)
  69. Writing at 0x00020000... (100 %)
  70. Wrote 147104 bytes (77364 compressed) at 0x00010000 in 1.9 seconds (effective 615.5 kbit/s)...
  71. Hash of data verified.
  72. Leaving...
  73. Hard resetting via RTS pin...
  74. Done
  75. .. only:: esp32s2
  76. .. code-block:: none
  77. ...
  78. 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
  79. esptool.py v3.0-dev
  80. Serial port /dev/ttyUSB0
  81. Connecting....
  82. Chip is ESP32-S2
  83. Features: WiFi
  84. Crystal is 40MHz
  85. MAC: 18:fe:34:72:50:e3
  86. Uploading stub...
  87. Running stub...
  88. Stub running...
  89. Changing baud rate to 460800
  90. Changed.
  91. Configuring flash size...
  92. Compressed 3072 bytes to 103...
  93. Writing at 0x00008000... (100 %)
  94. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 3851.6 kbit/s)...
  95. Hash of data verified.
  96. Compressed 22592 bytes to 13483...
  97. Writing at 0x00001000... (100 %)
  98. Wrote 22592 bytes (13483 compressed) at 0x00001000 in 0.3 seconds (effective 595.1 kbit/s)...
  99. Hash of data verified.
  100. Compressed 140048 bytes to 70298...
  101. Writing at 0x00010000... (20 %)
  102. Writing at 0x00014000... (40 %)
  103. Writing at 0x00018000... (60 %)
  104. Writing at 0x0001c000... (80 %)
  105. Writing at 0x00020000... (100 %)
  106. Wrote 140048 bytes (70298 compressed) at 0x00010000 in 1.7 seconds (effective 662.5 kbit/s)...
  107. Hash of data verified.
  108. Leaving...
  109. Hard resetting via RTS pin...
  110. Done
  111. .. only:: esp32s3
  112. .. code-block:: none
  113. ...
  114. 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
  115. esptool.py v3.2-dev
  116. Serial port /dev/ttyUSB0
  117. Connecting....
  118. Chip is ESP32-S3
  119. Features: WiFi, BLE
  120. Crystal is 40MHz
  121. MAC: 7c:df:a1:e0:00:64
  122. Uploading stub...
  123. Running stub...
  124. Stub running...
  125. Changing baud rate to 460800
  126. Changed.
  127. Configuring flash size...
  128. Flash will be erased from 0x00000000 to 0x00004fff...
  129. Flash will be erased from 0x00010000 to 0x00039fff...
  130. Flash will be erased from 0x00008000 to 0x00008fff...
  131. Compressed 18896 bytes to 11758...
  132. Writing at 0x00000000... (100 %)
  133. Wrote 18896 bytes (11758 compressed) at 0x00000000 in 0.5 seconds (effective 279.9 kbit/s)...
  134. Hash of data verified.
  135. Compressed 168208 bytes to 88178...
  136. Writing at 0x00010000... (16 %)
  137. Writing at 0x0001a80f... (33 %)
  138. Writing at 0x000201f1... (50 %)
  139. Writing at 0x00025dcf... (66 %)
  140. Writing at 0x0002d0be... (83 %)
  141. Writing at 0x00036c07... (100 %)
  142. Wrote 168208 bytes (88178 compressed) at 0x00010000 in 2.4 seconds (effective 569.2 kbit/s)...
  143. Hash of data verified.
  144. Compressed 3072 bytes to 103...
  145. Writing at 0x00008000... (100 %)
  146. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 478.9 kbit/s)...
  147. Hash of data verified.
  148. Leaving...
  149. Hard resetting via RTS pin...
  150. Done
  151. .. only:: esp32c2
  152. .. code-block:: none
  153. ...
  154. esptool.py esp32c2 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 60m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin
  155. esptool.py v3.3.1
  156. Serial port /dev/ttyUSB0
  157. Connecting....
  158. Chip is ESP32-C2 (revision 1)
  159. Features: Wi-Fi
  160. Crystal is 40MHz
  161. MAC: 10:97:bd:f0:e5:0c
  162. Uploading stub...
  163. Running stub...
  164. Stub running...
  165. Changing baud rate to 460800
  166. Changed.
  167. Configuring flash size...
  168. Flash will be erased from 0x00000000 to 0x00004fff...
  169. Flash will be erased from 0x00010000 to 0x0002ffff...
  170. Flash will be erased from 0x00008000 to 0x00008fff...
  171. Compressed 18192 bytes to 10989...
  172. Writing at 0x00000000... (100 %)
  173. Wrote 18192 bytes (10989 compressed) at 0x00000000 in 0.6 seconds (effective 248.5 kbit/s)...
  174. Hash of data verified.
  175. Compressed 128640 bytes to 65895...
  176. Writing at 0x00010000... (20 %)
  177. Writing at 0x00019539... (40 %)
  178. Writing at 0x00020bf2... (60 %)
  179. Writing at 0x00027de1... (80 %)
  180. Writing at 0x0002f480... (100 %)
  181. Wrote 128640 bytes (65895 compressed) at 0x00010000 in 1.7 seconds (effective 603.0 kbit/s)...
  182. Hash of data verified.
  183. Compressed 3072 bytes to 103...
  184. Writing at 0x00008000... (100 %)
  185. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 360.1 kbit/s)...
  186. Hash of data verified.
  187. Leaving...
  188. Hard resetting via RTS pin...
  189. .. only:: esp32c3
  190. .. code-block:: none
  191. ...
  192. 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
  193. esptool.py v3.0
  194. Serial port /dev/ttyUSB0
  195. Connecting....
  196. Chip is ESP32-C3
  197. Features: Wi-Fi
  198. Crystal is 40MHz
  199. MAC: 7c:df:a1:40:02:a4
  200. Uploading stub...
  201. Running stub...
  202. Stub running...
  203. Changing baud rate to 460800
  204. Changed.
  205. Configuring flash size...
  206. Compressed 3072 bytes to 103...
  207. Writing at 0x00008000... (100 %)
  208. Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 4238.1 kbit/s)...
  209. Hash of data verified.
  210. Compressed 18960 bytes to 11311...
  211. Writing at 0x00000000... (100 %)
  212. Wrote 18960 bytes (11311 compressed) at 0x00000000 in 0.3 seconds (effective 584.9 kbit/s)...
  213. Hash of data verified.
  214. Compressed 145520 bytes to 71984...
  215. Writing at 0x00010000... (20 %)
  216. Writing at 0x00014000... (40 %)
  217. Writing at 0x00018000... (60 %)
  218. Writing at 0x0001c000... (80 %)
  219. Writing at 0x00020000... (100 %)
  220. Wrote 145520 bytes (71984 compressed) at 0x00010000 in 2.3 seconds (effective 504.4 kbit/s)...
  221. Hash of data verified.
  222. Leaving...
  223. Hard resetting via RTS pin...
  224. Done
  225. If there are no issues by the end of the flash process, the board will reboot and start up the “hello_world” application.
  226. If you'd like to use the Eclipse or VS Code IDE instead of running ``idf.py``, check out `Eclipse Plugin <https://github.com/espressif/idf-eclipse-plugin/blob/master/README.md>`_, `VSCode Extension <https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md>`_.
  227. Monitor the Output
  228. ==================
  229. 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).
  230. This command launches the :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` application::
  231. $ idf.py -p <PORT> monitor
  232. Running idf_monitor in directory [...]/esp/hello_world/build
  233. Executing "python [...]/esp-idf/tools/idf_monitor.py -b 115200 [...]/esp/hello_world/build/hello_world.elf"...
  234. --- idf_monitor on <PORT> 115200 ---
  235. --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
  236. ets Jun 8 2016 00:22:57
  237. rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  238. ets Jun 8 2016 00:22:57
  239. ...
  240. After startup and diagnostic logs scroll up, you should see "Hello world!" printed out by the application.
  241. .. code-block:: none
  242. ...
  243. Hello world!
  244. Restarting in 10 seconds...
  245. This is {IDF_TARGET_PATH_NAME} chip with {IDF_TARGET_CORE_NUM} CPU core(s), {IDF_TARGET_FEATURES}
  246. Minimum free heap size: {IDF_TARGET_HEAP_SIZE} bytes
  247. Restarting in 9 seconds...
  248. Restarting in 8 seconds...
  249. Restarting in 7 seconds...
  250. To exit IDF monitor use the shortcut ``Ctrl+]``.
  251. .. only:: esp32 or esp32c2
  252. 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.
  253. .. figure:: ../../_static/get-started-garbled-output.png
  254. :align: center
  255. :alt: Garbled output
  256. :figclass: align-center
  257. If you have such a problem, do the following:
  258. 1. Exit the monitor.
  259. 2. Go back to ``menuconfig``.
  260. 3. Go to ``Component config`` --> ``Hardware Settings`` --> ``Main XTAL Config`` --> ``Main XTAL frequency``, then change :ref:`CONFIG_XTAL_FREQ_SEL` to 26 MHz.
  261. 4. After that, ``build and flash`` the application again.
  262. In the current version of ESP-IDF, main XTAL frequencies supported by {IDF_TARGET_NAME} are as follows:
  263. .. list::
  264. :SOC_XTAL_SUPPORT_24M: - 24 MHz
  265. :SOC_XTAL_SUPPORT_26M: - 26 MHz
  266. :SOC_XTAL_SUPPORT_32M: - 32 MHz
  267. :SOC_XTAL_SUPPORT_40M: - 40 MHz
  268. .. note::
  269. You can combine building, flashing and monitoring into one step by running::
  270. idf.py -p PORT flash monitor
  271. See also:
  272. - :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` for handy shortcuts and more details on using IDF monitor.
  273. - :ref:`idf.py` for a full reference of ``idf.py`` commands and options.
  274. **That's all that you need to get started with {IDF_TARGET_NAME}!**
  275. Now you are ready to try some other :idf:`examples`, or go straight to developing your own applications.
  276. .. important::
  277. Some of examples do not support {IDF_TARGET_NAME} because required hardware is not included in {IDF_TARGET_NAME} so it cannot be supported.
  278. 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}.
  279. Additional Tips
  280. ===============
  281. Permission issues /dev/ttyUSB0
  282. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  283. 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>`.
  284. Python compatibility
  285. ~~~~~~~~~~~~~~~~~~~~
  286. 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>`_.
  287. .. only:: esp32 or esp32s2 or esp32s3
  288. ..
  289. When adding new targets to the line above, please update this list in windows-start-project.rst and linux-macos-start-project.rst
  290. Start with Board Support Package
  291. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  292. To speed up prototyping on some development boards, you can use `Board Support Packages (BSPs) <https://github.com/espressif/esp-bsp>`_, which makes initialization of a particular board as easy as few function calls.
  293. A BSP typically supports all of the hardware components provided on development board. Apart from the pinout definition and initialization functions, a BSP ships with drivers for the external components such as sensors, displays, audio codecs etc.
  294. The BSPs are distributed via `IDF Component Manager <../api-guides/tools/idf-component-manager>`_, so they can be found in `IDF Component Registry <https://components.espressif.com>`_.
  295. .. only:: esp32
  296. **Here's an example of how to add ESP-WROVER-KIT BSP to your project:**
  297. .. code-block:: bash
  298. idf.py add-dependency esp_wrover_kit
  299. .. only:: esp32s2
  300. **Here's an example of how to add ESP32-S2-Kaluga-Kit BSP to your project:**
  301. .. code-block:: bash
  302. idf.py add-dependency esp32_s2_kaluga_kit
  303. .. only:: esp32s3
  304. **Here's an example of how to add ESP-BOX BSP to your project:**
  305. .. code-block:: bash
  306. idf.py add-dependency esp-box
  307. More examples of BSP usage can be found in `BSP examples folder <https://github.com/espressif/esp-bsp/tree/master/examples>`_.
  308. Flash Erase
  309. ~~~~~~~~~~~
  310. Erasing the flash is also possible. To erase the entire flash memory you can run the following command:
  311. .. code-block:: bash
  312. idf.py -p PORT erase-flash
  313. For erasing the OTA data, if present, you can run this command:
  314. .. code-block:: bash
  315. idf.py -p PORT erase-otadata
  316. The flash erase command can take a while to be done. Do not disconnect your device while the flash erasing is in progress.