[SOLVED] ESP32-S2 USB CDC-ACM problem in recognition

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

[SOLVED] ESP32-S2 USB CDC-ACM problem in recognition

Postby filo_gr » Fri Oct 15, 2021 9:35 am

Hello community!

My ESP32-S2 has an USB connector connected to pin 19 (D-), pin 20 (D+) and to the power supply. I use the TinyUSB drivers. I tested the USB connection through a terminal with the examples tusb_console, tusb_sample_descriptor, tusb_serial_device and they work.

I'm encountering some problems due to the recognition of my ESP32-S2 as CDC device when I plug it into a USB port of another microcontroller.
This device, which has the task of recognize the ESP32-S2, is a Microchip PIC32MX250F256H.
I think that the problem is due to the Class, Subclass and Protocol settings.
In fact I noticed when I plug the ESP's USB into my PC it's recognized as USB Serial Port with the values:
  • Class = 0x02
  • Subclass = 0x02
  • Protocol= 0x00
When connect the ESP to the Microchip microcontroller, it detects the ESP with the following values:
  • Class = 0x0A
  • Subclass = 0x00
  • Protocol= 0x00
After that the PIC32MX quit the communication because it doesn't recognize it in the right way (I have another CDC device that works perfectly with this MCU, it has Class = 0x02, Subclass = 0x02, Protocol= 0x01).

Is this the problem?
Is there a way to change the CDC parameters (class, etc...) of my ESP32-S2?

Thanks in advance
Last edited by filo_gr on Thu Oct 21, 2021 8:38 am, edited 1 time in total.
Filippo

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S2 USB CDC problem in recognition

Postby ESP_Sprite » Sat Oct 16, 2021 3:37 am

My guess is that TinyUSB is presenting itself as a composite device, with a CDC-ACM device in it. That allows TinyUSB to also present itself as other classes at the same time. I think you can specify TinyUSB to use a custom descriptor, but you'd have to provide that yourself.

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S2 USB CDC problem in recognition

Postby chegewara » Sat Oct 16, 2021 4:02 am

Hi @filo_gr,
you are pretty close in discovering whats wrong or how to fix it.

Here is base CDC descriptor which is used in tinyusb examples:
https://github.com/hathach/tinyusb/blob ... #L199-L219

and here for example is descriptor from esp32 S2 in bootload mode:

Code: Select all

Config Number: 1
	Number of Interfaces: 3
	Attributes: c0
	MaxPower Needed: 500mA

	Interface Number: 0
		Name: cdc_acm
		Alternate Number: 0
		Class: 02(comm.) 
		Sub Class: 02
		Protocol: 00
		Number of Endpoints: 1

			Endpoint Address: 85
			Direction: in
			Attribute: 3
			Type: Int.
			Max Packet Size: 64
			Interval: 1ms

	Interface Number: 1
		Name: cdc_acm
		Alternate Number: 0
		Class: 0a(data ) 
		Sub Class: 02
		Protocol: 00
		Number of Endpoints: 2

			Endpoint Address: 03
			Direction: out
			Attribute: 2
			Type: Bulk
			Max Packet Size: 64
			Interval: 0ms

			Endpoint Address: 84
			Direction: in
			Attribute: 2
			Type: Bulk
			Max Packet Size: 64
			Interval: 0ms
Both are using the same "protocol" value 0. Protocol 1 is for AT V.250 and you can edit descriptor from previous link and use this value and then pass your custom descriptor to build CDC device:
https://github.com/hathach/tinyusb/blob ... /cdc.h#L80

If you still need some help how to do it then you have to show some code you are using to create CDC device.

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

Re: ESP32-S2 USB CDC problem in recognition

Postby filo_gr » Mon Oct 18, 2021 7:10 am

chegewara wrote:
Sat Oct 16, 2021 4:02 am
Here is base CDC descriptor which is used in tinyusb examples:
https://github.com/hathach/tinyusb/blob ... #L199-L219

Both are using the same "protocol" value 0. Protocol 1 is for AT V.250 and you can edit descriptor from previous link and use this value and then pass your custom descriptor to build CDC device:
https://github.com/hathach/tinyusb/blob ... /cdc.h#L80
Thank you for your help!
Unfortunately I still need other informations, because I'm not able to put all together in order to make the system working well.
To make these tests, I used the ESP-IDF example tusb_serial_device_main.
At the moment, the only thing that I need is to ensure the PIC32 will be able to correctly detect the ESP32 device. It's not very important what the script will do (I mean, I don't think the part after the initialization will affect the correct descriptor).
In particular, I can't understand how I can configure the USB and CDC with tinyusb_driver_install and tusb_cdc_acm_init, starting from the TUD_CDC_DESCRIPTOR definition in your link.
Filippo

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S2 USB CDC problem in recognition

