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:
-
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
-
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
-
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)
to
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
-
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
-
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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.