How to create a simple FreeRTOS project with Embedded Studio
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:
- SEGGER Embedded Studio 5.42a or later
- Target Evalboard: SEGGER Cortex-M Trace Reference Board
- J-Link V11 or later
- J-Link 19-Pin Cortex-M Adapter
- FreeRTOS V10.4.3 or later
- Example project
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.
- Start Embedded Studio.
- (optional) install CPU support Package for your device family via Tools->Package Manager.
- Create new project via File->New Project->Create the project in a new solution.
- 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.
- 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.
- Connect your J-Link to your PC and to your target board.
- 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.
- 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.
- Download and unpack the FreeRTOS software to any location.
- In the unpacked folder open folder /FreeRTOS and copy the folder /FreeRTOS/Source to the /lib/FreeRTOS/FreeRTOS-Kernel in your ES project folder.
- 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.
- Right click that new folder and select Setup. Check the box "Recurse into Subdirectories" and press OK.
- 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".
- 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.
- All other folders and files can be safely removed by simply selecting them and pressing the DEL key our right click and delete.
- 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.
- 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.
- 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.
- 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.
- 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.
- (optional) add your third party libraries, HALs, drivers etc. to your project similarly to how you added the FreeRTOS kernel sources.
- 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.