Postby chegewara » Mon Oct 18, 2021 8:06 am

This example will be very problematic to use for you. It is using espressif wrapper around tinyusb with predefined USB descriptors, which you cant change unless you change esp-idf component:
https://github.com/espressif/esp-idf/bl ... trol.c#L36

I see 3 ways to do what you want:
1) mentioned change in esp-idf component; probably it will work with overriding component like with any other esp-idf components, so not that bad option,
2) try to use tinyusb cdc example (just remove msc part, and apply changes i mentioned in previous post)
https://github.com/hathach/tinyusb/blob ... src/main.c
3) start with this example, but this is most complex work to do i think:
https://github.com/espressif/esp-idf/bl ... tor_main.c

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

Re: ESP32-S2 USB CDC problem in recognition

Postby filo_gr » Mon Oct 18, 2021 10:08 am

chegewara wrote:
Mon Oct 18, 2021 8:06 am
2) try to use tinyusb cdc example (just remove msc part, and apply changes i mentioned in previous post)
https://github.com/hathach/tinyusb/blob ... src/main.c
Looking at this link, I noticed it creates a custom descriptor's structure like that:

Code: Select all

tusb_desc_device_t const desc_device =
{
    .bLength            = sizeof(tusb_desc_device_t),
    .bDescriptorType    = TUSB_DESC_DEVICE,
    .bcdUSB             = USB_BCD,

    // Use Interface Association Descriptor (IAD) for CDC
    // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
    .bDeviceClass       = TUSB_CLASS_MISC,
    .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
    .bDeviceProtocol    = MISC_PROTOCOL_IAD,

    .bMaxPacketSize0    = CFG_TUD_ENDPOINT0_SIZE,

    .idVendor           = USB_VID,
    .idProduct          = USB_PID,
    .bcdDevice          = 0x0100,

    .iManufacturer      = 0x01,
    .iProduct           = 0x02,
    .iSerialNumber      = 0x03,

    .bNumConfigurations = 0x01
};
I only need to change the class, subclass and protocol, so I made the following code:

Code: Select all

void
usb_init (void)
{
    // Setting of descriptor. You can use descriptor_tinyusb and
    // descriptor_str_tinyusb as a reference
    tinyusb_config_t tusb_cfg = { 0 }; // the configuration uses default values
    tusb_cfg.descriptor->bDescriptorType = g_desc_device.bDescriptorType;
    tusb_cfg.descriptor->bDeviceClass = g_desc_device.bDeviceClass;
    tusb_cfg.descriptor->bDeviceProtocol = g_desc_device.bDeviceProtocol;
    tusb_cfg.descriptor->bDeviceSubClass = g_desc_device.bDeviceSubClass;
    // Inizializzazione del driver.
    ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
    ESP_LOGI(g_p_tag, "USB initialization DONE");
    ESP_LOGI(g_p_tag, "Connect the USB connector!");
    // L'opzione CDC deve essere attiva in Menuconfig, in tal caso l'USB serial
    // device può essere inizializzato in base ai settaggi della struttura.
    ESP_ERROR_CHECK(tusb_cdc_acm_init(&g_amc_cfg));
}   /* usb_init() */
where:

Code: Select all

tusb_desc_device_t const g_desc_device =
{
    .bDescriptorType    = TUSB_DESC_DEVICE,
    // Use Interface Association Descriptor (IAD) for CDC
    // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
    .bDeviceClass       = TUSB_CLASS_CDC,
    .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
    .bDeviceProtocol    = MISC_PROTOCOL_IAD,
};
I'm completely sure there's something wrong, in fact after programming I see the ESP in a loop of panic errors.
Is that the right way? What are the troubles?
Filippo

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S2 USB CDC problem in recognition

Postby chegewara » Mon Oct 18, 2021 12:33 pm

Yes, you have to change protocol, but not in this descriptor. This descriptor is ok.
You cave to change code like this (CDC part):
https://github.com/hathach/tinyusb/blob ... ors.c#L126

Code: Select all

TUD_CDC_DESCRIPTOR_AT(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),

Code: Select all

#define TUD_CDC_DESCRIPTOR_AT(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
  /* Interface Associate */\
  8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
  /* CDC Control Interface */\
  9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, _stridx,\
  /* CDC Header */\
  5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
  /* CDC Call */\
  5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\
  /* CDC ACM: support line request */\
  4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
  /* CDC Union */\
  5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
  /* Endpoint Notification */\
  7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
  /* CDC Data Interface */\
  9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
  /* Endpoint Out */\
  7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
  /* Endpoint In */\
  7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
That should be enough.

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

Re: ESP32-S2 USB CDC problem in recognition

Postby filo_gr » Mon Oct 18, 2021 2:43 pm

I'm sorry if I'm persistent, I know the solution is here, but I still need help.
I created the following code, more or less the same of the example you linked:

