USB Serial not working in mbed-os 6

I am working on mbed lpc1768. I made a simple program of sending the data over usb using USBSerial class.
After the device boots, USB is getting enumerating in PC but i am not receiving data on the USB.
Below is my code:

USBSerial serial;
int main(void)
{
while (1) {
serial._putc(“I am a virtual serial port\r\n”);
ThisThread::sleep_for(1000);
}
}
I tried to debug the issue using led but it is not coming to main it seems.
But if i use mbed-os 2, it works perfectly.

Hi there,
I do not have LPC1768 but I’m working on the Nucleo-F429ZI with USB OTG and it is working.

The USBSerial is set to blocking in the default. That mean it waits for a connection from opposite side, that is the reason why your code not reach the main. So until you not connect a terminal application on your pc to a correct port nothing will happen.
The PC application also need manage the DTR signal.

Also you can not call _printc for call a string without a for loop, the _printc(int c) means print only one char.

When you want a standart serial connection with PC you need to check BufferedSerial or UnbufferedSerial.

BR, Jan

Hi Johnny,

Thank you for your reply.
Its working now when i enabled DTR signal in the terminal.
But why this DTR signal is required in USB?

Truly, I have no idea, my knowledge is not so deep. I first heard about it in the post what I posted above from JojoS.

In declare USBSerial serial, you can specify “connect_blocking” with false , ususing the full constructor as specified in USBSerial.h
Georges
USBSerial(uint16_t vendor_id = 0x04D8, uint16_t product_id = 0x000A, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking){
settingsChangedCallback = 0;