|Hint: Use the tree menu to navigate groups of related pages|
NXP LPC1768 ARM Cortex-M3 LPCXpresso Demo
Including Embedded Web Server and USB Examples
[Embedded Ethernet Examples]
NOTE: This demo was created with the Red Suite IDE. NXP have since acquired Code Red’s technology and now the demo can instead be used with NXP’s LPCXpresso IDE.
The demo presented on this page is pre-configured to run on the RDB1768 evaluation board from Code Red (Code Red have since been acquired by NXP). The board was fitted with an LPC1768 Cortex-M3 microcontroller from NXP.
The demo uses:
- The FreeRTOS GCC ARM Cortex-M3 port.
- The Red Suite Eclipse based IDE from Code Red (now the LPCXpresso IDE from NXP as noted at the top of this page) – which includes the FreeRTOS state viewer plug-in as standard. An Eclipse ‘managed make’ project is used.
- Adam Dunkels open source uIP embedded TCP/IP stack to implement a web server with CGI scripting.
- Bertrik Sikkens open source LPCUSB USB stack to implement a CDC class echo server.
The FreeRTOS ARM Cortex-M3 port includes a full interrupt nesting model. Interrupt priorities must be set in accordance with the instructions on the Customisation page for correct operation.
IMPORTANT! Notes on using the NXP ARM Cortex-M3 Web Server DemoPlease read all the following points before using this RTOS port.
My application does not run, what could be wrong?
Source Code OrganisationThe Red Suite project for the LPC1768 demo is located in the FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite directory. This is the directory to select when importing the project into your Red Suite workspace.
The FreeRTOS zip file download contains the files for all the ports and demo application projects. It therefore contains many more files than used by this demo. See the Source Code Organization section for a description of the downloaded files and information on creating a new project.
The Demo Application
Creating the project directory structureThe easiest way to use an Eclipse managed make build is to locate the required build files (C source files, header files and linker scripts) under the directory that contains the Eclipse project file. FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite/CreateProjectDirectoryStructure.bat is a batch file that will copy the required files from their normal locations within the FreeRTOS directory structure to sub directories under the Eclipse project directory. The batch file must be executed prior to attempting a build.
Execute CreateProjectDirectoryStructure.bat from either a command prompt or Windows explorer. It cannot be executed successfully from within the Eclipse environment itself.
Importing the project into a Red Suite workspace
- Start Red Suite. As it starts up you will be prompted for a workspace location. You can use your existing workspace or create a new one in a convenient location.
- Within the Red Suite IDE, select ‘Import…’ from the ‘File’ menu.
- A dialog box will appear. Select ‘Existing Projects Into Workspace’, then click ‘Next’.
- Browse to and select the FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite directory to complete the import process. Take care that the
‘Copy projects into workspace’ check box is NOT checked during this last step.
Importing the FreeRTOS project into the Red Suite workspace
Web server configurationConnect the RDB1768 development board to a computer running a web browser either directly using a point to point (crossover) cable, or via a Ethernet switch using a standard Ethernet cable.
The IP address used by the demo is set by the constants configIP_ADDR0 to configIP_ADDR3 within the file FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite/src/FreeRTOSConfig.h. The MAC address and net mask are configured within the same header file.
The IP addresses used by the web browser computer and the RDB1768 development board must be compatible. This can be ensured by making the first three octets of both IP addresses identical. For example, if the web browser computer uses IP address 192.168.100.1, then the development board can be given any address in the range 192.168.100.2 to 192.168.100.254 (barring any addresses already present on the network).
Building and executing the demo application
- Open main.c and search for a line that starts “#error”. Delete the line (it provides instructions on setting up the directory structure for those using the project without first reading these instructions).
- Connect the RDB1768 to the host computer using the Debug USB port. This both powers the target and provides a debug interface.
- To build the project, simply select ‘Build All’ from the ‘Project’ menu. The application should build with no errors or warnings (assuming the #error statement has been removed).
- A launch configuration needs to be created before a debug session can be started. This only needs to be done once, after it has been created debug sessions can be started simply by clicking the ‘Debug’ speed button. To create a launch configuration first select ‘Open Debug Dialog…’ from the ‘Run’ menu.
- In the dialog box that opens, double click where it says ‘C/C++ MCU Application’ to create a new configuration. The configuration parameters will be set automatically.
- Finally click ‘Debug’ to program the MCU flash memory and start a debug session.
Setting up the launch configuration
FunctionalityThe demo application creates 36 tasks prior to starting the RTOS scheduler. These tasks consist predominantly of the standard demo application tasks (see the demo application section for details of the individual tasks). Their only purpose is to test the RTOS kernel port and provide a demonstration of how to use the various API functions.
The following tasks and tests are created in addition to the standard demo tasks:
- Check function – called from the tick hook
This only executes every five seconds. Its main function is to check that all the standard demo tasks are still operational. The check function maintains a status string that can be viewed on the “Task Stats” page served by the uIP TCP/IP web server.
- uIP task
This is the task that handles the uIP stack. All TCP/IP processing is performed in this task.
- USB task
This is the task that handles the USB stack. The USB device will enumerate as a CDC device. The USB task simply echoes received characters with an offset which by default is one. Therefore if ‘A’ is received ‘B’ will be echoed back. If ‘x’ is received ‘y’ will be echoed back, etc.
When executing correctly the demo application will behave as follows:
- LEDs 2, 3 and 5 are under the control of the standard ‘flash’ tasks. Each will toggle at a different but fixed frequency.
- The USB device port of the RDB1768 will enumerate as a CDC class device. To use the USB port (assuming a Windows host computer):
- Connect the RDB1768 to your host computer using the USB device port of the RDB1768 (marked J11).
- The host computer should recognise the new USB connection and prompt for the location of a suitable .inf file. Select the option to manually select the .inf file location, then browse to usbser.inf which is located in the FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite directory. Assuming usbser.sys is available on your host computer the CDC device will be assigned a COM port number. The Windows Device Manager can be used to ascertain the actual number assigned.
- Open up a dumb terminal such as Hyperterminal and select the enumerated COM port number. Other parameters such as baud rate and flow control settings are not required and can be left at their default values.
- Type ‘A’ into the terminal window, if everything is working correctly you should see ‘B’ echoed back.
Note that a queue is used to pass each individual character between the USB interrupt service routine and the USB task. This is a convenient method for a slow echo server, but very inefficient if large amounts of data are to be transferred.
- The target hardware will serve the web pages described below to a standard web browser. To connect to the target:
- Open a web browser on the connected computer.
- Type “HTTP://” followed by the target IP address into the browsers address bar.
Entering the IP address into the web browser
(obviously use the correct IP address for your system)
Served Web PagesThe top of each served page includes a menu containing a link to every other page.
The served RTOS stats page showing status information on each task in the system.
The served run time stats page showing the processor utilisation of each task.
The served IO page
The IO page provides a simple interface that permits data to be sent to an LED. The check box permits the state of the user LED to be both set and queried. Changes are sent to the target hardware by clicking the “Update IO” button.
The TCP Stats and Connections pages display run time networking information.
RTOS port specific configurationConfiguration items specific to these demos are contained in FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite/src/FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application. In particular –
This sets the frequency of the RTOS tick. The supplied value of 1000Hz is useful for testing the RTOS kernel functionality but is faster than most applications require. Lowering this value will improve efficiency.
- configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY
See the RTOS kernel configuration documentation for full information on these configuration constants.
The lowest priority on a ARM Cortex-M3 core is in fact 255 – however different ARM Cortex-M3 vendors implement a different number of priority bits and supply library functions that expect priorities to be specified in different ways. Use the supplied examples as a reference.
Each port #defines ‘BaseType_t’ to equal the most efficient data type for that processor. This port defines BaseType_t to be of type long.
Note that vPortEndScheduler() has not been implemented.
Interrupt service routinesIn the demo application the vector table remains in flash.
Unlike most ports, interrupt service routines that cause a context switch have no special requirements and can be written as per the compiler documentation. The macro portEND_SWITCHING_ISR() can be used to request a context switch from within an ISR. An example interrupt service routine called vEMAC_ISR() is provided in FreeRTOS/Demo/CORTEX_LPC1768_GCC_RedSuite/src/webserver/emac.c. This should be used as a reference example.
Note that portEND_SWITCHING_ISR() will leave interrupts enabled.