-
Notifications
You must be signed in to change notification settings - Fork 34
feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part1/2) #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c8dac7f to
ed53b4e
Compare
a2cf813 to
649edbe
Compare
ed53b4e to
888ae35
Compare
888ae35 to
03caa71
Compare
03caa71 to
f439723
Compare
There was a problem hiding this 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 introduces the first part of a software VBUS monitoring feature for ESP32P4, specifically targeting USB OTG 2.0 high-speed functionality. It addresses the limitation where ESP32P4's USB OTG 2.0 doesn't have hardware detection of VBUS BVALID signal by implementing a software-based solution with configurable debouncing.
- Added VBUS monitor API infrastructure with debounce configuration
- Refactored test application from
dconn_detectiontovbus_monitorwith comprehensive test coverage - Updated documentation and configuration to support the new VBUS monitoring feature
Reviewed Changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tinyusb_vbus_monitor.c | New VBUS monitoring implementation (currently stub returning ESP_ERR_NOT_SUPPORTED) |
| tinyusb_task.c | Integration of VBUS monitor initialization and cleanup into TinyUSB task lifecycle |
| tinyusb.c | Added VBUS monitor configuration validation and setup for different USB OTG versions |
| test_apps/vbus_monitor/* | Comprehensive test suite replacing dconn_detection with extensive VBUS monitoring tests |
| include files | Added VBUS monitor configuration structures and API declarations |
| README.md | Documentation updates explaining VBUS monitoring setup and ESP32P4 limitations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
device/esp_tinyusb/test_apps/vbus_monitor/main/test_vbus_monitor.c
Outdated
Show resolved
Hide resolved
device/esp_tinyusb/test_apps/vbus_monitor/main/test_vbus_monitor.c
Outdated
Show resolved
Hide resolved
f439723 to
fee7783
Compare
There was a problem hiding this 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 19 out of 21 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
device/esp_tinyusb/test_apps/vbus_monitor/main/test_vbus_monitor.c
Outdated
Show resolved
Hide resolved
device/esp_tinyusb/test_apps/vbus_monitor/main/test_vbus_monitor.c
Outdated
Show resolved
Hide resolved
fee7783 to
33acda8
Compare
There was a problem hiding this 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 19 out of 21 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
device/esp_tinyusb/tinyusb.c:1
- Line 106 has incorrect condition. It should check
config->phy.vbus_monitor_io >= GPIO_NUM_0 && config->phy.vbus_monitor_io < GPIO_NUM_MAXinstead of justconfig->phy.self_powered.
/*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f573418 to
a8fbded
Compare
There was a problem hiding this 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 19 out of 21 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
device/esp_tinyusb/tinyusb.c:1
- The condition logic is incorrect. It should check
config->phy.vbus_monitor_io >= GPIO_NUM_0 && config->phy.vbus_monitor_io < GPIO_NUM_MAXinstead ofconfig->phy.self_powered.
/*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
device/esp_tinyusb/test_apps/vbus_monitor/main/test_vbus_monitor.c
Outdated
Show resolved
Hide resolved
…L override driving for VBUS monitoring - Added test cases for USB OTG 1.1 (esp32s2, esp32s3, esp32p4) - Added test cases for USB OTG 2.0 (esp32p4) - Enabled CI tests for esp32s2
a8fbded to
652c0fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
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.
652c0fb to
057986d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Memory leak and state corruption in task start error path
Memory leak and state corruption in error handling path of tinyusb_task_start(). If task creation succeeds but the task fails to notify within the timeout (line 177-180), the error path at line 180-182 frees task_ctx but does not reset the _task_is_running flag. This has two problems:
-
The _task_is_running flag remains true, preventing any future calls to tinyusb_task_start() from succeeding (they will fail with ESP_ERR_INVALID_STATE at line 138).
-
If the task eventually starts and successfully calls xTaskNotifyGive() after the timeout, it will continue running with a freed task_ctx pointer that was already freed at line 181. While the current implementation doesn't access task_ctx after notification, this creates a dangerous dangling pointer situation.
The error path should reset _task_is_running to false within a critical section before freeing task_ctx.
device/esp_tinyusb/tinyusb_task.c#L179-L182
esp-usb/device/esp_tinyusb/tinyusb_task.c
Lines 179 to 182 in 057986d
| ESP_LOGE(TAG, "Task wasn't able to start TinyUSB stack"); | |
| ret = ESP_ERR_TIMEOUT; | |
| goto err; | |
| } |
057986d to
d311914
Compare
d311914 to
623809e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Dangling _task_is_running Flag on Error Path
Inconsistent state on error: When the error path at label err: is reached (either from task creation failure at line 169 or timeout at line 180), the function frees task_ctx and returns, but does not reset the _task_is_running flag to false. This flag was set to true at line 140, but will remain set even though the task was never successfully started. This prevents subsequent calls to tinyusb_task_start from succeeding. The fix should reset _task_is_running to false within a critical section before freeing memory and returning.
device/esp_tinyusb/tinyusb_task.c#L185-L188
esp-usb/device/esp_tinyusb/tinyusb_task.c
Lines 185 to 188 in 623809e
| err: | |
| heap_caps_free(task_ctx); | |
| return ret; |
623809e to
d298a66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Task Running Flag Not Reset on Error Path
The error path at label err: does not reset _task_is_running flag before returning. This error path is reached when task creation fails (line 176) or when the notification times out (line 183). Since _task_is_running was set to true at line 140, it must be cleared in the error path to prevent the system from being left in an inconsistent state where subsequent calls to tinyusb_task_start() will fail at the check on line 139.
device/esp_tinyusb/tinyusb_task.c#L185-L188
esp-usb/device/esp_tinyusb/tinyusb_task.c
Lines 185 to 188 in d298a66
| err: | |
| heap_caps_free(task_ctx); | |
| return ret; |
Description
VBUS monitoring on ESP32-P4 - Part 1/2
dconn_detection->vbus_monitor, enabled for esp32s2version: '^0.18.0')Related
Testing
ESP32S2/S3
ESP32P4
Checklist
Before submitting a Pull Request, please ensure the following:
Note
Introduces software VBUS monitoring for ESP32P4 USB OTG 2.0 (HS) with debounce config, integrates it into the driver/task, updates docs, pins TinyUSB to 0.18, and replaces dconn tests with a new vbus monitor test app.
tinyusb_vbus_monitor.c/.hand integrate init/deinit intinyusb_task.candtinyusb.c(passtinyusb_vbus_monitor_config_t).tinyusb_phy_config_twithvbus_monitor_debounce_ms; set defaults intinyusb_default_config.h.tinyusb_task_startsignature to accept VBUS monitor cfg.tinyusb_vbus_monitor.conly foresp32p4.tinyusbto^0.18.0inidf_component.yml.dconn_detectionwithvbus_monitortest app: new cases for emulated/controlled/real VBUS across ports/targets, helper setup/teardown, pytest runner, and config (enable CDC).Written by Cursor Bugbot for commit d298a66. This will update automatically on new commits. Configure here.