Cortex-M3 / IAR Port
for Luminary Micro Stellaris microcontrollers
[RTOS Ports]
The port was developed using the DK-LM3S316 development kit.
Stellaris is a new range of embedded microcontrollers - the first to be commercially available with a Cortex-M3 core. The LM3S316 is a
low cost, low pin count device. It has
4KBytes of RAM and 16KBytes of ROM on chip. The demo
application code size has been deliberately limited to ensure it builds using the 8KByte code size limited KickStart version of the IAR tools.
From FreeRTOS.org V4.7.1 all IAR projects for ARM devices are saved using the IAR Embedded Workbench V5.x format and will not open from V4.x versions.
FreeRTOS.org V4.7.0 and earlier are still available from SourceForge and can be used with Embedded Workbench V4.x.
The IAR Cortex-M3 demo relies on a driver library file which is licensed separately from FreeRTOS.org. A full copy of the license applicable to this library is
contained in the EULA.txt file located in the Demo/CORTEX_LM3S316_IAR/hw_include directory within the FreeRTOS.org download.
There are currently four FreeRTOS.org ports for Luminary Micro Stellaris Cortex-M3 based microcontrollers -
one that uses the Sourcery G++ (GCC) tools, one that uses the
ARM Keil tools, one for Rowley CrossWorks,
and the port presented on this page which uses the IAR Embedded Workbench tool chain.
Upgrading to FreeRTOS.org V4.8.0: Prior to V4.8.0 the FreeRTOS.org kernel did not make use of the SVCall interrupt. From V4.8.0 onwards it does.
Therefore, to upgrade an older project to the V4.8.0 standard, a small edit to the startup code is required. To do this, simply install
vPortSVCHandler() in the SVCall position within the interrupt vector table (contained in the startup source file). The demo projects included in the
FreeRTOS.org download have already been updated so these can be used as an example.
Note: The V4.3.0 version of the IAR port introduced the configKERNEL_INTERRUPT_PRIORITY configuration parameter. This parameter permits the interrupt priority used by the kernel to be
configured such that the kernel activity will never delay a higher priority interrupt. See the Configuration and Usage section of this page for more information.
IMPORTANT! Notes on using the ARM Cortex-M3 IAR port
Please read all the following points before using this RTOS port.
- Source Code Organization
- The Demo Application
- Configuration and Usage Details
See also the FAQ My application does not run, what could be wrong?
Source Code Organization
The FreeRTOS.org download contains the source code for all the FreeRTOS ports so contains many more files that 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 IAR workspace for the Luminary Micro port is located in the FreeRTOS/Demo/CORTEX_LM3S316_IAR directory and is called RTOSDemo.eww.
The Demo Application
The FreeRTOS.org source code download includes a preconfigured demo applications for the IAR port. This demonstrates both fully preemptive tasks and co-routines - with 8
co-routines and 5 tasks being created (including the idle task).
Demo application hardware setup
Most of the DK-LM3S316 jumpers can remain in their default positions. For the ADC to correctly read the light sensor ensure jumper 0 is also in position on
the ADC connector JP2.
The demo application includes an interrupt driven UART test where a co-routine transmits characters that are then received by a task. For correct operation
of this functionality a loopback connector must be fitted to the SER0 connector of the DK-LM3S316 target board (pins 2 and 3
must be connected together on the 9Way connector).
The demo application uses the LEDs built into the prototyping board so no other hardware setup is required.
A J-Link JTAG interface is used to interface the host PC with the target.
Functionality
See the comments at the top of Demo/CORTEX_LM3S316_IAR/main.c for a detailed explanation of the demo functionality.
When executing correctly the demo application will behave as follows:
- The top row of the LCD will display a rotating message - originating from the 'LCD Message' demo task.
- The bottom row of the LCD will display the ADC 0 value, which can be connected to the DK-LM3S316 light sensor as described by the "hardware setup" section above. This
originates from the 'ADC' demo co-routine.
- LEDs marked LED0 to LED4 are under control of the 'flash' co-routines. Each will flash at a constant frequency, with LED0 being
the fastest and LED 4 being the slowest.
- LED5 will flash each time a character is transmitted on the serial port.
- LED6 will flash each time a character is received and validated on the serial port (though the loopback connector).
- LED7 is used to indicate an error has been detected and should remain off.
The demo includes functionality that checks all the tasks and co-routines are executing without error. If an error is located in any co-routine or task
LED7 will be turned on. This functionality can be tested by removing the loopback connector while the demo is executing and in so doing deliberately generating
an error.
Building and executing the demo application
To build the application simply open RTOSDemo.eww from within the Embedded Workbench IDE, then select "Rebuild all" from the "Project" menu.
To download then execute the demo:
- Connect your host computer to the target board using the J-Link J-TAG interface.
- Click the "Debug" speed button, or simply press CTRL D.
- The LM3S31x flash memory will be programmed and the debugger will stop at the beginning of main().
RTOS Port specific configuration
Configuration items specific to these demos are contained in FreeRTOS/Demo/CORTEX_LM3S316_IAR/FreeRTOSConfig.h. The
constants defined in this file can be edited to suit your application. In particular -
- configTICK_RATE_HZ
This sets the frequency of the RTOS tick. The supplied value of 1000Hz is useful for
testing the kernel functionality but is faster than most applications require. Lowering this value will improve efficiency.
- configKERNEL_INTERRUPT_PRIORITY
This sets the interrupt priority used by the kernel.
The kernel should use a low interrupt priority (high numeric value), allowing higher priority interrupts to be unaffected by the
kernel entering critical sections. Instead of critical sections globally disabling interrupts, they only disable interrupts that
are below the kernel interrupt priority.
This permits very flexible interrupt handling:
- At the kernel priority level interrupt handling 'tasks' can be written and prioritised
as per any other task in the system. These are tasks that are woken by an interrupt. The interrupt service routine (ISR) itself should be written to be as short
as it possibly can be - it just grabs the data then wakes the high priority handler task. The ISR then returns directly into the
woken handler task - so interrupt processing is contiguous in time just as if it were all done in the ISR itself. The benefit of this is that
all interrupts remain enabled in the handler task. The Ethernet driver within the LM3S6965 demo uses a handler task to demonstrate the mechanism.
-
ISR's running above the kernel priority are never masked out by the kernel itself, so their responsiveness is not effected by the kernel functionality.
However, such ISR's cannot use the FreeRTOS.org API functions. The fast timer interrupt test within the LM3S6965 demo demonstrates this behaviour.
This parameter will default to 255 if omitted from the FreeRTOSConfig.h file.
Each port #defines 'portBASE_TYPE' to equal the most efficient data type for that processor. This port defines
portBASE_TYPE to be of type long.
Note that vPortEndScheduler() has not been implemented.
Interrupt service routines
The interrupt vector table is contained within FreeRTOS/Demo/CORTEX_LM3S316_IAR/hw_include/startup.c and can be populated as required.
In 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. This mechanism is demonstrated by the UART ISR called vUART_ISR() and
defined within commtest.c.
Note that portEND_SWITCHING_ISR() will leave interrupts enabled.
Switching between the pre-emptive and co-operative real time kernels
Set the definition configUSE_PREEMPTION within FreeRTOS/Demo/CORTEX_LM3S316_IAR/FreeRTOSConfig.h to 1 to use pre-emption or 0
to use co-operative. The demo application will only execute correctly with configUSE_PREEMPTION set to 0 if configIDLE_SHOULD_YIELD is set to 1.
Compiler options
As 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 files.
Memory allocation
Source/Portable/MemMang/heap_1.c is included in the ARM Cortex-M3 demo application project 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 driver
It 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 optimized solution.
Copyright (C) 2003 - 2008 Richard Barry
Any and all data, files, source code, html content and documentation included in the FreeRTOS distribution or available on this site are the exclusive property of Richard Barry.
See the files license.txt (included in the distribution) and this
copyright notice for more information. FreeRTOS
TM and FreeRTOS.org
TM are trade marks of Richard Barry.