4 years, 5 months ago.

How to use alternative USB port as default serial

The LCP4088QSB has two other USB ports besides the HDK USB port that is normally used for programming etc.

If I declare :

Serial pc(USBTX, USBRX); 

in my code the serial I/O goes to the HDK USB port.

I'd like to know what the declaration syntax is to enable use of USB#2 (Micro USB below Ethernet port) as a serial device instead of the HDK port - but only for debug/console I/O(!). Using Mbed OS5 btw.

I don't expect to be able to program the board via USB#2, it's just that when it's plugged into my prototype the HDK USB port gets fouled by other components. I'm happy to remove the LCP4088QSB board when I have to program it...

Any help appreciated.

2 Answers

4 years, 5 months ago.

Hi Chris,

Look at this pin description: https://os.mbed.com/media/uploads/embeddedartists/lpc4088_qsb_pinning.xlsx Use Pin Name as pin name like Serial pc(P0_2, P0_3); or Serial pc(p2, p3)

Probably you have to do some trials before you find correct pins. Try first replace USBTX and USBRX with Px_y. Uart 3 is p9 and p10 Uart 4 is p37 and p31

Regards, Pekka

Regards, Pekka

Thanks Pekka, I have done this as a workaround for now using a FT232 compatible adaptor.

posted by Chris Hoffmann 17 Nov 2019
4 years, 5 months ago.

You could use another set of serial port pins as proposed by Pekka, but that means you need to use a separate Serial to USB converter. Something like an FT232 (note that you must use the correct voltage 3V3).

The alternative is to use the USB device capability of the LPC4088 processor. The second USB port is connected to the processors USB engine. Note that it could also serve as USB host and that is what the USB connector next to the Ethernet is used for. You will have to include the USBSerial lib to make it work. Find some examples for the mbed LCP1768. I am not sure that all of that still works well with mbed OS5.

Thanks Wim, the 'alternative' you mention is what I'm looking for.

I'll look for the LCP1768 examples. I just want the USB serial device which (not host), from what I read so far, should be supported in OS5.

posted by Chris Hoffmann 17 Nov 2019

So, I'm having trouble reconciling the LPC1768 examples with the LPC4088 hardware...

The 1768 only has 1 additional USB channel whereas the 4088 has two (USB1 & USB2) yes? So how do I tell the USBSerial constructor to use USB2?

Also in Pekka's spreadsheet and the LPC4088QSB circuit, the CPU pins used by USB2 are P0.31 (D+) and 'USB_DM2' (D-).

The D- pin is not defined in any of the mbed target headers so I can't see how to construct it using a: USBSerial serial(USBTX, USBRX) style call. In any case the D+ & D- pins aren't UART pins so how can that constructor even work?

Very confused at the moment!

posted by Chris Hoffmann 18 Nov 2019

The ''normal'' serial port connection to the Host PC uses a regular serial port on the target processor (eg LPC4088) that is connected to the programmer hardware part of your board. The programmer is separate processor that behaves as a memory stick for drag&drop programming and also provides a virtual COM port to the PC. The programmer/interface is connected to the target serial pins and acts as USB-to-Serial converter. Pekka's spreadsheet suggests that the UART0 TXD, RXD pair (p0_2, p0_3) on the LPC4088 is used as (USBTX, USBRX). The USBTX, USBRX names are really just predefined aliases for the actual serial port pinnames.

The hardware USB engine on the LPC4088 is a separate peripheral device. It doesn't need any external converter to implement a USB Host or USB Device. It does however require the correct piece of software on your target to initialise and interface with the USB engine. It does not need any pin specification when instantiating the device because the specific external pins are hard connected to the USB engine and can't be remapped. Pekka's spreadsheet suggests that the USB Host uses (USB_D+1, USB_D-1) or (p0_29, p0_30) and the USB Device uses (USB_D+2, USB_D-2) or (p0_31, usb_dm2).

Instantiating the code would be something like this:

#include "mbed.h"
 #include "USBSerial.h"
 
 //Virtual serial port over USB
 USBSerial serial;  // No params needed. Pins are hardcoded
 
 int main(void) {
 
    while(1)
    {
        serial.printf("I am a virtual serial port\n");
        wait(1);
    }
 }

See here

The tricky part is that not all mbed platforms support the USBSerial lib. Someone needs to implement the code for that platform, assuming that the hardware is present on the device. I don't know about the LPC4088. You may have to try or check the sourcecode of the USB libs. In case it is not supported you may want to take a shortcut and use an external cheap USB-to-Serial converter like the FT232. It will cost just a few Euros on Aliexpress.

See here for example.

posted by Wim Huiskamp 18 Nov 2019

Thanks Wim for the fine detail. I think I grokked most of that already from the documents and digging around in the mbed-os target code for the LPC4088.

My confusion in the example code above (which I have seen already too) is that given that the LPC4088 has USB 1 (host) and USB2 (device) ports, which one is used by the instantiation "USBSerial serial;" ?

Is it 'device' (USB2) by default i.e is there a separate USB Host instantiation that automagically chooses USB1 (where supported)?

I shall try the above in my code and see what happens.

As I mentioned to Pekka, I've been working around it using a FT232 converter already

P.S. The compile succeeds but I get a runtime error:

++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x2F8B
Error Value: 0x0
Current Thread: main  Id: 0x10001D7C Entry: 0x86EF StackSize: 0x1000 StackMem: 0x10000540 SP: 0x1000145C
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=LPC4088
-- MbedOS Error Info --
This board does not have a hardware USB driver

I'm going to forget about it for now - didn't think it would be this difficult ;-)

Thanks Wim & Pekka for taking the time to reply...

posted by Chris Hoffmann 18 Nov 2019