Skip to content

Commit e561485

Browse files
Merge pull request #432 from espressif/feat/esp_tinyusb_vendor_sizes
feat(esp_tinyusb): Add Kconfig option for Vendor specific buffers
2 parents 555cf21 + 45b7947 commit e561485

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
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
- esp_tinyusb: Fixed VBUS monitoring feature on ESP32-P4 USB OTG 2.0 (HS)
4+
- Vendor class: Add configuration options for TX/RX buffers
45

56
## 2.1.0
67

device/esp_tinyusb/Kconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,41 @@ menu "TinyUSB Stack"
318318
range 0 2
319319
help
320320
Setting value greater than 0 will enable TinyUSB Vendor specific feature.
321+
322+
config TINYUSB_VENDOR_RX_BUFSIZE
323+
depends on (TINYUSB_VENDOR_COUNT > 0)
324+
int "Vendor specific FIFO size of RX channel"
325+
default 512 if IDF_TARGET_ESP32P4
326+
default 64
327+
range 0 32768
328+
help
329+
This buffer size defines maximum data length in bytes that you can receive at once.
330+
331+
Note: Unlike other USB classes, the vendor class supports setting buffer sizes to 0
332+
to disable internal buffering. When disabled, RX data goes directly to tud_vendor_rx_cb(),
333+
the tud_vendor_read() function is not available and application must handle data in the callback.
334+
335+
config TINYUSB_VENDOR_TX_BUFSIZE
336+
depends on (TINYUSB_VENDOR_COUNT > 0)
337+
int "Vendor specific FIFO size of TX channel"
338+
default 512 if IDF_TARGET_ESP32P4
339+
default 64
340+
range 0 32768
341+
help
342+
This buffer size defines maximum data length in bytes that you can transmit at once.
343+
344+
Note: Unlike other USB classes, the vendor class supports setting buffer sizes to 0
345+
to disable internal buffering. When disabled, tud_vendor_write() bypasses internal software FIFO.
346+
347+
config TINYUSB_VENDOR_EPSIZE
348+
depends on (TINYUSB_VENDOR_COUNT > 0)
349+
int "Vendor specific Endpoint buffer size"
350+
default 512 if IDF_TARGET_ESP32P4
351+
default 64
352+
range 64 32768
353+
help
354+
This low layer buffer has the most significant impact on performance. Set to 8192 for best performance.
355+
Sizes above 8192 bytes bring only little performance improvement.
356+
321357
endmenu # "Vendor Specific Interface"
322358
endmenu # "TinyUSB Stack"

device/esp_tinyusb/include/tusb_config.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* SPDX-FileCopyrightText: 2019 Ha Thach (tinyusb.org),
3-
* SPDX-FileContributor: 2020-2025 Espressif Systems (Shanghai) CO LTD
3+
* SPDX-FileContributor: 2020-2026 Espressif Systems (Shanghai) CO LTD
44
* SPDX-License-Identifier: MIT
55
*
66
* Copyright (c) 2019 Ha Thach (tinyusb.org),
@@ -30,6 +30,7 @@
3030

3131
#include "tusb_option.h"
3232
#include "sdkconfig.h"
33+
#include "esp_assert.h"
3334

3435
#ifdef __cplusplus
3536
extern "C" {
@@ -156,8 +157,24 @@ extern "C" {
156157
#define CFG_TUD_MIDI_TX_BUFSIZE 64
157158

158159
// Vendor FIFO size of TX and RX
159-
#define CFG_TUD_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
160-
#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
160+
#define CFG_TUD_VENDOR_RX_BUFSIZE CONFIG_TINYUSB_VENDOR_RX_BUFSIZE
161+
#define CFG_TUD_VENDOR_TX_BUFSIZE CONFIG_TINYUSB_VENDOR_TX_BUFSIZE
162+
#define CFG_TUD_VENDOR_EPSIZE CONFIG_TINYUSB_VENDOR_EPSIZE
163+
164+
#if (CFG_TUD_VENDOR > 0)
165+
#if (CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED)
166+
#define EP_SIZE_VENDOR 512
167+
#else
168+
#define EP_SIZE_VENDOR 64
169+
#endif
170+
ESP_STATIC_ASSERT(CFG_TUD_VENDOR_EPSIZE >= EP_SIZE_VENDOR, "Vendor EP size must be at least 64 for FS and 512 for HS");
171+
#if (CFG_TUD_VENDOR_RX_BUFSIZE > 0)
172+
ESP_STATIC_ASSERT(CFG_TUD_VENDOR_RX_BUFSIZE >= EP_SIZE_VENDOR, "Vendor RX buffer size must be at least equal to EP size");
173+
#endif
174+
#if (CFG_TUD_VENDOR_TX_BUFSIZE > 0)
175+
ESP_STATIC_ASSERT(CFG_TUD_VENDOR_TX_BUFSIZE >= EP_SIZE_VENDOR, "Vendor TX buffer size must be at least equal to EP size");
176+
#endif
177+
#endif
161178

162179
// DFU macros
163180
#define CFG_TUD_DFU_XFER_BUFSIZE CONFIG_TINYUSB_DFU_BUFSIZE

0 commit comments

Comments
 (0)