establish-serial-connection.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. Establish Serial Connection with {IDF_TARGET_NAME}
  2. ==================================================
  3. :link_to_translation:`zh_CN:[中文]`
  4. .. only:: not SOC_USB_OTG_SUPPORTED and not SOC_USB_SERIAL_JTAG_SUPPORTED
  5. Establishing a serial connection with the {IDF_TARGET_NAME} target device could be done using a USB-to-UART bridge.
  6. .. only:: SOC_USB_OTG_SUPPORTED or SOC_USB_SERIAL_JTAG_SUPPORTED
  7. Establishing a serial connection with the {IDF_TARGET_NAME} target device could be done using USB-to-UART bridge or USB peripheral supported in {IDF_TARGET_NAME}.
  8. Some development boards have the USB-to-UART bridge installed. If a board does not have a bridge then an external bridge may be used.
  9. .. only:: SOC_USB_OTG_SUPPORTED or SOC_USB_SERIAL_JTAG_SUPPORTED
  10. Supported USB Peripheral
  11. ------------------------
  12. The {IDF_TARGET_NAME} supports the USB peripheral. In this case, the USB-to-UART bridge is not needed and the device can be flashed directly.
  13. .. blockdiag::
  14. :scale: 70%
  15. :caption: SoC with Supported USB
  16. :align: center
  17. blockdiag usb_capable_esp {
  18. node_height = 80;
  19. span_width = 160;
  20. span_height = 140;
  21. default_fontsize = 16
  22. # labels of diagram nodes
  23. PC [label="Personal\n Computer"];
  24. CHIP [label="{IDF_TARGET_NAME}", width=120];
  25. DUMMY [shape=none, width=1]
  26. # node connections
  27. PC <- DUMMY [label = "USB", fontsize=14];
  28. DUMMY -> CHIP [fontsize=14];
  29. group {
  30. shape = line;
  31. style = dotted;
  32. color = "#FF0000";
  33. label = "Development Board\n\n\n";
  34. CHIP; DUMMY;
  35. }
  36. }
  37. Apart from the USB peripheral, some development boards also include the USB-to-UART bridge.
  38. USB-to-UART Bridge on Development Board
  39. ---------------------------------------
  40. For boards with an installed USB-to-UART bridge, the connection between the personal computer and the bridge is USB and between the bridge and {IDF_TARGET_NAME} is UART.
  41. .. blockdiag::
  42. :caption: Development Board with USB-to-UART Bridge
  43. :align: center
  44. blockdiag esp_dev_board_with_usb_to_uart_bridge {
  45. node_height = 80;
  46. span_width = 160;
  47. span_height = 140;
  48. default_fontsize = 16
  49. # labels of diagram nodes
  50. PC [label="Personal\nComputer"];
  51. BRIDGE [label="USB-to-UART\n Bridge"];
  52. CHIP [label="{IDF_TARGET_NAME}", width=120];
  53. # node connections
  54. PC <-> BRIDGE [label = "USB", fontsize=14];
  55. BRIDGE <-> CHIP [label = "UART", fontsize=14];
  56. group {
  57. shape = line;
  58. style = dotted;
  59. color = "#FF0000";
  60. label = "Developmment Board\n\n\n";
  61. BRIDGE; CHIP;
  62. }
  63. }
  64. External USB-to-UART Bridge
  65. ---------------------------
  66. Sometimes the USB-to-UART bridge is external. This is often used in small development boards or finished products when space and costs are crucial.
  67. .. blockdiag::
  68. :caption: External USB-to-UART Bridge
  69. :align: center
  70. blockdiag external_usb_to_uart_bridge_to_esp {
  71. node_height = 80;
  72. span_width = 160;
  73. span_height = 140;
  74. default_fontsize = 16
  75. # labels of diagram nodes
  76. PC [label="Personal\n Computer"];
  77. BRIDGE [label="USB-to-UART\n Bridge", width=180];
  78. CHIP [label="{IDF_TARGET_NAME}", width=120];
  79. DUMMY [shape=none, width=1]
  80. # node connections
  81. PC <-> BRIDGE [label = "USB", fontsize=14];
  82. BRIDGE <- DUMMY [label = "UART", fontsize=14];
  83. DUMMY -> CHIP [fontsize=14];
  84. group {
  85. shape = line;
  86. style = dotted;
  87. color = "#FF0000";
  88. label = "Programmmer Board\n\n\n";
  89. BRIDGE
  90. }
  91. group {
  92. shape = line;
  93. style = dotted;
  94. color = "#FF0000";
  95. label = "Development Board\n\n\n";
  96. CHIP; DUMMY;
  97. }
  98. }
  99. .. only:: SOC_USB_OTG_SUPPORTED or SOC_USB_SERIAL_JTAG_SUPPORTED
  100. Flash using USB
  101. ---------------
  102. For the {IDF_TARGET_NAME}, the USB peripheral is available, allowing you to flash the binaries without the need for an external USB-to-UART bridge.
  103. {IDF_TARGET_USB_PIN_DM:default="Not Updated!", esp32c3="GPIO18", esp32s3="GPIO19", esp32s2="GPIO19"}
  104. {IDF_TARGET_USB_PIN_DP:default="Not Updated!", esp32c3="GPIO19", esp32s3="GPIO20", esp32s2="GPIO20"}
  105. The USB on the {IDF_TARGET_NAME} uses the **{IDF_TARGET_USB_PIN_DP}** for **D+** and **{IDF_TARGET_USB_PIN_DM}** for **D-**.
  106. .. only:: SOC_USB_SERIAL_JTAG_SUPPORTED
  107. .. note:: The {IDF_TARGET_NAME} supports only *USB CDC and JTAG*.
  108. If you are flashing for the first time, you need to get the {IDF_TARGET_NAME} into the download mode manually. To do so, press and hold the ``BOOT`` button and then press the ``RESET`` button once. After that release the ``BOOT`` button.
  109. .. only:: esp32s2
  110. After flashing the binaries, a manual reset is needed.
  111. Flash using UART
  112. ----------------
  113. This section provides guidance on how to establish a serial connection between {IDF_TARGET_NAME} and PC using USB-to-UART Bridge, either installed on the development board or external.
  114. Connect {IDF_TARGET_NAME} to PC
  115. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  116. Connect the {IDF_TARGET_NAME} board to the PC using the USB cable. If device driver does not install automatically, identify USB-to-UART bridge on your {IDF_TARGET_NAME} board (or external converter dongle), search for drivers in internet and install them.
  117. Below is the list of USB to serial converter chips installed on most of the {IDF_TARGET_NAME} boards produced by Espressif together with links to the drivers:
  118. * CP210x: `CP210x USB to UART Bridge VCP Drivers <https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers>`_
  119. * FTDI: `FTDI Virtual COM Port Drivers <https://ftdichip.com/drivers/vcp-drivers/>`_
  120. Please check the board user guide for specific USB-to-UART bridge chip used. The drivers above are primarily for reference. Under normal circumstances, the drivers should be bundled with an operating system and automatically installed upon connecting the board to the PC.
  121. For devices downloaded using a USB-to-UART bridge, you can run the following command including the optional argument to define the baud rate.
  122. .. code-block:: bash
  123. idf.py -p PORT [-b BAUD] flash
  124. You can change the flasher baud rate by replacing ``BAUD`` with the baud rate you need. The default baud rate is ``460800``.
  125. .. note::
  126. If the device does not support the auto download mode, you need to get into the download mode manually. To do so, press and hold the ``BOOT`` button and then press the ``RESET`` button once. After that release the ``BOOT`` button.
  127. Check port on Windows
  128. ---------------------
  129. Check the list of identified COM ports in the Windows Device Manager. Disconnect {IDF_TARGET_NAME} and connect it back, to verify which port disappears from the list and then shows back again.
  130. Figures below show serial port for ESP32 DevKitC and ESP32 WROVER KIT
  131. .. figure:: ../../_static/esp32-devkitc-in-device-manager.png
  132. :align: center
  133. :alt: USB to UART bridge of ESP32-DevKitC in Windows Device Manager
  134. :figclass: align-center
  135. USB to UART bridge of ESP32-DevKitC in Windows Device Manager
  136. .. figure:: ../../_static/esp32-wrover-kit-in-device-manager.png
  137. :align: center
  138. :alt: Two USB Serial Ports of ESP-WROVER-KIT in Windows Device Manager
  139. :figclass: align-center
  140. Two USB Serial Ports of ESP-WROVER-KIT in Windows Device Manager
  141. Check port on Linux and macOS
  142. -----------------------------
  143. To check the device name for the serial port of your {IDF_TARGET_NAME} board (or external converter dongle), run this command two times, first with the board / dongle unplugged, then with plugged in. The port which appears the second time is the one you need:
  144. Linux ::
  145. ls /dev/tty*
  146. macOS ::
  147. ls /dev/cu.*
  148. .. note::
  149. macOS users: if you don't see the serial port then check you have the USB/serial drivers installed. See Section `Connect {IDF_TARGET_NAME} to PC`_ for links to drivers. For macOS High Sierra (10.13), you may also have to explicitly allow the drivers to load. Open System Preferences -> Security & Privacy -> General and check if there is a message shown here about "System Software from developer ..." where the developer name is Silicon Labs or FTDI.
  150. .. _linux-dialout-group:
  151. Adding user to ``dialout`` on Linux
  152. -----------------------------------
  153. The currently logged user should have read and write access the serial port over USB. On most Linux distributions, this is done by adding the user to ``dialout`` group with the following command::
  154. sudo usermod -a -G dialout $USER
  155. on Arch Linux this is done by adding the user to ``uucp`` group with the following command::
  156. sudo usermod -a -G uucp $USER
  157. Make sure you re-login to enable read and write permissions for the serial port.
  158. Verify serial connection
  159. ------------------------
  160. Now verify that the serial connection is operational. You can do this using a serial terminal program by checking if you get any output on the terminal after resetting {IDF_TARGET_NAME}.
  161. .. only:: esp32c2
  162. The default console baudrate on ESP32-C2 is 115200 when using a 40MHz XTAL, or 74880 when using a 26MHz XTAL.
  163. .. only:: not esp32c2
  164. The default console baudrate on {IDF_TARGET_NAME} is 115200.
  165. Windows and Linux
  166. ^^^^^^^^^^^^^^^^^
  167. In this example we will use `PuTTY SSH Client <https://www.putty.org/>`_ that is available for both Windows and Linux. You can use other serial programs and set communication parameters like below.
  168. Run terminal, set identified serial port, baud rate = 115200 (change this to the default baudrate your chip is using), data bits = 8, stop bits = 1, and parity = N. Below are example screen shots of setting the port and such transmission parameters (in short described as 115200-8-1-N) on Windows and Linux. Remember to select exactly the same serial port you have identified in steps above.
  169. .. figure:: ../../_static/putty-settings-windows.png
  170. :align: center
  171. :alt: Setting Serial Communication in PuTTY on Windows
  172. :figclass: align-center
  173. Setting Serial Communication in PuTTY on Windows
  174. .. figure:: ../../_static/putty-settings-linux.png
  175. :align: center
  176. :alt: Setting Serial Communication in PuTTY on Linux
  177. :figclass: align-center
  178. Setting Serial Communication in PuTTY on Linux
  179. Then open serial port in terminal and check, if you see any log printed out by {IDF_TARGET_NAME}. The log contents will depend on application loaded to {IDF_TARGET_NAME}, see `Example Output`_.
  180. .. note::
  181. Close the serial terminal after verification that communication is working. If you keep the terminal session open, the serial port will be inaccessible for uploading firmware later.
  182. macOS
  183. ^^^^^
  184. To spare you the trouble of installing a serial terminal program, macOS offers the **screen** command.
  185. - As discussed in `Check port on Linux and macOS`_, run::
  186. ls /dev/cu.*
  187. - You should see similar output::
  188. /dev/cu.Bluetooth-Incoming-Port /dev/cu.SLAB_USBtoUART /dev/cu.SLAB_USBtoUART7
  189. - The output will vary depending on the type and the number of boards connected to your PC. Then pick the device name of your board and run (change 115200 to the default baudrate your chip is using)::
  190. screen /dev/cu.device_name 115200
  191. Replace ``device_name`` with the name found running ``ls /dev/cu.*``.
  192. - What you are looking for is some log displayed by the **screen**. The log contents will depend on application loaded to {IDF_TARGET_NAME}, see `Example Output`_. To exit the **screen** session type Ctrl-A + \\ .
  193. .. note::
  194. Do not forget to **exit the screen session** after verifying that the communication is working. If you fail to do it and just close the terminal window, the serial port will be inaccessible for uploading firmware later.
  195. Example Output
  196. ^^^^^^^^^^^^^^
  197. An example log is shown below. Reset the board if you do not see anything.
  198. .. highlight:: none
  199. ::
  200. ets Jun 8 2016 00:22:57
  201. rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  202. ets Jun 8 2016 00:22:57
  203. rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  204. configsip: 0, SPIWP:0x00
  205. clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
  206. mode:DIO, clock div:2
  207. load:0x3fff0008,len:8
  208. load:0x3fff0010,len:3464
  209. load:0x40078000,len:7828
  210. load:0x40080000,len:252
  211. entry 0x40080034
  212. I (44) boot: ESP-IDF v2.0-rc1-401-gf9fba35 2nd stage bootloader
  213. I (45) boot: compile time 18:48:10
  214. ...
  215. If you can see readable log output, it means serial connection is working and you are ready to proceed with installation and finally upload of application to {IDF_TARGET_NAME}.
  216. .. note::
  217. For some serial port wiring configurations, the serial RTS & DTR pins need to be disabled in the terminal program before the {IDF_TARGET_NAME} will boot and produce serial output. This depends on the hardware itself, most development boards (including all Espressif boards) *do not* have this issue. The issue is present if RTS & DTR are wired directly to the EN & GPIO0 pins. See the `esptool documentation`_ for more details.
  218. If you got here from :ref:`get-started-connect` when installing s/w for {IDF_TARGET_NAME} development, then you can continue with :ref:`get-started-configure`.
  219. .. _esptool documentation: https://docs.espressif.com/projects/esptool/en/latest/advanced-topics/boot-mode-selection.html#automatic-bootloader