Arm Mbed OS support forum

USBSerial on f446re

I’m trying to use the USBSerial class on a nucleo F446re board using platformio.

I tried with the example on the HandBook manual, the simplest possible:

// clang-format off
#include <mbed.h>
#include <USBSerial.h>
// clang-format on

// Virtual serial port over USB

int main(void) {
  USBSerial serial;
  while (1) {
    serial.printf("I am a virtual serial port\r\n");
    ThisThread::sleep_for(1000);
  }
}

There are two problems here: the first is that when I compile if USBSerial is included before mbed it does not compile…

The second is that this example is giving a fatal error (function mbed_die) as soon as it constructs the USBSerial object.

Hello,

that is obsolate, the latest you can found here - USBSerial - API references and tutorials | Mbed OS 6 Documentation

In addition you also need to place the content below to the mbed_app.json file

{
    "config": {
        "usb_speed": {
            "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
            "value": "USE_USB_OTG_FS"
        }
    },
    "target_overrides": {
        "*": {
            "target.device_has_add": ["USBDEVICE"]
        }
    }
}

The PC application also need to manage the DTR signal .

BR, Jan