dfu.rst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ***********************************************
  2. Device Firmware Upgrade through USB
  3. ***********************************************
  4. .. only:: esp32
  5. .. note::
  6. Device Firmware Upgrade through USB is not supported with ESP32 chips.
  7. Device Firmware Upgrade (DFU) is a mechanism for upgrading the firmware of devices through Universal Serial Bus (USB).
  8. DFU is supported by {IDF_TARGET_NAME} chips. The necessary connections for the USB peripheral are shown in the following table.
  9. +------+-------------+
  10. | GPIO | USB |
  11. +======+=============+
  12. | 20 | D+ (green) |
  13. +------+-------------+
  14. | 19 | D- (white) |
  15. +------+-------------+
  16. | GND | GND (black) |
  17. +------+-------------+
  18. | +5V | +5V (red) |
  19. +------+-------------+
  20. .. only:: esp32s3
  21. By default, :doc:`USB_SERIAL_JTAG<usb-serial-jtag-console>` module is connected to the internal PHY of the ESP32-S3, while USB_OTG peripheral can be used only if the external USB PHY is connected. Since DFU mode is provided via USB_OTG peripheral, it cannot be used through the internal PHY in this configuration.
  22. You can permanently switch the internal USB PHY to work with USB_OTG peripheral instead of USB_SERIAL_JTAG by burning ``USB_PHY_SEL`` eFuse. See ESP32-S3 Technical Reference Manual for more details about USB_SERIAL_JTAG and USB_OTG.
  23. .. note::
  24. The {IDF_TARGET_NAME} chip needs to be in bootloader mode for the detection as a DFU device and flashing. This can be
  25. achieved by pulling GPIO0 down (e.g. pressing the BOOT button), pulsing RESET down for a moment and releasing
  26. GPIO0.
  27. .. warning::
  28. Some cables are wired up with non-standard colors and some drivers are able to work with swapped D+ and D-
  29. connections. Please try to swap the cables connecting to D+ and D- if your device is not detected.
  30. The software requirements of DFU are included in :ref:`get-started-get-prerequisites` of the Getting Started Guide.
  31. Section :ref:`api_guide_dfu_build` describes how to build firmware for DFU with ESP-IDF and
  32. Section :ref:`api_guide_dfu_flash` deals with flashing the firmware.
  33. .. _api_guide_dfu_build:
  34. Building the DFU Image
  35. ======================
  36. The DFU image can be created by running::
  37. idf.py dfu
  38. which creates ``dfu.bin`` in the build directory.
  39. .. note::
  40. Don't forget to set the target chip by ``idf.py set-target`` before running ``idf.py dfu``. Otherwise, you might
  41. create an image for a different chip or receive an error message something like ``unknown target 'dfu'``.
  42. .. _api_guide_dfu_flash:
  43. Flashing the Chip with the DFU Image
  44. ====================================
  45. The DFU image is downloaded into the chip by running::
  46. idf.py dfu-flash
  47. which relies on `dfu-util <http://dfu-util.sourceforge.net/>`_. Please see :ref:`get-started-get-prerequisites` for
  48. installing ``dfu-util``. ``dfu-util`` needs additional setup for :ref:`api_guide_dfu_flash_win` or setting up an
  49. :ref:`api_guide_dfu_flash_udev`. Mac OS users should be able to use ``dfu-util`` without further setup.
  50. If there are more boards with the same chip connected then ``idf.py dfu-list`` can be used to list the available
  51. devices, for example::
  52. Found Runtime: [303a:0002] ver=0723, devnum=4, cfg=1, intf=2, path="1-10", alt=0, name="UNKNOWN", serial="0"
  53. Found Runtime: [303a:0002] ver=0723, devnum=6, cfg=1, intf=2, path="1-2", alt=0, name="UNKNOWN", serial="0"
  54. Consequently, the desired device can be selected for flashing by the ``--path`` argument. For example, the devices
  55. listed above can be flashed individually by the following commands::
  56. idf.py dfu-flash --path 1-10
  57. idf.py dfu-flash --path 1-2
  58. .. note::
  59. The vendor and product identificators are set based on the selected chip target by the ``idf.py set-target``
  60. command and it is not selectable during the ``idf.py dfu-flash`` call.
  61. See :ref:`api_guide_dfu_flash_errors` and their solutions.
  62. .. _api_guide_dfu_flash_udev:
  63. udev rule (Linux only)
  64. ----------------------
  65. udev is a device manager for the Linux kernel. It allows us to run ``dfu-util`` (and ``idf.py dfu-flash``) without
  66. ``sudo`` for gaining access to the chip.
  67. Create file ``/etc/udev/rules.d/40-dfuse.rules`` with the following content::
  68. SUBSYSTEMS=="usb", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="00??", GROUP="plugdev", MODE="0666"
  69. .. note::
  70. Please check the output of command ``groups``. The user has to be a member of the `GROUP` specified above. You may
  71. use some other existing group for this purpose (e.g. `uucp` on some systems instead of `plugdev`) or create a new
  72. group for this purpose.
  73. Restart your computer so the previous setting could take into affect or run ``sudo udevadm trigger`` to force
  74. manually udev to trigger your new rule.
  75. .. _api_guide_dfu_flash_win:
  76. USB drivers (Windows only)
  77. --------------------------
  78. ``dfu-util`` uses `libusb` to access the device. You have to register on Windows the device with the `WinUSB` driver.
  79. Please see the `libusb wiki <https://github.com/libusb/libusb/wiki/Windows#How_to_use_libusb_on_Windows>`_ for more
  80. details.
  81. The drivers can be installed by the `Zadig tool <https://zadig.akeo.ie/>`_. Please make sure that the device is in
  82. download mode before running the tool and that it detects the {IDF_TARGET_NAME} device before installing the drivers. The Zadig
  83. tool might detect several USB interfaces of {IDF_TARGET_NAME}. Please install the WinUSB driver for only that interface for
  84. which there is no driver installed (probably it is Interface 2) and don't re-install the driver for the other interface.
  85. .. warning::
  86. The manual installation of the driver in Device Manager of Windows is not recommended because the flashing might
  87. not work properly.
  88. .. _api_guide_dfu_flash_errors:
  89. Common errors and known issues
  90. ------------------------------
  91. - ``dfu-util: command not found`` might indicate that the tool hasn't been installed or is not available from the terminal.
  92. An easy way of checking the tool is running ``dfu-util --version``. Please see :ref:`get-started-get-prerequisites` for
  93. installing ``dfu-util``.
  94. - The reason for ``No DFU capable USB device available`` could be that the USB driver wasn't properly installed on
  95. Windows (see :ref:`api_guide_dfu_flash_win`), udev rule was not setup on Linux
  96. (see :ref:`api_guide_dfu_flash_udev`) or the device isn't in bootloader mode.
  97. - Flashing with ``dfu-util`` on Windows fails on the first attempt with error ``Lost device after RESET?``. Please
  98. retry the flashing and it should succeed the next time.