Skip to content

ESP32 UART Bridge Fix (Flash ESP32 via Pico)#18

Open
DynaMight1124 wants to merge 8 commits into
MegaCadeDev:masterfrom
DynaMight1124:UARTBridge-fix
Open

ESP32 UART Bridge Fix (Flash ESP32 via Pico)#18
DynaMight1124 wants to merge 8 commits into
MegaCadeDev:masterfrom
DynaMight1124:UARTBridge-fix

Conversation

@DynaMight1124

Copy link
Copy Markdown

Hi

Heres another AI fix, the original dev created a UART bridge that cleverly allowed the Pico to programme the ESP32 however I could never get it to work, however AI added some fixes that worked and now it programmes perfectly. Granted it is a little bit of a niche setup using an ESP32 for the BT side, but there are some uses such as limited space. I had recently designed a PCB that fitted into an old Xbox DVD dongle and a Pico-W was too long so went with the Pico/ESP32 sandwiched either side.

Heres some AI info on what files were changed and why:

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.

   * 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.
@MegaCadeDev

Copy link
Copy Markdown
Owner

I'll take a look at these requests when I have time I've just been busy, promise I'm not ignoring you!

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.

2 participants