Code: Select all

/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
 * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
 *
 * Auto ProductID layout's Bitmap:
 *   [MSB]         HID | MSC | CDC          [LSB]
 */
#define _PID_MAP(itf, n)  ( (CFG_TUD_##itf) << (n) )
#define USB_PID           (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
                           _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )

#define USB_VID   0xCafe
#define USB_BCD   0x0200

enum
{
  ITF_NUM_CDC = 0,
  ITF_NUM_CDC_DATA,
  ITF_NUM_MSC,
  ITF_NUM_TOTAL
};

#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
  // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
  // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In, 5 Bulk etc ...
  #define EPNUM_CDC_NOTIF   0x81
  #define EPNUM_CDC_OUT     0x02
  #define EPNUM_CDC_IN      0x82

  #define EPNUM_MSC_OUT     0x05
  #define EPNUM_MSC_IN      0x85

#elif CFG_TUSB_MCU == OPT_MCU_SAMG
  // SAMG doesn't support a same endpoint number with different direction IN and OUT
  //    e.g EP1 OUT & EP1 IN cannot exist together
  #define EPNUM_CDC_NOTIF   0x81
  #define EPNUM_CDC_OUT     0x02
  #define EPNUM_CDC_IN      0x83

  #define EPNUM_MSC_OUT     0x04
  #define EPNUM_MSC_IN      0x85

#else
  #define EPNUM_CDC_NOTIF   0x81
  #define EPNUM_CDC_OUT     0x02
  #define EPNUM_CDC_IN      0x82

  #define EPNUM_MSC_OUT     0x03
  #define EPNUM_MSC_IN      0x83

#endif

#define CONFIG_TOTAL_LEN    (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)

uint8_t const desc_fs_configuration[] =
{
  // Config number, interface count, string index, total length, attribute, power in mA
  //TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),

  // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
  TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),

  // Interface number, string index, EP Out & EP In address, EP size
  //TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
};

// other speed configuration
uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];

// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
tusb_desc_device_qualifier_t const desc_device_qualifier =
{
  .bLength            = sizeof(tusb_desc_device_qualifier_t),
  .bDescriptorType    = TUSB_DESC_DEVICE_QUALIFIER,
  .bcdUSB             = USB_BCD,

  .bDeviceClass       = TUSB_CLASS_MISC,
  .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
  .bDeviceProtocol    = MISC_PROTOCOL_IAD,

  .bMaxPacketSize0    = CFG_TUD_ENDPOINT0_SIZE,
  .bNumConfigurations = 0x01,
  .bReserved          = 0x00
};

//--------------------------------------------------------------------+
// String Descriptors
//--------------------------------------------------------------------+

