ATmega32u4: change USB device class to CDC

I have an Arduino Lilypad USB. Here's what usb-devices shows:

T:  Bus=01 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 12 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=1b4f ProdID=9208 Rev=01.00
S:  Manufacturer=SparkFun   
S:  Product=LilyPadUSB      
C:  #Ifs= 3 Cfg#= 1 Atr=80 MxPwr=500mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm
I:  If#=0x1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm
I:  If#=0x2 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

Now the problem is that the class is not 0x02 (CDC) and is instead 0x00.

Because of that the ESP32-S3-OTG-USB board I have does not recognize it:

E (5340) cdc_acm: cdc_acm_host_open(718): USB device with VID: 0x1B4F, PID: 0x9208 not found

How do I change the class from 0x00 to 0x02 (CDC)?

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

This is far (and I mean FAR) outside my area of knowledge.

I hope that the below gets you on the way (and doesn't put you on the wrong foot).

  1. Enable verbose output during compilation under file → preferences in the IDE.
  2. Compile a sketch for the Lilypad USB.
  3. In your output you will find which core is used and where it is located.
Using board 'LilyPadProtoUSB' from platform in folder: C:\Users\yourUsername\AppData\Local\Arduino15\packages\SparkFun\hardware\avr\1.1.13
Using core 'arduino' from platform in folder: C:\Users\yourUsername\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
  1. In the core directory you will find a number of files that relate to USB; CDC.cpp, USB*.cpp and USB*.h, there might be others.
  2. Start digging through them and modify what is needed.
  3. Compile a sketch and check.

Good luck

Notes

  • These instructions are for IDE2.0; I'm reasonably sure that they also apply to 1.8.x.
  • The change that you make might affect all boards or all future compiles for the LilyPad; you're advised to make backups :wink:

Do you get from a fresh LilypadUSB? Sparkfun says that they use a slightly modified Caterina bootloader which shouldn't include a HID interface. It seems you have uploaded a sketch to this device and the class shows the correct value: 0 means "Use class information in the Interface Descriptors". If you have a device class 2 you must not offer an HID interface.

If you want to try to change that, you'll find the corresponding code in USBCore.cpp:

#ifdef CDC_ENABLED
const DeviceDescriptor USB_DeviceDescriptorIAD =
	D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
#else // CDC_DISABLED
// The default descriptor uses USB class OxEF, subclass 0x02 with protocol 1
// which means "Interface Association Descriptor" - that's needed for the CDC,
// but doesn't make much sense as a default for custom devices when CDC is disabled.
// (0x00 means "Use class information in the Interface Descriptors" which should be generally ok)
const DeviceDescriptor USB_DeviceDescriptorIAD =
	D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
#endif

The first argument to the D_DEVICE macro is the device class.

It's rather strange that your code choose the 0 class as you can see here that's only the case if CDC is disabled which isn't the case actually in you device.

Are you sure that your device conforms fully to the Communications Device Class Specification? I guess there is a reason why Arduino chose the 0xEF class for most CDC devices.