LPC1347 USB Library Part 1

January 14, 2013

In preparation for the new LPC1347 board I have compiled the USB code into a library file that can be included into a project to provide access to printf. The library includes access to the USB CDC, UART and standard IO. The code in the library includes a complete USB stack along with a subset of the standard I/O facilities provided for C programming. The code library is based on the USB ROM code that is included on the LPC1347 processor. The application interface has been made as simple as possible and is described below.

void Comport_Init(char device,int baudrate):

The port parameter can be one of BRIDGE,UART or CDC. The bridged mode connects the UART and CDC together while the other modes direct the character output to the specified I/O port. The baud rate is required when you select the UART otherwise it is optional and is ignored since the CDC sets the baud rate. This must be called prior to any other LPC USB library calls.

void putchar(char data):

Send a single byte of data.

char getchar(void):

Receive a single byte of data. This function is blocking; it will wait forever if no character arrives. Use the rx_ready() function to test if any data is available.

char rx_ready(void):

Non blocking test for receive data. If data is available the function returns true.


Standard formatted print supporting strings, characters and hex. %x, %s, %d, %c

Setup Library

I used the GCC compiler to compile the code and create a library archive. The code design consists of the source code for the USB stack along with a stdio library extracted from Newlib libc. These files can be built from the command line using a makefile or from within the Programmers Notepad project. Currently the makefile only supports the LPC1347 because it uses the ROM drivers that are part of this chip; of course it is also possible to build for other targets like the LPC11Uxx but that would require a lot more work and I don’t need the feature.

The complete library project is provided as a Programmers Notepad project. The library is already compiled so all you need to do is install it in the correct directories. Assuming you have followed my notes on installing GCC and programmers notepad you will have installed the libraries in c:\DNC_LABS


One Response to LPC1347 USB Library Part 1

  1. Aaron
    February 13, 2013 at 5:07 pm

    I took a look at your code while developing my own CDC port using the ROM drivers. After a lot of digging it turns out that you need to reenable the SOF interrupt after every Configure_Event, then you’ll start getting the SOF events and won’t need to fake it with the SysTick. Thanks for putting me on the right track.

    usb_param.USB_Configure_Event = CDC_Configure_Event;

    ErrorCode_t CDC_Configure_Event (USBD_HANDLE_T hUsb) {

    USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*)hUsb;
    if (pCtrl->config_value) { /* Check if USB is configured */
    // initialize buffer parameters
    g_vCOM.tx_in_progress = 0;
    g_vCOM.rxlen = 0;
    g_vCOM.txlen = 0;
    // enable the SOF interrupt again (which was disabled by the ROM drivers)
    return LPC_OK;

Leave a Reply

Your email address will not be published. Required fields are marked *