Merge branch 'fix/usb/buffer_sizes' into 'master'

usb: TinyUSB buffer sizes

Closes IDFGH-7469

See merge request espressif/esp-idf!18359
This commit is contained in:
Tomas Rezucha
2022-06-14 17:23:52 +08:00
5 changed files with 8 additions and 52 deletions

View File

@@ -125,6 +125,7 @@ menu "TinyUSB Stack"
depends on TINYUSB_MSC_ENABLED depends on TINYUSB_MSC_ENABLED
int "MSC FIFO size" int "MSC FIFO size"
default 512 default 512
range 64 10000
help help
MSC FIFO size, in bytes. MSC FIFO size, in bytes.
endmenu # "Massive Storage Class" endmenu # "Massive Storage Class"
@@ -148,6 +149,7 @@ menu "TinyUSB Stack"
depends on TINYUSB_CDC_ENABLED depends on TINYUSB_CDC_ENABLED
int "CDC FIFO size of RX channel" int "CDC FIFO size of RX channel"
default 64 default 64
range 64 10000
help help
CDC FIFO size of RX channel. CDC FIFO size of RX channel.

View File

@@ -18,48 +18,6 @@
extern "C" { extern "C" {
#endif #endif
/* tinyusb uses buffers with type of uint8_t[] but in our driver we are reading them as a 32-bit word */
#if (CFG_TUD_ENDPOINT0_SIZE < 4)
# define CFG_TUD_ENDPOINT0_SIZE 4
# warning "CFG_TUD_ENDPOINT0_SIZE was too low and was set to 4"
#endif
#if TUSB_OPT_DEVICE_ENABLED
# if CFG_TUD_HID
# if (CFG_TUD_HID_BUFSIZE < 4)
# define CFG_TUD_HID_BUFSIZE 4
# warning "CFG_TUD_HID_BUFSIZE was too low and was set to 4"
# endif
# endif
# if CFG_TUD_CDC
# if (CFG_TUD_CDC_EP_BUFSIZE < 4)
# define CFG_TUD_CDC_EP_BUFSIZE 4
# warning "CFG_TUD_CDC_EP_BUFSIZE was too low and was set to 4"
# endif
# endif
# if CFG_TUD_MSC
# if (CFG_TUD_MSC_BUFSIZE < 4)
# define CFG_TUD_MSC_BUFSIZE 4
# warning "CFG_TUD_MSC_BUFSIZE was too low and was set to 4"
# endif
# endif
# if CFG_TUD_MIDI
# if (CFG_TUD_MIDI_EPSIZE < 4)
# define CFG_TUD_MIDI_EPSIZE 4
# warning "CFG_TUD_MIDI_EPSIZE was too low and was set to 4"
# endif
# endif
# if CFG_TUD_CUSTOM_CLASS
# warning "Please check that the buffer is more then 4 bytes"
# endif
#endif
/** /**
* @brief Configuration structure of the tinyUSB core * @brief Configuration structure of the tinyUSB core
*/ */

View File

@@ -17,6 +17,7 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#define RX_UNREADBUF_SZ_DEFAULT 64 // buffer storing all unread RX data #define RX_UNREADBUF_SZ_DEFAULT 64 // buffer storing all unread RX data
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
typedef struct { typedef struct {
@@ -79,7 +80,6 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
} }
} }
/* Invoked when CDC interface received data from host */ /* Invoked when CDC interface received data from host */
void tud_cdc_rx_cb(uint8_t itf) void tud_cdc_rx_cb(uint8_t itf)
{ {
@@ -157,8 +157,6 @@ void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
} }
} }
esp_err_t tinyusb_cdcacm_register_callback(tinyusb_cdcacm_itf_t itf, esp_err_t tinyusb_cdcacm_register_callback(tinyusb_cdcacm_itf_t itf,
cdcacm_event_type_t event_type, cdcacm_event_type_t event_type,
tusb_cdcacm_callback_t callback) tusb_cdcacm_callback_t callback)
@@ -188,7 +186,6 @@ esp_err_t tinyusb_cdcacm_register_callback(tinyusb_cdcacm_itf_t itf,
} }
} }
esp_err_t tinyusb_cdcacm_unregister_callback(tinyusb_cdcacm_itf_t itf, esp_err_t tinyusb_cdcacm_unregister_callback(tinyusb_cdcacm_itf_t itf,
cdcacm_event_type_t event_type) cdcacm_event_type_t event_type)
{ {
@@ -273,7 +270,6 @@ esp_err_t tinyusb_cdcacm_read(tinyusb_cdcacm_itf_t itf, uint8_t *out_buf, size_t
return ESP_OK; return ESP_OK;
} }
size_t tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch) size_t tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch)
{ {
if (!get_acm(itf)) { // non-initialized if (!get_acm(itf)) { // non-initialized
@@ -282,13 +278,13 @@ size_t tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch)
return tud_cdc_n_write_char(itf, ch); return tud_cdc_n_write_char(itf, ch);
} }
size_t tinyusb_cdcacm_write_queue(tinyusb_cdcacm_itf_t itf, const uint8_t *in_buf, size_t in_size) size_t tinyusb_cdcacm_write_queue(tinyusb_cdcacm_itf_t itf, const uint8_t *in_buf, size_t in_size)
{ {
if (!get_acm(itf)) { // non-initialized if (!get_acm(itf)) { // non-initialized
return 0; return 0;
} }
return tud_cdc_n_write(itf, in_buf, in_size); const uint32_t size_available = tud_cdc_n_write_available(itf);
return tud_cdc_n_write(itf, in_buf, MIN(in_size, size_available));
} }
static uint32_t tud_cdc_n_write_occupied(tinyusb_cdcacm_itf_t itf) static uint32_t tud_cdc_n_write_occupied(tinyusb_cdcacm_itf_t itf)

View File

@@ -179,12 +179,12 @@ uint8_t const descriptor_cfg_kconfig[] = {
# if CFG_TUD_CDC # if CFG_TUD_CDC
// Interface number, string index, EP notification address and size, EP data address (out, in) and size. // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, 64), TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, CFG_TUD_CDC_EP_BUFSIZE),
# endif # endif
# if CFG_TUD_CDC > 1 # if CFG_TUD_CDC > 1
// Interface number, string index, EP notification address and size, EP data address (out, in) and size. // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC1, 4, 0x83, 8, 0x04, 0x84, 64), TUD_CDC_DESCRIPTOR(ITF_NUM_CDC1, 4, 0x83, 8, 0x04, 0x84, CFG_TUD_CDC_EP_BUFSIZE),
# endif # endif
# if CFG_TUD_MSC # if CFG_TUD_MSC

View File

@@ -44,7 +44,7 @@ void tinyusb_cdc_line_state_changed_callback(int itf, cdcacm_event_t *event)
void app_main(void) void app_main(void)
{ {
ESP_LOGI(TAG, "USB initialization"); ESP_LOGI(TAG, "USB initialization");
tinyusb_config_t tusb_cfg = {}; // the configuration using default values const tinyusb_config_t tusb_cfg = {}; // the configuration using default values
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg)); ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
tinyusb_config_cdcacm_t amc_cfg = { tinyusb_config_cdcacm_t amc_cfg = {