Skip to content

Conversation

@roma-jam
Copy link
Collaborator

@roma-jam roma-jam commented Oct 30, 2025

Description

VBUS monitoring on ESP32-P4 - Part 2/2

  • added GPIO ISR + debounce timer + debounce logic; drive GOTGCTL.BVALID on VBUS appear/disappear.

Related

Testing

  • Enabling CI test for vbus_monitor on esp32p4

Verification

Verification is made by launching the vbus_monitor test application test cases.
To verify all scenarios, additional hardware features should be done with a dev board:

  1. Connect GPIO4 and GPIO5 together (for controlled vbus test)
  2. Add the resistor divider, connected to the +5V of the usb port (the +5V point was taken from the drain of Q3 and Q4)

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Note

Implements GPIO ISR + debounce-driven VBUS monitoring (with DWC BVALID override/soft-disconnect) on ESP32-P4, updates API to return esp_err, and enables corresponding tests and example setup.

  • Device (VBUS monitor):
    • Implement ISR-based GPIO VBUS monitoring with FreeRTOS debounce timer in device/esp_tinyusb/tinyusb_vbus_monitor.c.
    • Add low-level DWC helpers and drive GOTGCTL.BVALID and DCTL.SFTDISCON on VBUS appear/disappear (ESP32-P4).
    • Robust init: single-instance guard, GPIO config/ISR hookup, debounce timer creation, BVALID override enable; start timer if VBUS already high.
    • Deinit now returns esp_err_t; cleans up ISR, GPIO, timer, and disables BVALID override.
    • Header tinyusb_vbus_monitor.h: document new error returns; change tinyusb_vbus_monitor_deinit signature to return esp_err_t.
  • Tests (test_vbus_monitor.c):
    • Enable GOTGCTL-based attach/detach test and replace placeholders with real routines.
    • For controlled/real VBUS tests on OTG 2.0, install/uninstall GPIO ISR service.
  • Example (MSC test app):
    • On ESP32-P4, install GPIO ISR service before tinyusb_driver_install in msc_device.c.

Written by Cursor Bugbot for commit 6b9d6ea. This will update automatically on new commits. Configure here.

@roma-jam roma-jam added this to the esp_tinyusb v2.0.2 milestone Oct 30, 2025
@roma-jam roma-jam self-assigned this Oct 30, 2025
@roma-jam roma-jam added the Component: usb_device Issue affects usb_device component label Oct 30, 2025
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch from 03caa71 to f439723 Compare October 31, 2025 01:14
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 57de566 to 85e04ef Compare October 31, 2025 01:15
@roma-jam roma-jam requested a review from Copilot October 31, 2025 13:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements software VBUS monitoring functionality for ESP32P4, the second part of a two-part implementation. It adds GPIO-based interrupt handling with debounce logic to detect VBUS presence and automatically control USB device connection/disconnection by overriding the GOTGCTL.BVALID signal.

  • Implements GPIO ISR with debounce timer for VBUS state detection
  • Adds low-level USB DWC register manipulation functions for BVALID override control
  • Enables previously disabled test cases for VBUS monitoring functionality

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tinyusb_vbus_monitor.c Core implementation of VBUS monitoring with GPIO ISR, debounce logic, and USB register control
test_vbus_monitor.c Enables test cases by replacing placeholder return values with actual test function calls
tinyusb_vbus_monitor.h Updates function signatures and documentation for new return types and error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch from f439723 to fee7783 Compare November 2, 2025 14:50
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 85e04ef to f388b64 Compare November 2, 2025 14:58
@roma-jam roma-jam requested a review from Copilot November 2, 2025 14:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch 4 times, most recently from a744c34 to 3a4f14a Compare November 2, 2025 21:28
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from f388b64 to 3325a80 Compare November 2, 2025 21:34
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch from f573418 to a8fbded Compare November 4, 2025 12:08
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 3325a80 to 3181ea4 Compare November 4, 2025 14:57
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch from a8fbded to 652c0fb Compare November 4, 2025 15:09
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 3181ea4 to b7434a9 Compare November 4, 2025 15:09
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch from 652c0fb to 057986d Compare November 5, 2025 10:30
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from b7434a9 to 038ddc8 Compare November 5, 2025 10:32
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch 2 times, most recently from d311914 to 623809e Compare November 5, 2025 12:31
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 038ddc8 to 94ebda9 Compare November 5, 2025 12:32
@roma-jam roma-jam marked this pull request as ready for review November 5, 2025 12:44
@roma-jam roma-jam changed the title feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part2/2) [WIP] feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part2/2) Nov 5, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on November 20

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@roma-jam roma-jam changed the title feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part2/2) feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part2/2) [WIP] Nov 5, 2025
@roma-jam roma-jam marked this pull request as draft November 5, 2025 12:54
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch from 623809e to d298a66 Compare November 6, 2025 12:44
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 94ebda9 to 137ba53 Compare November 6, 2025 13:05
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part1 branch 4 times, most recently from 97354e1 to 15fb575 Compare November 7, 2025 11:28
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch 2 times, most recently from 0379ebd to 4953363 Compare November 8, 2025 21:12
@roma-jam roma-jam requested a review from Copilot November 10, 2025 06:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 4953363 to c2dbd6f Compare November 10, 2025 09:24
@roma-jam roma-jam requested a review from Copilot November 10, 2025 09:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from cf4fd4a to 6e1c6a8 Compare November 10, 2025 09:30
@roma-jam roma-jam changed the title feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part2/2) [WIP] feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part2/2) Nov 10, 2025
@roma-jam roma-jam marked this pull request as ready for review November 10, 2025 09:30
- added GPIO ISR, debounce timer, debounce logic
- added GOTGCTL.BVALID driving on VBUS appear/disappear
- added DCTL.SFTDISCON driving on VBUS appear/dissapear
@roma-jam roma-jam force-pushed the feature/vbus_monitor_esp32p4_part2 branch from 6e1c6a8 to 6b9d6ea Compare November 10, 2025 11:38
@roma-jam
Copy link
Collaborator Author

Hi
@tore-espressif
@peter-marcisovsky
@igi540

This PR is ready. PTAL!

}

/**
* @brief TinyUSB Attach/Detach events test, when VBUS monitoring is enabled and connected to GPIO
Copy link
Collaborator

@tore-espressif tore-espressif Nov 10, 2025

Choose a reason for hiding this comment

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

Did you get expected results in this testcase?

IIRC, the USB-DWC does not only check state of BVALID signal but also state of D+ and D-. Eg. if you deassert bValid, but D+ and D- stay connected, the detachment might not be detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: usb_device Issue affects usb_device component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants