Modifying a FreeRTOS Demo
to use a different compiler or run on different hardware
[Demo Projects]

What This Page is About

FreeRTOS already includes many demo applications - each of which is targeted at:
  1. A specific microcontroller.
  2. A specific development tool (compiler, debugger, etc.).
  3. A specific hardware platform (prototyping or evaluation board).
These are documented under 'Supported Devices' in the menu frame on the left.

Unfortunately it is not possible to provide a demo project for every combination of microcontroller, compiler and evaluation board - so it might be that a demo application does not exist that matches your required setup exactly. This page documents how existing demo applications can be modified or combined to better match the setup you require.

It is generally a simple task to take an existing demo for one evaluation board and modify it to run on another - and only slightly more complex to take a demo for one compiler and modify it to use another. This page provides instruction on these and similar porting type activities. It is not so simple however to take a FreeRTOS port and convert it to run on a completely different, and as yet unsupported, processor core architecture. This page does not therefore cover the topic of creating completely new FreeRTOS ports.


Converting a Demo to Use a Different Evaluation Board

This subsection documents the steps required to convert an existing demo application from one prototyping board to another, without changing either the microcontroller or compiler being used. As an example, these instructions would be used to convert the IAR SAM7S demo targeted at the SAM7S-EK hardware to instead target the Olimex SAM7-P64 prototyping board.

Ensure each step is completed successfully prior to moving to the next:

  1. Initial compilation:

    An existing demo application should be used as a starting point for the conversion exercise, therefore first check you can successfully compile the existing demo application exactly as downloaded - before making any modifications. In most cases the demo application should compile without any errors or warnings.

    This WEB site contains a documentation page for each demo application included in the FreeRTOS download. Please ensure to read this in full. Build instructions are included.

  2. Modifying the LED IO:

    LEDs provide the easiest method of getting visual feedback that the demo application is running, so it is useful to get the LEDs on the new hardware platform working as soon as possible.

    It is unlikely that the hardware platform to which the demo is being ported has LEDs on the same IO ports as the hardware platform on which the demo was developed - so some minor modification will be required.

    The function vParTestInitialise() within partest.c contains the IO port mode and direction configuration. The function prvSetupHardware() within main.c contains more generic hardware configuration (for example, enabling the clock to the IO peripheral) and may also require some modification, depending on the port being used.

    Make any changes necessary to the two function highlighted in the paragraph above, then write a very simple program to check that the LED outputs are working. This simple program need not make use of FreeRTOS - all that is of interest at this stage is ensuring the LEDs work - so for now comment out the existing main() function and replace it with something similar to the following example:

        int main( void )
        {
        volatile unsigned long ul; /* volatile so it is not optimized away. */
    
            /* Initialise the LED outputs - note that prvSetupHardware() might also 
            have to be called! */
            vParTestInitialise();
    
            /* Toggle the LEDs repeatedly. */
            for( ;; )
            {
                /* We don't want to use the RTOS features yet, so just use a very 
                crude delay mechanism instead. */
                for( ul = 0; ul < 0xfffff; ul++ )
                {
                }
    
                /* Toggle the first four LEDs (on the assumption there are at least 
                4 fitted. */
                vParTestToggleLED( 0 );
                vParTestToggleLED( 1 );
                vParTestToggleLED( 2 );
                vParTestToggleLED( 3 );
            }
    
            return 0;
        }
    

  3. Introducing the scheduler:

    Once the LEDs are known to be working the dummy main() function can be removed, and the original main() function restored.

    It is advisable to start with the simplest multitasking application possible. The standard 'flash test' tasks are often used initially as a multitasking equivalent of a 'hello world' type application.

    The standard 'flash test' tasks are a set of 3 very simple tasks - each of which toggles a single LED at a fixed frequency, with each task using a different frequency. These tasks are included in nearly all the demo applications, and are started within main() by a call to the function vStartLEDFlashTasks() (or vStartFlashCoRoutines() should the co-routine version be used instead). If the main() function of the demo you are using does not call vStartLEDFlashTasks() (or alternatively vStartFlashCoRoutines()) then simply add the file FreeRTOS/Demo/Common/Minimal/Flash.c to your build and add the call to vStartLEDFlashTasks() manually.

    Comment out every function that is used to start one or more demo tasks, other than the call to vStartLEDFlashTasks(). It is likely that main() will then only call three functions: prvSetupHardware(), vStartLEDFlashTasks(), and vTaskStartScheduler(). For example (based on the typical main() introduced earlier):

        int main( void )
        {
            /* Setup the microcontroller hardware for the demo. */
            prvSetupHardware();
    
            /* Leave this function. */
            vCreateFlashTasks(); 
    
            /* All other functions that create tasks are commented out.
            
                vCreatePollQTasks();
                vCreateComTestTasks();
                Etc.
    
                xTaskCreate( vCheckTask, "check", STACK_SIZE, NULL, TASK_PRIORITY, NULL );
            */
    
            Start the scheduler. */
            vTaskStartScheduler();
    
            /* Should never get here! */
            return 0;
        }
    
    This very simple application is running correctly if LEDs 0 to 2 (inclusive) are under the control of the 'flash' tasks and each is toggling at a fixed but different frequency.

  4. Finishing off:

    Once the simple flash demo is executing you can restore the full demo application with all the demo tasks being created.

    Points to keep in mind:

    • If the demo application did not originally have a call to vTaskCreateFlashTasks(), and a call to this function was added manually, then the call should be removed again. This is for two reasons, first the flash tasks may use LED outputs that are already used elsewhere within the demo, and second the full demo might already use all the available RAM, meaning there is no room for additional tasks to be created.
    • The standard 'com test' tasks (if included in the demo) will utilise one of the microcontrollers UART peripherals. Check that the UART used is valid for the hardware onto which you have ported the demo.
    • It is unlikely that peripherals such as LCDs will function without modification to account for any hardware or interface differences.


Combining or Modifying Existing Demo Projects

This subsection highlights the details that require consideration to either modify an existing project, or combine two existing project, both with the aim of creating a project specific to your requirements. For example, you may wish to create an STR9 demo project that uses the GCC compiler. While the FreeRTOS download may not (at the time or writing) include a GCC STR9 demo, it does include an IAR STR9 demo, and a GCC STR75x demo. The information required to create the STR9 GCC project can be gleaned from these two existing project. There are two ways this can be done:
  1. Take an existing demo project that uses the correct compiler but targets a different microcontroller, and re-target this to the required microcontroller.
  2. Create a new project using your chosen compiler. When this option is taken an existing demo project can be used as a guide to which files and settings are required, even if the existing project uses a different compiler.
The following notes highlight the information that requires consideration whichever method is used:



Copyright (C) 2010 Real Time Engineers Ltd.
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 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..