Hello,
usually is good to share with us some informations about Mbed OS version, about a tool what you use and share a link of the example what you tried.
Anyway, you probably mixed something. I see above you try to setup the USB OTG aka onchip USB interface. But the code more looks like old code for old library with UART.
- The constructor is not correct, just use example from Mbed documentation - USBSerial - API references and tutorials | Mbed OS 6 Documentation
- These macros
USBTX
andUSBRX
are for the VCP debug console over UART via ST-link.
BR, Jan