Skip to content

ESP32 UART Bridge Fix (Flash ESP32 via Pico) - #243

Open
DynaMight1124 wants to merge 60 commits into
wiredopposite:masterfrom
DynaMight1124:UARTBridge-fix
Open

DynaMight1124 wants to merge 60 commits into
wiredopposite:masterfrom
DynaMight1124:UARTBridge-fix

Conversation

@DynaMight1124

Copy link
Copy Markdown

Hi

I created a Xbox DVD Dongle that used a Pico and ESP32 along with a PCB. I loved the idea of being able to flash the ESP32 directly from the Pico as it allowed the device to be sealed, but I could never get it to work, I raised an issue prev #187

Recently found Gemini CLI when it can scan entire codebases and after some back and forth, its now working! You're welcome to put your own spin on it, I asked if ALL the files updated were required and it indicated it was.

Heres the AI stuff about the changes:
The following 7 files contain the complete and verified fix for the ESP32 flashing issue:

  1. Firmware/RP2040/src/USBDevice/DeviceDriver/UARTBridge/uart_bridge/uart_bridge.c
  • Auto-Reset Logic: Implemented the specific DTR/RTS signal mapping required for direct (transistor-less) Pico-to-ESP32 connections.
  • Protection Window: Added a 5-second ignore window for DTR/RTS signals upon entering UART mode. This prevents the OS from accidentally knocking the ESP32 out of its manual bootloader state when the COM port is first opened.
  • High-Speed Stability: Moved UART handling to a high-priority polling loop on Core 1 and added volatile memory protection to prevent data loss at high baud rates.
  • Auto-Exit: Restored the logic to detect the PROGRAMMING_COMPLETE flag so the Pico reboots back to controller mode automatically.
  1. Firmware/RP2040/src/USBDevice/DeviceDriver/UARTBridge/uart_bridge/uart_bridge.h
  • Updated declarations to expose the new bridge control and callback functions.
  1. Firmware/RP2040/src/Board/esp32_api.cpp
  • Improved Timing: Refined the enter_programming_mode() sequence to hold the Boot pin (GPIO0) LOW for a full 500ms after reset, ensuring the ESP32 reliably catches the bootloader state.
  1. Firmware/RP2040/src/tusb_config.h
  • Performance: Increased CDC TX/RX buffer sizes from 256 to 1024 bytes. This is required to prevent "Sync" errors when flashing at high speeds (e.g., 921600 baud).
  1. Firmware/RP2040/src/USBDevice/tud_callbacks.cpp
  • Infrastructure: Linked the global TinyUSB CDC events (Line State/Coding) to the internal driver system so the UART bridge can actually "hear" the DTR/RTS signals from the PC.
  1. Firmware/RP2040/src/USBDevice/DeviceDriver/DeviceDriver.h
  • Architecture: Added virtual methods for CDC callbacks to the base driver class, allowing the UART bridge to implement them without breaking other drivers.

MegaCadeDev and others added 30 commits July 30, 2025 14:55
Added IDs for Wii U Pro Controller, 8BitDo Ultimate Bluetooth Controller, Switch 1 Joy cons (Left and Right) and Ouya Gen 1 Controller.
Fixed Wii and Wii U controller support, RB LB and RT LT work now for both controllers
Updated README to reflect the fork status and added new features for Wii U Pro and Wii Remotes. Changed purchase link to the original creator's store.
Clarified the installation instructions for ESP-IDF and BTStack.
Updated repository URL in the cloning instructions.
Updated supported platforms and added new features for Wii U and Switch.
Updated project name and year in README.
…ways-send; remove scripts from repo

- docs/README.md: project overview, output modes, XInput/360, latency, building
- docs/IMPROVEMENTS.md: XInput/360 section, latency default 0, always-send in XInput
- MAIN_LOOP_DELAY_US default 0 (Config.h, CMakeLists.txt)
- XInput process(): always send latest state when USB ready
- .gitignore: add Firmware/RP2040/scripts; scripts removed from tracking (not shipped with build)

