dfu.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 ESP32-S2 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. .. note::
  21. The ESP32-S2 chip needs to be in bootloader mode for the detection as a DFU device and flashing. This can be
  22. achieved by pulling GPIO0 down (e.g. pressing the BOOT button), pulsing RESET down for a moment and releasing
  23. GPIO0.
  24. .. warning::
  25. Some cables are wired up with non-standard colors and some drivers are able to work with swapped D+ and D-
  26. connections. Please try to swap the cables connecting to D+ and D- if your device is not detected.
  27. The software requirements of DFU are included in :ref:`get-started-get-prerequisites` of the Getting Started Guide.
  28. Section :ref:`api_guide_dfu_build` describes how to build firmware for DFU with ESP-IDF and
  29. Section :ref:`api_guide_dfu_flash` deals with flashing the firmware.
  30. .. _api_guide_dfu_build:
  31. Building the DFU Image
  32. ======================
  33. The DFU image can be created by running::
  34. idf.py dfu
  35. which creates ``dfu.bin`` in the build directory.
  36. .. note::
  37. Don't forget to set the target chip by ``idf.py set-target`` before running ``idf.py dfu``. Otherwise, you might
  38. create an image for a different chip or receive an error message something like ``unknown target 'dfu'``.
  39. .. _api_guide_dfu_flash:
  40. Flashing the Chip with the DFU Image
  41. ====================================
  42. The DFU image is downloaded into the chip by running::
  43. idf.py dfu-flash
  44. which relies on `dfu-util <http://dfu-util.sourceforge.net/>`_. Please see :ref:`get-started-get-prerequisites` for
  45. installing ``dfu-util``. ``dfu-util`` needs additional setup for :ref:`api_guide_dfu_flash_win` or setting up an
  46. :ref:`api_guide_dfu_flash_udev`. Mac OS users should be able to use ``dfu-util`` without further setup.
  47. See :ref:`api_guide_dfu_flash_errors` and their solutions.
  48. .. _api_guide_dfu_flash_udev:
  49. udev rule (Linux only)
  50. ----------------------
  51. udev is a device manager for the Linux kernel. It allows us to run ``dfu-util`` (and ``idf.py dfu-flash``) without
  52. ``sudo`` for gaining access to the chip.
  53. Create file ``/etc/udev/rules.d/40-dfuse.rules`` with the following content::
  54. SUBSYSTEMS=="usb", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="00??", GROUP="plugdev", MODE="0666"
  55. .. note::
  56. Please check the output of command ``groups``. The user has to be a member of the `GROUP` specified above. You may
  57. use some other existing group for this purpose (e.g. `uucp` on some systems instead of `plugdev`) or create a new
  58. group for this purpose.
  59. Restart your computer so the previous setting could take into affect or run ``sudo udevadm trigger`` to force
  60. manually udev to trigger your new rule.
  61. .. _api_guide_dfu_flash_win:
  62. USB drivers (Windows only)
  63. --------------------------
  64. ``dfu-util`` uses `libusb` to access the device. You have to register on Windows the device with the `WinUSB` driver.
  65. Please see the `libusb wiki <https://github.com/libusb/libusb/wiki/Windows#How_to_use_libusb_on_Windows>`_ for more
  66. details.
  67. The drivers can be installed by the `Zadig tool <https://zadig.akeo.ie/>`_. Please make sure that the device is in
  68. download mode before running the tool and that it detects the ESP32-S2 device before installing the drivers. The Zadig
  69. tool might detect several USB interfaces of ESP32-S2. Please install the WinUSB driver for only that interface for
  70. which there is no driver installed (probably it is Interface 2) and don't re-install the driver for the other interface.
  71. .. warning::
  72. The manual installation of the driver in Device Manager of Windows is not recommended because the flashing might
  73. not work properly.
  74. .. _api_guide_dfu_flash_errors:
  75. Common errors and known issues
  76. ------------------------------
  77. - ``dfu-util: command not found`` might indicate that the tool hasn't been installed or is not available from the terminal.
  78. An easy way of checking the tool is running ``dfu-util --version``. Please see :ref:`get-started-get-prerequisites` for
  79. installing ``dfu-util``.
  80. - The reason for ``No DFU capable USB device available`` could be that the USB driver wasn't properly installed on
  81. Windows (see :ref:`api_guide_dfu_flash_win`), udev rule was not setup on Linux
  82. (see :ref:`api_guide_dfu_flash_udev`) or the device isn't in bootloader mode.
  83. - Flashing with ``dfu-util`` on Windows fails on the first attempt with error ``Lost device after RESET?``. Please
  84. retry the flashing and it should succeed the next time.