Setting up USB device on ESP32-S3
Posted: Wed Oct 04, 2023 7:36 pm
Hi there, I’m attempting to use an ESP32-S3 board as device, the exact board I’m using being esp32-s3-devkitc-1-N8R2. What I want to do is to use it as a composite USB device, combining keyboard and CDC ; the cdc serial port being used to configure macros on the keyboard through a software on the computer.
I have managed to make it work as a keyboard, but I can’t seem to be able to configure the CDC as I wish. Since to detect the right USB device to communicate to, I have to scan for the right VID/PID but I can’t change this. Here is the code I am working with (which is a simplified code taken from the ESP32 GitHub) :
The serial works correctly, I can write things on the hardware serial and see the bytes coming on the usb serial just right. The only issue here is that the USB descriptor is kept as the original one on my device manager. The VID, PID, Product Name and Manufacturer Name that are debugged to USBSerial are the default ones, though I should have changed them in setup.
I am using the Platformio framework, but I believe everything is setup correctly : I have to unset the flag and set on the build flags, so here is the platformio.ini file :
Has anyone been able to perform this ? Or is the hardware simply not supporting changing the USB descriptor ?
I have managed to make it work as a keyboard, but I can’t seem to be able to configure the CDC as I wish. Since to detect the right USB device to communicate to, I have to scan for the right VID/PID but I can’t change this. Here is the code I am working with (which is a simplified code taken from the ESP32 GitHub) :
- #include <Arduino.h>
- #include "USB.h"
- #include "USBCDC.h"
- #define HWSerial Serial0
- #define USBSerial Serial
- void setup() {
- USB.VID(0x1234);
- USB.PID(0x5678);
- USB.productName("Test1");
- USB.manufacturerName("Test2");
- HWSerial.begin(115200);
- USBSerial.begin(115200);
- USB.begin();
- }
- void loop() {
- USBSerial.println(USB.VID());
- USBSerial.println(USB.PID());
- USBSerial.println(USB.productName());
- USBSerial.println(USB.manufacturerName());
- while(HWSerial.available()){
- size_t l = HWSerial.available();
- uint8_t b[l];
- l = HWSerial.read(b, l);
- USBSerial.write(b, l);
- }
- delay(100);
- }
I am using the Platformio framework, but I believe everything is setup correctly : I have to unset the flag
Code: Select all
ARDUINO_USB_MODE
Code: Select all
ARDUINO_USB_CDC_ON_BOOT
- ; PlatformIO Project Configuration File
- ;
- ; Build options: build flags, source filter
- ; Upload options: custom upload port, speed and extra flags
- ; Library options: dependencies, extra library storages
- ; Advanced options: extra scripting
- ;
- ; Please visit documentation for the other options and examples
- ; https://docs.platformio.org/page/projectconf.html
- [env:esp32-c3-devkitm-1]
- platform = espressif32
- board = esp32-s3-devkitc-1
- ; change microcontroller
- board_build.mcu = esp32s3
- ; change MCU frequency
- board_build.f_cpu = 240000000L
- build_unflags = -D ARDUINO_USB_MODE
- build_flags = -D ARDUINO_USB_CDC_ON_BOOT=1
- framework = arduino
- monitor_port = COM7
- upload_port = COM7
- monitor_speed = 115200
- monitor_rts = 0
- monitor_dtr = 0