5 years, 4 months ago.

Using Serial and USBSerial in the same program?

I am using LPC11U35/501. I has both A USB interface and a serial (UART) interface. I want to use both in a program that communicates with a computer over USB (using virtual serial port) on one hand and with a ESP8266 wifi module via the UART on the other.

I can make the USBSerial working and I can make the UART working but when I am using both, the UART part works well but the virtual serial port on the computer (Mac OSX) gets only 0x00 bytes.

Is there a way to use both the USB serial and UART in the same program?

My Test Program

#include "mbed.h"
#include "USBSerial.h"
DigitalOut led(P0_7);  // LED pin on my board.
//Virtual serial port over USB
USBSerial usb_serial;

// Hardware serial to wifi device.
Serial wifi_serial(P0_19, P0_18);  // tx, rx

Timer timer;

void setup() {

void loop() {
  if (timer.read_ms() < 500) {
  led = !led;    // Invert LED state

int main(void) {
  for(;;) {

1 Answer

5 years, 4 months ago.

I tried your program on TG-LPC11U35-501, it works fine :)


If you are using CoolTerm or some other GUI terminal application, please try re-establishing the connection after the program start. (This can be done by pressing "Disconnect" and "Connect" buttons.)
Since the program initializes the USB at every time of the program start, the previous connection on the PC is aborted.


Accepted Answer

Thanks Tedd, this was very useful. I tried it on a TG-LPC11U35 and my binary run well. I tried it on another board of mine (different design than my first board) and it also worked well. The original board I used is a very minimal design where the 1.5k usb pullup is hardwired to 3.3V (instead of switching with a transistor). For some reason it worked well without the Serial. Possibly the Serial initialization increased the initialization time which resulted in premature enumeration. Lesson learnt. ;-)

posted by Zapta Z. 16 Feb 2015