Setting Up FreeRTOS From Scratch on STM32F407 Discovery Kit

Choosing FreeRTOS as a Real-Time Operating System for your embedded project is a great choice. The FreeRTOS is truly free and provides many simple and effective RTOS features. But setting up freeRTOS from scratch might be difficult or I can say a bit confusing as it requires some customization such as adding Microcontroller specific files, setting header file paths, etc. In this Instructable, I will guide you on how to set up FreeRTOS on your STM32F407 Discovery kit in detail using Kiel uVision IDE.

Supplies:

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Open Keil UVision IDE

Open Keil uVision IDE. Click on a project the select New uVision Project...Then select your working directory and give your preferred project name.

Step 2: Select the Device

Once you have given name to the project, in the next step you need to add device. Here we are adding STM32F407VG Micronconroller from STMicroelectronics. Select the STM32F407VG, then Click OK.

Step 3: Manage Run-Time Environment

The next step is to select the library/driver component in the Manage Run-Time Environment Tab. Here select all components as shown in the above picture. Once you check all appropriate field Click Resolve then Click OK.

Step 4: Copy FreeRTOS Into Your Project Folder

Now you need to Copy the entire FreeRTOS folder into your project folder.

Step 5: Add FreeRTOS Files to Project

Once you have copied the FreeRTOS folder inside your project folder, you have to add all the necessary FreeRTOS files to your Project.

  1. In Keil, Select Target1, right-click then select Add new group. Rename this group as FreeRTOS.
  2. Now Click on the FreeRTOS group, right-click the select Add Existing files to Group "FreeRTOS..."
  3. Add all the FreeRTOS files as shown in the above picture.

The path to finding these files in FreeRTOS folder are :

  • Files: croutine, event_groups, list, queue, stream_buffer, tasks and timers. Path: (....\FreeRTOSv10.2.1\FreeRTOS\Source)
  • Files:heap_4(There are 4 memory management files add anyone). Path: (....\FreeRTOSv10.2.1\FreeRTOS\Source\portable\MemMang)
  • Files: port.c (This is an MCU specific file). Path: (...\FreeRTOSv10.2.1\FreeRTOS\Source\portable\RVDS\ARM_CM4F)

Note : FreeRTOS version may change. Just use the latest version available.

Step 6: Configure the Path of the FreeRTOS Header Files

Once you have added the FreeRTOS source files, you need to tell the compiler where respective header files are located. Hence we need to configure the compiler option.

Right Click on Target1--> Option for Target "Target1.." --> C/C++--> Include path. Make sure you include these paths :

  1. Include folder in FreeRTOS ( ...\FreeRTOSv10.2.1\FreeRTOS\Source\include)
  2. RVDS directory (...\FreeRTOSv10.2.1\FreeRTOS\Source\portable\RVDS\ARM_CM4F)

Note: If you have any header files, make sure you include the path of these header files as explained above.

Step 7: Add "FreeRTOSConfig.h" File to Project

The FreeRTOS has one important header file called FreeRTOSConfig.h. This file contains the application-specific(in our case-specific to Cortex M4F MCU) customization. For simplicity, I have copied our MCU specific FreeRTOSConfig.h file in the RVDS directory. And also in step 6, we have already added the RVDS path. If you're adding it yourself then You have to add this file in your project and also make sure you include the path of this file as explained in step 6.

Incase if you want to add FreeRTOSConfig.h file by your self in your preferred directory, I have included this file below.

For more information Click here FreeRTOSConfig.h

Step 8: Add the "main.c" File With the Basic Template

  • Now Create a New User group( I have renamed it to "User application").
  • Add a new C-file to this Group( I have added a file called main.c).
  • This is the file where the main() function exists. I have included all the minimum required functions and headers into this file so that the project successfully compiles.

You can find the main.c file with basic template below.

Step 9: Connect Your STM32F407 Discovery Kit to Your PC/Laptop

Step 10: Select ST-Link Debugger in Compiler Configuration

Right Click on Target1, then click on Option for Target "Target1..", then navigate to Debug Tab andSelect ST-Link-Debugger as shown in the above picture

Step 11: Configure ST-Link Debugger

After selecting the ST-Link Debugger in step 10, click on Settings then select Trace and check all the fields as shown in the above picture.

Step 12: Build and Upload the Code

After completing all the steps build the project and make sure there are no errors in the code. After successful compilation, upload the code to your Discovery Kit.

Step 13: Goto to Debug Window and Open Serial Monitor

After uploading go to debug window-->view-->Serial Windows-->Debug(printf) Viewer as shown in the above picture.

Step 14: Run the Code to See the Ouput on Debug Printf Window

The Final step is to run the code as shown in the picture to see the output in the printf window. Here in main.c I have implemented 2 simple tasks called task1 and task2. Both the task have the same priority and they just print the name of the task. Due to the same priorities you can see both of them running and printing the name.

Be the First to Share

    Recommendations

    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    Discussions