Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


Simple example of FreeRTOS on Arduino

  • Nicolas JAN
    Nicolas JAN


    I work on a project which need some tasks carried out in the same time on
    my Arduino Uno. And after few web researches, I found your project.

    I try to make a simple example with a task which writes on the serial port.
    But when I load the program, the arduino card sends me texts with strange
    characters (example : GCÿƒ#ÿØ#ü¿cÿ€¤äƒ›ç¼ƒã£Dà [Ã'§'ä['¼¸C#$Dà)

    Have you an idea where comes from this bug ?

    This is my code :

    main.c :

    include <stdlib.h>

    include <stdbool.h>

    include <string.h>

    #include <avr io.h="">

    / Scheduler include files. /

    include <FreeRTOS.h>

    include <task.h>

    include <queue.h>

    include <semphr.h>

    / serial interface include file. /

    include <lib_serial.h>

    / Create a handle for the serial port. /

    xComPortHandle xSerialPort;

    static void vHelloWorld(void*);

    static void vHelloWorld(void*)


    for( ;; )


    xSerialPrintf("Hello World !\n");




    / Main program loop /

    int16_t main(void) attribute((OS_main));

    int16_t main(void)


    xSerialPort = xSerialPortInitMinimal( 115200, portSERIAL_BUFFER,

    avrSerialPrintf("Start of Main()\n");

    xTaskCreate( vHelloWorld, ( signed portCHAR * ) "vHelloWorld", 50,



    Nicolas JAN

    • Nicolas,

      thanks for writing.

      Garbage on the serial port is almost always caused by a mismatch of speeds. The Arduino frequency of 16MHz is one of the worst cases, because it doesn't divide closely to any serial bit rate and there's always a small rate error.

      I'm guessing that this case is caused because the CPU_CLOCK_HZ is not set to 16000000. This is done in the freeRTOS/include/FreeRTOSConfig.h file. Just adjust the comment appropriately, from my default below.

          #define configCPU_CLOCK_HZ      ( ( uint32_t ) 22118400 )       // Modded Arduino (usually 16000000) with 328p device
      //  #define configCPU_CLOCK_HZ      ( ( uint32_t ) 16000000 )       // Arduino with 328p device

      For a bit more background, see here.

      Good luck.