Expand description
USB-CDC-ACM device with esptool auto-reset support.
The Lolin S2 Mini has no USB-UART bridge, so esptool cannot toggle GPIO0/EN via physical DTR/RTS pins. Instead, the firmware exposes the native USB-OTG port as a CDC-ACM device and interprets the CDC control-line state the way the classic devkit reset sequence does:
| DTR | RTS | Meaning | Action |
|---|---|---|---|
| 1 | 0 | IO0 low | set FORCE_DOWNLOAD_BOOT |
| 0 | 1 | EN low (reset) | software reset |
| 0 | 0 | idle | clear FORCE_DOWNLOAD_BOOT |
| 1 | 1 | transient | no-op |
esptoolβs --before usb-reset walk is (0,0) -> (1,0) -> (0,1) -> (0,0): the (1,0) state arms FORCE_DOWNLOAD_BOOT, then (0,1)
resets into the ROM bootloader.
The flag lives in the RTC domain and survives software resets. The ROM
bootloader does not clear it on entry β after a flash the chip would
stay stuck in the bootloader forever (until power-on). inv flash
therefore clears the flag itself after flashing (esptool write-reg 0x3F408128 0 0x1 through the stub) and then resets via the RTC watchdog,
which boots the application.
The same task also drains the log ring from crate::logging over the
CDC data endpoint, so inv monitor shows the firmware log output.
ConstantsΒ§
- LOG_
CHUNK π - Log chunk size handed to the CDC endpoint (matches
max_packet_size). - POLL_
INTERVAL π - Line-poll interval of the DTR/RTS state machine.
- USB_PID π
- Espressif generic CDC-ACM product ID.
- USB_VID π
- Espressif USB vendor ID (same as the ROM bootloader).
StaticsΒ§
- BOS_
DESCRIPTOR π - Buffer for the generated USB configuration descriptor.
- CDC_
STATE π - Scratch buffer for USB control transfers.
- CONFIG_
DESCRIPTOR π - Bulk OUT endpoint buffer for the CDC data endpoint.
- CONTROL_
BUF π - Buffer for the generated USB BOS descriptor.
- EP_
OUT_ πBUFFER - The S2 peripheral types are invariant in their lifetime, which pins the
USB driver to
'static; the embassy-usb buffers therefore must be'statictoo. They are initialized exactly once at task start.
FunctionsΒ§
- control_
and_ πlog - Runs the DTR/RTS state machine and drains the log ring into the host.
- enter_
bootloader π - Resets into the ROM USB-CDC download mode (bootloader).
- flush_
logs π - Copies pending log lines from the ring into the CDC endpoint until the
ring is empty or the endpoint errors out. See
control_and_logfor the cancellation-safety argument. - set_
force_ πdownload - Set or clear the ROM
FORCE_DOWNLOAD_BOOTflag inRTC_CNTL_OPTION1. - task
- Runs the USB-CDC-ACM device and the esptool reset protocol.