Made-with: Cursor
Updated README to include new features and changes for version 1.0.0.4a and 1.0.0.3a patched.
- Switch mode: full Nintendo Switch Pro Controller emulation (report format, subcommands, init handshake)
- SwitchPro.h: correct Pro report button byte layout (Y/X/B/A bits per hardware reference)
- Switch device: face-button mapping and SwitchProDevice.h descriptors
- README: Switch Pro emulation description, retro-pico-switch attribution, version 1.0.0.5a
- Version bump to v1.0.0a5 (FWDefines.cmake)
- .gitignore: exclude Firmware/RP2040/build_* (release build dirs)

Made-with: Cursor
Added a link to join the Discord community for support.
… sensitivity; docs

- Board support: RP2350_ZERO, RP2040_XIAO, RP2354 (Config.h, OGXMini.cpp, Standard.cpp, CMakeLists.txt)
- Xbox360: 8BitDo LED keepalive for VID 0x2DC8 / PID 0x3016, 0x3106
- Switch: analog stick sensitivity gain (1.2x, STICK_GAIN in Switch.cpp)
- Main loop: tud_task() before process() in PicoW, Standard, Four_Channel_I2C for latency
- README: new build options, features (boards, 8BitDo, Switch sensitivity), Sakura attribution
- IMPROVEMENTS.md: board support, 8BitDo fix, Switch sensitivity sections and summary

Made-with: Cursor
…/PS1PS2, version bump

- Gamepad: 2-entry pad_in queue to avoid dropping fast button/stick inputs (BT vs main loop race)
- FWDefines: bump version to v1.0.0a6
- Docs: BLUEPAD32_PS4_PS5_PARSING (Xbox vs DS4/DS5), Dreamcast_Port, GPIO_Output_Pinout_and_Mappings
- Bluepad32 parser: skip gyro/accel/touchpad for DS4/DS5 (Xbox-style path for lower latency); patch in patches/bluepad32_ps4_ps5_latency.diff
- GPIO output: Dreamcast, GameCube, N64, PS1/PS2 device drivers and GPIOHost (joybus, maple, psx)
- README, CMake, DeviceManager, UserSettings, HostManager updates for new modes and boards

Made-with: Cursor
MegaCadeDev and others added 29 commits March 10, 2026 05:53
… RP2040 docs README

- PS5 host: always push every DualSense report (no skip) so OG Xbox mode does not drop inputs
- IMPROVEMENTS.md: document DualSense/OG Xbox change and Xbox OG latency behaviour
- .gitignore: ignore local-only docs (Input_Controllers_Research, Other_Projects_Output_Modes, Wired_Retro_Controllers)
- Firmware/RP2040/docs/README.md: add GPIO pinout, Dreamcast port, update IMPROVEMENTS description
- Other staged changes: board/PS1PS2/GameCube/N64/Dreamcast/UserSettings/PicoW/bluepad32-related

Made-with: Cursor
- FW_VERSION v1.0.0a8 (FWDefines.cmake)
- Bluepad32: BLE ads off during Classic ACL, BR inquiry pause, DS4 Pico path,
  Xbox BLE stale-slot reconnect (submodule → MegaCadeDev/bluepad32 fork)
- Tinyusb: default remote wakeup when config advertises RW (submodule fork)
- .gitmodules: bluepad32 & tinyusb → MegaCadeDev forks (see Firmware/docs/Submodule_forks.md)
- README, CHANGELOG, IMPROVEMENTS, Wired_Controllers; PS2/OG Xbox IGR, etc.

Made-with: Cursor
- Switch2ProHost: full digital mapping from 10-byte payload; bulk bring-up
- Optional OGXM_SWITCH2_HID_RAW_LOG (Debug); build scripts prompt
- Docs: Wired_Controllers, README, CHANGELOG; FW v1.0.0a9
- ogxm_log via stdio UART; controller_capture tooling
Updated controller support details and hardware notes.
…chpad-mask

