Page 1 of 1

How to implement custom PID and VID?

Posted: Thu Aug 31, 2023 7:35 pm
by frotaitalos
I imagine that maybe my question is too much of a beginner, but I've researched a lot about it and I haven't found anything enlightening about it.

I use esp32-s2 in my commercial products, my devices have USB for the user to update the devices, and for now I'm only using the USB Serial feature, but I want to start using the real USB protocol, and for that I need the Custom PID for the web software I'm developing to automatically connect to my device. I already requested the PID allocated in the Espressif VID, but I still have no idea how I will enter this into the device when I have the custom PID. I already have the inclusion of the USB API in my code and I've tested codes like the following below.


[Codebox]MSC_Update.onEvent(usbEventCallback);
USB.onEvent(usbEventCallback);
USBSerial.begin();
USB.PID(0x81A4);
USB.VID(0x303A);
USB.begin();[/Codebox]

But when recognizing the device by my computer, I notice that the PID has not been changed, could someone point me out what I'm doing wrong? I want to use all the USB API so that my device is recognized by the computer with the product information (brand name, model, version, etc).

Re: How to implement custom PID and VID?

Posted: Thu Aug 31, 2023 8:00 pm
by lbernstone
You need to set the PID & VID before you call begin. I just tested the USBSerial example, and was able to change the VID & PID this way.
Note that you can only assign one device class. If you are using USBSerial (aka USB-CDC), you will not be able to also treat that same device as an MSC. I'm not going to say this would be impossible, but you are not going to find an out of box solution for that (you would pretty much have to write your own device class).

Re: How to implement custom PID and VID?

Posted: Mon Sep 04, 2023 5:27 pm
by frotaitalos
lbernstone wrote:
Thu Aug 31, 2023 8:00 pm
You need to set the PID & VID before you call begin. I just tested the USBSerial example, and was able to change the VID & PID this way.
Note that you can only assign one device class. If you are using USBSerial (aka USB-CDC), you will not be able to also treat that same device as an MSC. I'm not going to say this would be impossible, but you are not going to find an out of box solution for that (you would pretty much have to write your own device class).

I tried again following your instructions but it didn't work. I've attached screenshots so you can check. The device keeps showing up as a COM port and with another VID

Re: How to implement custom PID and VID?

Posted: Mon Sep 04, 2023 6:52 pm
by lbernstone
I started from the USBSerial example. Directly after the HWSerial initialization, I added the lines for VID and PID (before any other USB calls). Make sure the board settings are USB Mode: USB OTG, disable USB-CDC on boot, and upload mode is USB OTG.

Code: Select all

larryb@larryb-IdeaPad:~/esp32/arduino-esp32/libraries/USB/examples$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 0bda:c123 Realtek Semiconductor Corp. Bluetooth Radio
Bus 003 Device 002: ID 27c6:55b4 Shenzhen Goodix Technology Co.,Ltd. Fingerprint Reader
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 5986:212a Acer, Inc Integrated Camera
Bus 001 Device 017: ID dead:beef Espressif Systems ESP32S3_DEV
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Re: How to implement custom PID and VID?

Posted: Mon Sep 04, 2023 8:06 pm
by lbernstone
Rereading your post, everything is working for you. VIDs are hex numbers, I recommend you use a 0x for your numbers. 1234 = 0x04D2