Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

ESP32-S2 TinyUSB Set Manufacturer and product strings
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ESP32-S2 TinyUSB Set Manufacturer and product strings

by jockm on Tue Nov 23, 2021 7:58 pm

Is there a way to set the manufacturer and product description strings for the ESP32-S2 when using Adafruit_TinyUSB_Arduino?

If we look in Adafruit_USBD_Device.cpp we see that a number of functions are stubbed out when you are using the ESP32-S2, so calling setProductDescriptor() and setManufacturerDescriptor() won't work. Indeed we see this comment at line 139:

// EPS32 use built-in core descriptor builder.

So can anyone point me to how one uses the built-in core descriptor builder to set these strings?

jockm
 
Posts: 65
Joined: Mon May 13, 2013 11:43 pm

Re: ESP32-S2 TinyUSB Set Manufacturer and product strings

by hathach on Mon Nov 29, 2021 4:56 am


hathach
 
Posts: 1184
Joined: Tue Apr 23, 2013 1:02 am

Re: ESP32-S2 TinyUSB Set Manufacturer and product strings

by jockm on Mon Nov 29, 2021 5:22 pm

Following the lead of Adafruit_USBD_WebUSB.cpp, where USB.usbVersion() is set in the constructor:

Code: Select all | TOGGLE FULL SIZE
Adafruit_USBD_WebUSB::Adafruit_USBD_WebUSB(const void *url) {
  _connected = false;
  _url = (const uint8_t *)url;
  _linestate_cb = NULL;

#ifdef ARDUINO_ARCH_ESP32
  // ESP32 requires setup configuration descriptor within constructor

  // WebUSB requires USB version at least 2.1 (or 3.x)
  USB.usbVersion(0x0210);

  _webusb_dev = this;
  uint16_t const desc_len = getInterfaceDescriptor(0, NULL, 0);
  tinyusb_enable_interface(USB_INTERFACE_VENDOR, desc_len,
                           webusb_load_descriptor);
#endif
}


I placed the following code in startup():

Code: Select all | TOGGLE FULL SIZE
Adafruit_USBD_HID *usb_hid;

// the setup function runs once when you press reset or power the board
void setup()
{
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
   // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
   TinyUSB_Device_Init(0);
#endif

   linxBufferPos = 0;
   currentChannel = 255;

   USB.productName("productName");
   USB.manufacturerName("manufacturerName");
   USB.serialNumber("serialNumber");
   USB.webUSBURL("webUSBURL");
   // USB.begin();

   usb_hid = new Adafruit_USBD_HID(hidReportDescriptor, sizeof(hidReportDescriptor), HID_ITF_PROTOCOL_NONE, 2, true);
   usb_hid->setReportCallback(get_report_callback, set_report_callback);
   usb_hid->begin();

   // wait until device mounted
   while( !TinyUSBDevice.mounted() ) delay(1);
}


And saw no change in System Monitor.

I am sorry to be a pest, but this is all under-documented. I would gladly R the TFM if I could simply find one.

jockm
 
Posts: 65
Joined: Mon May 13, 2013 11:43 pm

Re: ESP32-S2 TinyUSB Set Manufacturer and product strings

by hathach on Tue Nov 30, 2021 1:46 am

by epressif design, all the descriptors cannot be changed one USB.begin() is called which is done before setup(). You have to do it within an object constructor to make sure it is invoked before USB.begin() (like webusb does). This behavior is specific to esp32 and annoying to me as well. You should look at their usb code in the core for more information

hathach
 
Posts: 1184
Joined: Tue Apr 23, 2013 1:02 am

Please be positive and constructive with your questions and comments.