Fix wired DS4 PS/touchpad button masking in PS4 USB host parser
…eiver.

Reliable wired USB host on PIO adapters (RP2350-USB-A validated): SOF servicing,
Switch 1/2 Pro init and mapping, DualShock 3 enable/keepalive, 360 wireless
receiver four-port sync, Pico W unplug watchdog, and I2C pad wire format fix.

Co-authored-by: Cursor <cursoragent@cursor.com>
Vendor GIP init and 30-byte XBOFS input path for 1532:0a00 on PIO USB host; document Atrox and related arcade sticks in wired controller lists.

Co-authored-by: Cursor <cursoragent@cursor.com>
…resh.

Ship STEAM DualSense+touchpad mouse output, PS3/PS4 motion, Steam Controller 2026 BLE, and related Pico W fixes; update README with social links, branding images, and support guidance.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Pico SDK 2.1 still referenced hids_client.c; point it at hids_host.c and
hci_event_builder.c. Rename MAX_NR_HIDS_HOSTS and bump bluepad32 to the tip
with DS5 touchpad + steam instance merge fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Skip HOGP for Triton, quiet CYW43 scans during BLE connect, and bump
the firmware version after restoring input on Pico W.

Co-authored-by: Cursor <cursoragent@cursor.com>
…pposite#86).

Restore Bluepad32 GAP inquiry defaults so Android/D-input 8BitDo pads
discover reliably; reboot only after Xbox BLE ready disconnects so Classic
BT reconnects without freezing OG Xbox; drop stale BLE slots on USB resume;
register Pro 2 Android PIDs.

Co-authored-by: Gary L <MegaCadeDev@users.noreply.github.com>
…osite#47 wiredopposite#54 wiredopposite#87 wiredopposite#27).

Quiet BT during PIO host-up, drop idle false-unplug, OG Xbox Core0 yield, DS4 HID keepalive, and Series Guide press/release without the 80 ms pulse overcorrection. Builds on wiredopposite#86.

Co-authored-by: Cursor <cursoragent@cursor.com>
Reorganize README and firmware docs (architecture, build, support issues, planned work, mode guides) and restore reliable Xbox One/Series GIP bring-up on Pico W USB host.

Co-authored-by: Cursor <cursoragent@cursor.com>
Clarify that only Wii U GameCube Adapter mode is supported for MAX_GAMEPADS>1 builds, and that Tools/controller_capture scripts are not accepted for mapping submissions—adapter-side Debug UART capture is required instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
   * Auto-Reset Logic: Implemented the specific DTR/RTS signal mapping required for direct (transistor-less) Pico-to-ESP32 connections.
   * Protection Window: Added a 5-second ignore window for DTR/RTS signals upon entering UART mode. This prevents the OS from accidentally knocking the ESP32 out of its manual bootloader state when the COM port
     is first opened.
   * High-Speed Stability: Moved UART handling to a high-priority polling loop on Core 1 and added volatile memory protection to prevent data loss at high baud rates.
   * Auto-Exit: Restored the logic to detect the PROGRAMMING_COMPLETE flag so the Pico reboots back to controller mode automatically.
Updated declarations to expose the new bridge control and callback functions.
Implementation: Overrode the new CDC callbacks to pass signal data directly into the core bridge logic.
Implementation: Overrode the new CDC callbacks to pass signal data directly into the core bridge logic.
Improved Timing: Refined the enter_programming_mode() sequence to hold the Boot pin (GPIO0) LOW for a full 500ms after reset, ensuring the ESP32 reliably catches the bootloader state.
Performance: Increased CDC TX/RX buffer sizes from 256 to 1024 bytes. This is required to prevent "Sync" errors when flashing at high speeds (e.g., 921600 baud).
Infrastructure: Linked the global TinyUSB CDC events (Line State/Coding) to the internal driver system so the UART bridge can actually "hear" the DTR/RTS signals from the PC.
Architecture: Added virtual methods for CDC callbacks to the base driver class, allowing the UART bridge to implement them without breaking other drivers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants