USB DFU (DFU mode) implementation for ESP32-S2 based on tinyUSB
Go to file
King Kévin 4a53aab483 dfu: upload returns partition data 2022-07-23 13:01:23 +02:00
.github add get-dependencies.py 2022-07-01 17:23:14 +07:00
docs add get-deps target 2022-07-01 16:24:58 +07:00
examples dfu: upload returns partition data 2022-07-23 13:01:23 +02:00
hw support UART write on ESP32-S2-based boards 2022-07-23 12:44:17 +02:00
lib Remove lib/Pico-PIO-USB, which has moved to hw/mcu/raspberry_pi/Pico-PIO-USB. 2022-05-27 11:54:28 -04:00
src Merge pull request #1514 from maddyaby/audiod_typo 2022-07-19 17:10:45 +07:00
test Add test CI. 2021-06-30 20:30:03 +02:00
tools add get-dependencies.py 2022-07-01 17:23:14 +07:00
.gitattributes Add gitattributes 2020-01-15 14:46:12 -05:00
.gitignore Unify skip and only logic for build scripts 2022-01-05 15:44:23 -08:00
.gitmodules add upstream Pico-PIO-USB 2022-05-16 13:44:06 +07:00
.readthedocs.yaml rename to .readthedocs.yaml 2021-08-05 12:29:32 +07:00
CODE_OF_CONDUCT.rst code_of_conduct: refactor file from markdown to restructuredtext 2021-07-30 12:46:30 +01:00
CONTRIBUTORS.rst increase version, update doc for release 2022-02-23 11:55:57 +07:00
LICENSE migrate license from BSD 3 clause to MIT 2019-03-20 16:11:42 +07:00
README.md doc: add project README 2022-07-23 12:35:02 +02:00
README.rst update readme 2022-06-16 14:41:10 +07:00
pkg.yml Change mynewt package type to sdk 2020-05-07 10:11:58 +02:00
repository.yml Add missing releases to Mynewt repository.yml 2022-03-07 15:33:27 +01:00
version.yml add repo & version yml 2018-09-02 16:44:27 +07:00

README.md

This is a USB DFU (DFU mode) implementation for ESP32-S2 based on tinyUSB. It allows flashing the firmware using dfu-util.

design choice

ESP-IDF

The ESP-IDF uses tinyUSB, but only offers few profiles (e.g. CDC, MSC). They are defined in 'esp-idf/components/tinyusb/additions', and re-use the tinyUSB device implementations. But there is no DFU implementation (runtime or DFU mode).

TinyUSB

TinyUSB is a generic USB stack for micro-controllers. It supports ESP32-S2. DFU is implemented and there is an example. This example can't be used for ESP32-S2 though. I've added freeRTOS to it so it can be used on the ESP32-S2.

bootloader

The ESP-IDF allows you to have a custom bootloader (2nd stage), but I was not able to add freeRTOS to it, required by the tinyUSB implementation.

factory

This USB DFU implementation is flashed as a factory application image. It will then flash the main firmware image into the OTA0 partition. Thus it requires a custom partition table, with a "small" factory partition, just one OTA application partition, and one OTA data partition. The factory partition should be 200 KB. This is super large for just a "bootloader" to flash firmware images, but since ESP32 often use large external flash memory, this is not too much of an issue. Feel free to reuse the 'partitions.csv' file as example.

alternatives

ESP-ROM

The ESP-S2 comes with a ROM bootloader that already allows you to flash over USB using the serial CDC ACM profile. But this method does not let you restart into the main firmware. The ROM bootloader USB stack even offers DFU capability, and you can flash using dfu-util. But this one also does not let you restart into the main firmware.

To flash using USB serial (can't restart the device):

idf.py -p /dev/ttyACM0 flash
...
WARNING: ESP32-S2 chip was placed into download mode using GPIO0.
esptool.py can not exit the download mode over USB. To run the app, reset the chip manually.
To suppress this note, set --after option to 'no_reset'.

And to flash using DFU:

# generate the DFU binary (not the same as the usual flash binary)
idf.py dfu
dfu-util --device 303a:0002 --download build/dfu.bin
# or
idf.py dfu-flash

Note: after detaching, the bootloader claims for be in runtime mode, but this is still the bootloader, and not the flashed firmware.

TinyUF2

TinyUF2 is a UF2 bootloader by Adafruit. It is based on TinyUSB, and supports ESP32-S2. It uses the DFU name (Device Firmware Upgrade), but it's not the DFU specified by USB. Instead it provides a MSC interface where you can copy the firmware binary file to.