Skip to content

Improvements ESP32 CDC/UART detection - #3489

Open
josesimoes wants to merge 4 commits into
nanoframework:mainfrom
josesimoes:fix-esp32-cdc
Open

Improvements ESP32 CDC/UART detection#3489
josesimoes wants to merge 4 commits into
nanoframework:mainfrom
josesimoes:fix-esp32-cdc

Conversation

@josesimoes

Copy link
Copy Markdown
Member

Description

  • Rework detection for S2 as its the only series with USB-OTG only.
  • Moved WP_TransportType to it's own header file to allow inclusion from C and C++.
  • Adjust sdkconfig to use default console to free TinyUSB.
  • Update S2 defconfig to use only CDC for WP transport.
  • Disabled graphics and touch for S2 build.

Motivation and Context

  • Resolves S2 not booting.
  • Hardening UART/USB detection for WP transport.

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

- Rework detection for S2 as its the only series with USB-OTG only.
- Moved WP_TransportType to it's own header file to allow inclusion from C and C++.
- Adjust sdkconfig to use default console to free TinyUSB.
- Update S2 defconfig to use only CDC for WP transport.
- Disabled graphics and touch for S2 build.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@josesimoes, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: a9ce6b63-df78-42af-8f0c-4aa157e612d0

📥 Commits

Reviewing files that changed from the base of the PR and between 51b55c4 and 12df33a.

📒 Files selected for processing (1)
  • targets/ESP32/_nanoCLR/System.IO.Ports/sys_io_ser_native_System_IO_Ports_SerialPort.cpp
📝 Walkthrough

Walkthrough

ESP32 transport handling now uses a shared transport definition, adjusts TinyUSB and fallback initialization, applies runtime USB-JTAG reset behavior, and updates ESP32-S2 configuration for UART console, USB CDC, graphics, and touch support.

Changes

ESP32 transport integration

Layer / File(s) Summary
Shared transport contract and runtime consumers
targets/ESP32/_include/WireProtocol_Transport.h, targets/ESP32/_common/WireProtocol_HAL_Interface.c, targets/ESP32/_nanoCLR/...
Defines shared transport types and state, and uses the runtime transport in Wire Protocol, serial-port, and reset handling.
Transport selection and initialization
targets/ESP32/_common/WireProtocol_HAL_Interface.c
Excludes UART fallback when TinyUSB is active, restricts destructive probing to fallback-capable builds, records initialization state, and dispatches I/O through the selected transport.
ESP32-S2 transport and feature configuration
targets/ESP32/_IDF/sdkconfig.default.esp32s2, targets/ESP32/defconfig/ESP32_S2_defconfig
Enables the UART console, selects USB CDC, and disables graphics and touch-controller options.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WP_Initialise
  participant TinyUSB
  participant UART
  WP_Initialise->>TinyUSB: Attempt TinyUSB initialization
  TinyUSB-->>WP_Initialise: Select TinyUSB or expose fallback path
  WP_Initialise->>UART: Initialize UART when configured
  WP_Initialise-->>WP_Initialise: Dispatch I/O using g_WP_Transport
Loading

Possibly related PRs

Suggested reviewers: adriansoundy

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely reflects the ESP32 CDC/UART detection and transport-selection changes.
Description check ✅ Passed The description matches the transport, config, and S2 build changes described in the diff.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@targets/ESP32/_common/WireProtocol_HAL_Interface.c`:
- Around line 411-413: Update the initialization failure path around
WP_Transport and WP_Port_Initialised so a failed transport setup leaves
WP_Port_Initialised false, allowing WP_ReceiveBytes and WP_TransmitMessage to
retry initialization; only set it true after a transport succeeds.

In `@targets/ESP32/_include/WireProtocol_Transport.h`:
- Line 22: Rename the shared transport global from WP_Transport to
g_WP_Transport throughout its declaration, definition, and all references.
Update the exported declaration near WireProtocol_Transport.h:22, the definition
near WireProtocol_HAL_Interface.c:47, and usages in
sys_io_ser_native_System_IO_Ports_SerialPort.cpp and targetHAL_Power.c; preserve
the existing type and behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 58043d62-cb80-44e8-9a5b-876b9e299ee7

📥 Commits

Reviewing files that changed from the base of the PR and between 7b827aa and 81d547b.

📒 Files selected for processing (6)
  • targets/ESP32/_IDF/sdkconfig.default.esp32s2
  • targets/ESP32/_common/WireProtocol_HAL_Interface.c
  • targets/ESP32/_include/WireProtocol_Transport.h
  • targets/ESP32/_nanoCLR/System.IO.Ports/sys_io_ser_native_System_IO_Ports_SerialPort.cpp
  • targets/ESP32/_nanoCLR/targetHAL_Power.c
  • targets/ESP32/defconfig/ESP32_S2_defconfig

Comment thread targets/ESP32/_common/WireProtocol_HAL_Interface.c Outdated
Comment thread targets/ESP32/_include/WireProtocol_Transport.h Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants