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