Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS+ Products FreeRTOS Labs Integration Services Contact / Enquiries

Combining LPCOpen Examples
Adding USB Virtual COM / CDC Functionality into the lwIP Example

Previous pages have demonstrated a stand alone LPCOpen project that uses the USB drivers built into the LPC1800 part to very easily create a USB virtual COM port, and a FreeRTOS LPCOpen project that created a simple ping echo server. This page shows how to take advantage of FreeRTOS's multi tasking environment to very easily add the virutal COM port example into the echo server example, so both examples run on the LPC1830 Xplorer board simultaneously.

It is assumed that all preceding steps have already been completed.

The instructions on this page combine the TCP and USB examples in a crude manner. The page that follows demonstrates how some small FreeRTOS specific updates to the code can change the run-time behaviour, and in so doing improve run-time efficiency. Improved run-time efficiency in turn allows the microcontroller to either execute a larger and more complex application, or spend more of its time in a low power state.

Workflow steps:
  1. The LPC1800 chip support, LPC1830 Xplorer board support, usbd_rom_cdc_vcom and freertos_tcpecho projects should already be included in the LPCXpresso workspace.

    The following C source files within the usbd_rom_cdc_vcom project are used to implement the interface to the hardware USB drivers, define the USB CDC descriptors, and provide the simple USB CDC echo functionality respectively:

    • cdc_vcom.c
    • cdc_desc.c
    • cdc_main.c

    The three C source files listed above rely on the following two C header files:

    • app_usbd_cfg.h
    • cdc_vcom.h

    Copy all five files from the usbd_rom_cdc_vcom project into the src and inc folders as apprpriate of the freertos_tcpecho project. The file copy can be done directly from the Eclipse project explorer window, or as a standard file copy (the Eclipse project will need to be refreshed if the a standard file copy is used).

    The files to copy from the USB project into the TCP project

  2. The include path used by the freertos_tcpecho project must be updated to include the path to the C header files that map source code callable API functions onto the ROMed (hardware) USB drivers.

    View the properties for the freertos_tcpecho project by right clicking on the project in the Eclipse project explorer and selecting 'Properties' from the pop up menu.

    Add /lpc_chip_18xx/inc/usbd as an include path.

    Adding the path to the header files that map to the hardware USB drivers

  3. One of the files copied from the USB project into the TCP project included an implementation of main(), so now the TCP project contains two implementations of main(). The main() function in cdc_main.c is going to be renamed, and its prototype is going to be changed to allow it to instead be created as a FreeRTOS task.

    Open the freertos_tcpecho.c file that was just copied into the TCP project, and located the definition of main(). Change the definition of main() from:

    int main(void)
    void cdc_task( void *pvParameters )
    Note some of the initialisation code is also duplicated in the two main() functions (one of which was just renamed), but this can be ignored in this basic example.

    Converting main() into a task in cdc_main.c

  4. Now the prototype of the function has been changed it can be created as a FreeRTOS task.

    This time open the freertos_cdcecho.c C source file and locate the implementation of main() it contains. It already creates an lwIP task. Add in code that also creates the Virtual COM / CDC task, as shown in the image below.

    Creating the CDC demo as a task

  5. Build, download and run the example as before. This time when you run the application you will be able to connect to the USB virtual COM / CDC port and ping the LPC1800 at the same time.

    Typing text into a Tera Term window that is connected to the USB virtual COM / CDC port

    Receiving ping replies from the LPC1830 target

Next: Using simple FreeRTOS techniques to massively reduce CPU usage

[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS+ Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.