Please note: From FreeRTOS V5.1.0 the demo presented on this page has switched from using the old (and discontinued) Keil DKARM compiler to instead use the latest Keil/RVDS/ARM compiler.
The port was developed on an MCB2100 development/prototyping board (instructions are provided should you wish to use an alternative development board) using a ULINK USB JTAG adapter. The Keil simulator also proved very useful. A complete development kit can be obtained from Hitex Development Tools.
The MCB2100 is a fully featured and comprehensive prototyping board that allows easy access to the LPC2129 peripherals and includes 8 built in LEDs which are utilised by the FreeRTOS demo application.
The development tools include a compiler, assembler and linker tool chain along with an IDE and excellent device specific simulator. The simulator includes a 'logic analyzer' feature that can be used to monitor the microcontroller IO - providing the same visual feedback in the simulated environment that the LEDs do on the real target hardware. Unfortunately the evaluation version of the tools are limited to a combined ROM and RAM image size of 16KBytes - which is too restrictive to run this demo (because the FreeRTOS heap memory is included in the 16KBytes, even if it is not being used).
IMPORTANT! Notes on using the Keil/ARM/RVDS LPC2129 RTOS portPlease read all the following points before using this RTOS port.
My application does not run, what could be wrong?
Source Code OrganisationThe FreeRTOS download contains the source code for all the FreeRTOS ports so contains many more files than required to run this demo. See the Source Code Organization section for a description of the downloaded files and information on creating a new project.
The uVision project file for this demo is called RTOSDemo.Uv2 and can be located in the Demo/ARM7_LPC2129_Keil_RVDS directory.
The project contains two configurations, one that uses the ARM instruction set and one that uses the THUMB instruction set.
The Demo ApplicationThe FreeRTOS source code download includes a fully preemptive multitasking demo application for the Keil LPC2000 RTOS port.
Demo application hardware setupThe demo application includes tasks that send and receive characters over the serial port. The characters sent by one task need to be received by another - if any character is missed or received out of sequence an error condition is flagged. A loopback connector is required on the serial port for this mechanism to operate (simply connect pins 2 and 3 together on the P1 serial port connector of COM 1 - a paper clip is usually sufficient for this purpose).
The demo application uses the LEDs built into the prototyping board so no other hardware setup is required.
FunctionalityThe demo application creates 25 tasks. When executing correctly the demo application will behave as follows:
Building the demo application
Running the demo applicationThe demo application can be executed in the simulator or on the target hardware. To switch between the simulator and JTAG debugger:
Using the simulator and logic analyzerThe microcontroller IO ports can be monitored using the simulators 'logic analyzer' feature. Below is a screen capture of the logic analyzer being used to monitor certain output pins while the demo application is being simulated.
Monitoring the port pins in the logic analyzer
The red green and blue lines show pins P1.16, P1.17 and P1.18 respectively under control of the 'Flash' tasks. The black line shows pin P1.19 which is toggled each time a character is transmitted. You would need to zoom much closer in to see the line being toggled for each individual transmitted character.
When being simulated the 'Check' task will find an error in the 'ComTest' tasks. This is because the 'ComTest' tasks require a loopback connector as described previously.
Programming the flashThe demo application can be programmed into the microcontroller flash from within the Keil IDE using the 'Flash' menu item. The prototyping board must be reset to start the program executing.
The flash must be programmed before the JTAG debugger can be used.
RTOS port specific configurationConfiguration items specific to this port are contained in Demo/ARM7_LPC2129_Keil_RVDS/FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application. In particular - the definition configTICK_RATE_HZ is used to set 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.
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 routinesA context switch might be required from within an interrupt service routine if the interrupt causes a task to unblock (through a queue or semaphore event), and the unblocked task has a priority higher than the interrupted task.
An interrupt service routine that cannot cause a context switch has no special requirements and can be written as per the normal RVDS syntax. Interrupt service routines that can cause a context switch require an assembly file wrapper, as demonstrated below.
See the file Demo/ARM7_LPC2129_Keil_RVDS/serial/serialISR.s within the demo application for a full example.
The assembly file wrapper calls a C function (in the example above the C function is called vUART_ISRHandler()) in which the main interrupt functionality can be implemented. The C function has no special requirements and does not need any special function qualifiers. See the function vUART_ISRHandler() within Demo/ARM7_LPC2129_Keil_RVDS/serial/serial.c for a full example. vUART_ISRHandler() also demonstrates the portEXIT_SWITCHING_ISR() macro, which is used to ensure the correct task is selected to run once the interrupt exits.
To use a part other than an LPC2129The LPC2129 uses a standard ARM7 core with processor specific peripherals. The core real time kernel components should be portable across all ARM7 devices - but the peripheral setup and memory requirements will require consideration. Items to consider:
Switching between the pre-emptive and co-operative RTOS kernelsSet the definition configUSE_PREEMPTION within Demo/ARM7_LPC2129_Keil_RVDS/FreeRTOSConfig.h to 1 to use pre-emption or 0 to use co-operative.
Compiler optionsAs with all the ports, it is essential that the correct compiler options are used. The best way to ensure this is to base your application on the provided demo application project file - as described in the Source Organization section.
Execution ContextThe RTOS scheduler executes in supervisor mode, tasks execute in system mode.
NOTE! : The processor MUST be in supervisor mode when the RTOS scheduler is started (vTaskStartScheduler is called). The demo applications included in the FreeRTOS download switch to supervisor mode prior to main being called. If you are not using one of these demo application projects then ensure Supervisor mode is entered before calling vTaskStartScheduler().
Interrupt service routines always run in ARM mode.
Demo/ARM7_LPC2129_Keil_RVDS/Startup.s configures stacks for system/user, IRQ and SWI modes only.
SWI instructions are used by the real time kernel and can therefore not be used by the application code.
Memory allocationSource/Portable/MemMang/heap_2.c is included in the ARM7 demo application makefile to provide the memory allocation required by the real time kernel. Please refer to the Memory Management section of the API documentation for full information.
Serial port driverIt should also be noted that the serial drivers are written to test some of the real time kernel features - and they are not intended to represent an optimised solution.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.
FreeRTOS and other embedded software careers at AWS.