diff --git a/components/tinyusb/Kconfig b/components/tinyusb/Kconfig index 680edd39b8..21a2f9fbe0 100644 --- a/components/tinyusb/Kconfig +++ b/components/tinyusb/Kconfig @@ -125,6 +125,7 @@ menu "TinyUSB Stack" depends on TINYUSB_MSC_ENABLED int "MSC FIFO size" default 512 + range 64 10000 help MSC FIFO size, in bytes. endmenu # "Massive Storage Class" @@ -148,6 +149,7 @@ menu "TinyUSB Stack" depends on TINYUSB_CDC_ENABLED int "CDC FIFO size of RX channel" default 64 + range 64 10000 help CDC FIFO size of RX channel. diff --git a/components/tinyusb/additions/include/tinyusb.h b/components/tinyusb/additions/include/tinyusb.h index 8cf1608142..f0832c2996 100644 --- a/components/tinyusb/additions/include/tinyusb.h +++ b/components/tinyusb/additions/include/tinyusb.h @@ -18,48 +18,6 @@ extern "C" { #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 */ diff --git a/components/tinyusb/additions/src/tusb_cdc_acm.c b/components/tinyusb/additions/src/tusb_cdc_acm.c index db7159f70b..b046ce5050 100644 --- a/components/tinyusb/additions/src/tusb_cdc_acm.c +++ b/components/tinyusb/additions/src/tusb_cdc_acm.c @@ -17,6 +17,7 @@ #include "sdkconfig.h" #define RX_UNREADBUF_SZ_DEFAULT 64 // buffer storing all unread RX data +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) 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 */ 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, cdcacm_event_type_t event_type, 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, 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; } - size_t tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch) { 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); } - 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 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) diff --git a/components/tinyusb/additions/src/usb_descriptors.c b/components/tinyusb/additions/src/usb_descriptors.c index 283e9f5faa..f0c3228d15 100644 --- a/components/tinyusb/additions/src/usb_descriptors.c +++ b/components/tinyusb/additions/src/usb_descriptors.c @@ -179,12 +179,12 @@ uint8_t const descriptor_cfg_kconfig[] = { # if CFG_TUD_CDC // 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 # if CFG_TUD_CDC > 1 // 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 # if CFG_TUD_MSC diff --git a/examples/peripherals/usb/device/tusb_serial_device/main/tusb_serial_device_main.c b/examples/peripherals/usb/device/tusb_serial_device/main/tusb_serial_device_main.c index 5265f40575..3794713b3a 100644 --- a/examples/peripherals/usb/device/tusb_serial_device/main/tusb_serial_device_main.c +++ b/examples/peripherals/usb/device/tusb_serial_device/main/tusb_serial_device_main.c @@ -44,7 +44,7 @@ void tinyusb_cdc_line_state_changed_callback(int itf, cdcacm_event_t *event) void app_main(void) { 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)); tinyusb_config_cdcacm_t amc_cfg = {