How to create a simple FreeRTOS project with Embedded Studio

From SEGGER Wiki
Jump to: navigation, search

This article contains a guide that explains how FreeRTOS can be added to a generic SEGGER Embedded Studio(ES) project and how a simple, bare-metal FreeRTOS application can be created with that.


The following import tutorial will be based on the following Hardware and Software combinations:


This tutorial will be based on the hardware and software combination above. So if you are using another hardware steps might vary, but the general approach stays the same.

  1. Start Embedded Studio.
  2. (optional) install CPU support Package for your device family via Tools->Package Manager.
  3. Create new project via File->New Project->Create the project in a new solution.
    1. Set a project name. If no CPU package is used then select "A C/C++ executable for a Cortex-M processor". Press Next, select your target device and keep pressing Next until your project is finished.
    2. If you are using a CPU support package select the "A C/C++ executable for..." from the corresponding package and finish your project as described in the point above.
  4. Connect your J-Link to your PC and to your target board.
  5. Give your newly created project a try by building it with F7 and executing it with F5. You should see now some Hello World printf in terminal.
  6. Create a new folder /lib/FreeRTOS/FreeRTOS-Kernel in both the project explorer in Embedded Studio and on your hard drive in the project folder.
  7. Download and unpack the FreeRTOS software to any location.
  8. In the unpacked folder open folder /FreeRTOS and copy the folder /FreeRTOS/Source to the /lib/FreeRTOS/FreeRTOS-Kernel in your ES project folder.
  9. Now add the same files to the Embedded Studio project explorer. The easiest way is to drag and drop the folder onto the /lib/FreeRTOS/FreeRTOS-Kernel folder.
  10. Right click that new folder and select Setup. Check the box "Recurse into Subdirectories" and press OK.
  11. This should add all FreeRTOS sources to your setup. However not all files are needed so the wrong files have to be removed again. To do this first convert the folder to a regular folder by right clicking it and select "Convert to regular folder".
  12. You will need all .c source files from the /Source folder. All include files from /Source/include and the folders /Source/portable/GCC and /Source/portable/MemManage.
  13. All other folders and files can be safely removed by simply selecting them and pressing the DEL key our right click and delete.
  14. Next make sure that in /Source/portable/MemManage you only have one .c file selected e.g. heap_1.c. Remove all other .c files, otherwise the project will later not build.
  15. In /Source/portable/GCC make sure that only the folder is included that is the architecture of your target platform. In our example it is a Cortex-M4 target device so only folder /Source/portable/GCC/ARM_CM4F stays. All other folders can be safely removed as before.
  16. Next you will need to create a FreeRTOSConfig.h file which will configure your FreeRTOS setup. For references see the FreeRTOS documentation or use one of the config headers from the many samples out there as reference. For example the one from the example project above. We recommend to place this file into your source folder where your main.c file is. In this case it is folder /source in the project folder.
  17. Next all include paths need to be set. You can add this in project options under Project->Options->Preprocessor->User Include Directories. If you are using the same folder structure as recommended the following three include paths must be set. If you are using another project structure adjust the paths accordingly.
    1. $(ProjectDir)/source
    2. $(ProjectDir)/lib/FreeRTOS/FreeRTOS-Kernel/Source/include
    3. $(ProjectDir)/lib/FreeRTOS/FreeRTOS-Kernel/Source/portable/GCC/ARM_CM4F
  18. Now edit your main.c to include FreeRTOS.h and task.h and add your FreeRTOS application code to the main.c You can use the example projects main as reference.
  19. (optional) add your third party libraries, HALs, drivers etc. to your project similarly to how you added the FreeRTOS kernel sources.
  20. Once all this is done your application should build now and you should be able to debug your first FreeRTOS application in Embedded Studio!


  • Make sure all include paths are set correctly.
  • The Embedded Studio compiler is clang based. So make sure that the sources you add outside of FreeRTOS are clang compatible.