// array of pointer to string descriptors
char const* string_desc_arr [] =
{
  (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
  "TinyUSB",                     // 1: Manufacturer
  "TinyUSB Device",              // 2: Product
  "123456789012",                // 3: Serials, should use chip ID
  "TinyUSB CDC",                 // 4: CDC Interface
  "TinyUSB MSC",                 // 5: MSC Interface
};

static uint16_t _desc_str[32];

void
usb_init (void)
{
    // Setting of descriptor. You can use descriptor_tinyusb and
    // descriptor_str_tinyusb as a reference
    tinyusb_config_t tusb_cfg = { 0 }; // the configuration uses default values
    // Inizializzazione del driver.
    ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
    ESP_LOGI(g_p_tag, "USB initialization DONE");
    ESP_LOGI(g_p_tag, "Connect the USB connector!");
    // L'opzione CDC deve essere attiva in Menuconfig, in tal caso l'USB serial
    // device può essere inizializzato in base ai settaggi della struttura.
    ESP_ERROR_CHECK(tusb_cdc_acm_init(&g_amc_cfg));
}   /* usb_init() */
I created the desc_fs_configuration without TUD_CONFIG_DESCRIPTOR and TUD_CDC_DESCRIPTOR (note: the last one create an error because VS Code doesn't find the library although it's present).
As you can see, inside the array I'm using the define of your example:

Code: Select all

TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
I haven't changed nothing more. Now I'm stuck because I think I should pass the desc_fs_configuration to the function tusb_cdc_acm_init. Is it right?
Filippo

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32-S2 USB CDC problem in recognition

Postby chegewara » Mon Oct 18, 2021 2:49 pm

This is a default descriptor from tinyusb

Code: Select all

TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
you have to use some custom, like:

Code: Select all

TUD_CDC_DESCRIPTOR_AT(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
So, at the end code will look like:

Code: Select all

uint8_t const desc_fs_configuration[] =
{
  // Config number, interface count, string index, total length, attribute, power in mA
  TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),

  // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
  TUD_CDC_DESCRIPTOR_AT(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
};

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

Re: ESP32-S2 USB CDC problem in recognition

Postby filo_gr » Tue Oct 19, 2021 6:57 am

I noticed desc_fs_configuration is an array used inside a library, so I think if I modify it inside my code, this change will be seen also inside the USB library that uses the descriptor. Am I right?

Now the code is like that:

Code: Select all

#define _PID_MAP(itf, n)  ( (CFG_TUD_##itf) << (n) )
#define USB_PID           (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
                           _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )

#define USB_VID   0xCafe
#define USB_BCD   0x0200

enum
{
  ITF_NUM_CDC = 0,
  ITF_NUM_CDC_DATA,
  ITF_NUM_MSC,
  ITF_NUM_TOTAL
};

#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
  // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
  // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In, 5 Bulk etc ...
  #define EPNUM_CDC_NOTIF   0x81
  #define EPNUM_CDC_OUT     0x02
  #define EPNUM_CDC_IN      0x82

  #define EPNUM_MSC_OUT     0x05
  #define EPNUM_MSC_IN      0x85

#elif CFG_TUSB_MCU == OPT_MCU_SAMG
  // SAMG doesn't support a same endpoint number with different direction IN and OUT
  //    e.g EP1 OUT & EP1 IN cannot exist together
  #define EPNUM_CDC_NOTIF   0x81
  #define EPNUM_CDC_OUT     0x02
  #define EPNUM_CDC_IN      0x83

  #define EPNUM_MSC_OUT     0x04
  #define EPNUM_MSC_IN      0x85

#else
  #define EPNUM_CDC_NOTIF   0x81
  #define EPNUM_CDC_OUT     0x02
  #define EPNUM_CDC_IN      0x82

  #define EPNUM_MSC_OUT     0x03
  #define EPNUM_MSC_IN      0x83

#endif

#define CONFIG_TOTAL_LEN    (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)

// CDC Descriptor Template
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
#define TUD_CDC_DESCRIPTOR_AT(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
  /* Interface Associate */\
  8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
  /* CDC Control Interface */\
  9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, _stridx,\
  /* CDC Header */\
  5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
  /* CDC Call */\
  5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\
  /* CDC ACM: support line request */\
  4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
  /* CDC Union */\
  5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
  /* Endpoint Notification */\
  7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
  /* CDC Data Interface */\
  9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
  /* Endpoint Out */\
  7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
  /* Endpoint In */\
  7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0

uint8_t const desc_fs_configuration[] =
{
  // Config number, interface count, string index, total length, attribute, power in mA
  TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),

  // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
  TUD_CDC_DESCRIPTOR_AT(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
};

// other speed configuration
uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];

// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
tusb_desc_device_qualifier_t const desc_device_qualifier =
{
  .bLength            = sizeof(tusb_desc_device_qualifier_t),
  .bDescriptorType    = TUSB_DESC_DEVICE_QUALIFIER,
  .bcdUSB             = USB_BCD,

  .bDeviceClass       = TUSB_CLASS_MISC,
  .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
  .bDeviceProtocol    = MISC_PROTOCOL_IAD,

  .bMaxPacketSize0    = CFG_TUD_ENDPOINT0_SIZE,
  .bNumConfigurations = 0x01,
  .bReserved          = 0x00
};

//--------------------------------------------------------------------+
// String Descriptors
//--------------------------------------------------------------------+

// array of pointer to string descriptors
char const* string_desc_arr [] =
{
  (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
  "TinyUSB",                     // 1: Manufacturer
  "TinyUSB Device",              // 2: Product
  "123456789012",                // 3: Serials, should use chip ID
  "TinyUSB CDC",                 // 4: CDC Interface
  "TinyUSB MSC",                 // 5: MSC Interface
};

void
usb_init (void)
{
    // Setting of descriptor. You can use descriptor_tinyusb and
    // descriptor_str_tinyusb as a reference
    tinyusb_config_t tusb_cfg = { 0 }; // the configuration uses default values
    // Inizializzazione del driver.
    //vTaskDelay(pdMS_TO_TICKS(1000));
    ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
    ESP_LOGI(g_p_tag, "USB initialization DONE");
    ESP_LOGI(g_p_tag, "Connect the USB connector!");
    // L'opzione CDC deve essere attiva in Menuconfig, in tal caso l'USB serial
    // device può essere inizializzato in base ai settaggi della struttura.
    ESP_ERROR_CHECK(tusb_cdc_acm_init(&g_amc_cfg));
}   /* usb_init() */
I changed the TUD_CDC_DESCRIPTOR_AT with CDC_COMM_PROTOCOL_ATCOMMAND in the locations you indicated.
I build and flash the ESP32 device, no errors. However nothing is changed inside the descriptor.
Using UsbTreeView I can confirm the descriptor is the same as before this change inside the code.
Filippo

Who is online

Users browsing this forum: No registered users and 55 guests