Skip to content

Commit 97354e1

Browse files
committed
docs(esp_tinyusb): Updated CHANGELOG.md and README.md
1 parent 849e0ae commit 97354e1

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

device/esp_tinyusb/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## [Unreleased]
22

33
- Fixed forward compatibility with TinyUSB 0.19
4+
- Added VBUS monitoring feature for ESP32P4 USB OTG 2.0 (HS)
45

56
## 2.0.1
67

device/esp_tinyusb/README.md

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The default installation automatically configures the port (High-speed if suppor
8181

8282
Default descriptors are provided for the following USB classes: CDC, MSC, and NCM.
8383

84-
> **⚠️ Important:** For demonstration purposes, all error handling logic has been removed from the code examples. Do not ignore proper error handling in actual development.
84+
> ⚠️ For demonstration purposes, all error handling logic has been removed from the code examples. Do not ignore proper error handling in actual development.
8585
8686
```c
8787
#include "tinyusb_default_config.h"
@@ -208,10 +208,12 @@ Values of default descriptors could be configured via `menuconfig`.
208208

209209
### USB PHY configuration & Self-Powered Device
210210

211-
For self-powered devices, monitoring the VBUS voltage is required. To do this:
211+
For self-powered USB devices, the peripheral must be able to detect the VBUS voltage to know when it is connected to, or disconnected from, a USB host.
212212

213-
- Configure a GPIO pin as an input, using an external voltage divider or comparator to detect the VBUS state.
214-
- Set `self_powered = true` and assign the VBUS monitor GPIO in the `tinyusb_config_t` structure.
213+
To enable this:
214+
215+
- Connect VBUS to a GPIO input (typically through a voltage divider or external comparator).
216+
- Set `self_powered = true` and assign the VBUS monitor GPIO in `tinyusb_config_t`.
215217

216218
```c
217219
#include "tinyusb_default_config.h"
@@ -226,7 +228,79 @@ For self-powered devices, monitoring the VBUS voltage is required. To do this:
226228
tinyusb_driver_install(&tusb_cfg);
227229
}
228230
```
229-
If external PHY is used:
231+
232+
#### ESP32-P4 (USB OTG 2.0, High-Speed)
233+
234+
> **⚠️ Important:**
235+
>
236+
> On **USB OTG 1.1** (`TINYUSB_PORT_FULL_SPEED_0`), the VBUS **BVALID** signal is handled in hardware.
237+
>
238+
> On **USB OTG 2.0** (`TINYUSB_PORT_HIGH_SPEED_0`), there is no hardware **BVALID** detection – it is implemented in the driver.
239+
240+
For the high-speed port, the driver uses a combination of ISR-driven GPIO state detection plus a software debounce timer on the VBUS monitor GPIO. This filters glitches and cable plug/unplug noise.
241+
242+
- The debounce interval is controlled by `vbus_monitor_debounce_ms` in `tinyusb_config_t`.
243+
- If not set explicitly, the default debounce time is 250 ms.
244+
245+
> **Note:**
246+
>
247+
> The `vbus_monitor_debounce_ms` member also exists in `tinyusb_config_t` when using `TINYUSB_PORT_FULL_SPEED_0`, but it is not used by the driver in that mode because VBUS is already handled in hardware.
248+
249+
You can override the debounce interval in the driver configuration:
250+
251+
```c
252+
#include "tinyusb_default_config.h"
253+
254+
void app_main(void)
255+
{
256+
tinyusb_config_t tusb_cfg = TINYUSB_DEFAULT_CONFIG();
257+
258+
tusb_cfg.phy.self_powered = true;
259+
tusb_cfg.phy.vbus_monitor_io = GPIO_NUM_0;
260+
tusb_cfg.phy.vbus_monitor_debounce_ms = 350; // new debounce value
261+
262+
tinyusb_driver_install(&tusb_cfg);
263+
}
264+
```
265+
266+
> **🔧 GPIO ISR requirement**:
267+
>
268+
> When VBUS monitoring is enabled with `TINYUSB_PORT_HIGH_SPEED_0` (ESP32-P4 USB OTG 2.0), the GPIO driver ISR service **must be installed before** calling `tinyusb_driver_install()`.
269+
270+
To install GPIO's drvier's ISR service:
271+
272+
```c
273+
#include "tinyusb_default_config.h"
274+
#include "driver/gpio.h"
275+
#include "sdkconfig.h"
276+
277+
void app_main(void)
278+
{
279+
tinyusb_config_t tusb_cfg = TINYUSB_DEFAULT_CONFIG();
280+
281+
tusb_cfg.phy.self_powered = true;
282+
tusb_cfg.phy.vbus_monitor_io = GPIO_NUM_0;
283+
284+
#if (CONFIG_IDF_TARGET_ESP32P4)
285+
// TINYUSB_PORT_HIGH_SPEED_0 is used by default
286+
gpio_install_isr_service(ESP_INTR_FLAG_LOWMED);
287+
#endif // CONFIG_IDF_TARGET_ESP32P4
288+
289+
tinyusb_driver_install(&tusb_cfg);
290+
291+
// application code
292+
293+
tinyusb_driver_uninstall();
294+
295+
#if (CONFIG_IDF_TARGET_ESP32P4)
296+
gpio_uninstall_isr_service();
297+
#endif // CONFIG_IDF_TARGET_ESP32P4
298+
}
299+
```
300+
301+
The driver can also **skip PHY configuration** if you need to initialize and manage the USB PHY externally (for example, when using a custom or external PHY).
302+
303+
To do this, set `skip_setup = true`:
230304
231305
```c
232306
#include "tinyusb_default_config.h"

0 commit comments

Comments
 (0)