Upgraded FreeRTOSConfig.h Configuration File Guide

Upgraded FreeRTOSConfig.h Configuration File Guide

Introduction

In the last article, I provided runnable code. Those who have tested it should know that getting FreeRTOS up and running is quite simple; there is no need to modify a lot of code and configuration information to successfully integrate FreeRTOS into your project.

This article will discuss the code within FreeRTOS, keeping simplicity and fundamentals in mind for most readers.

The contents of the “FreeRTOSConfig.h” configuration file have increased with the addition of features (functionality) in each version. This means that as the system’s capabilities grow, the corresponding configuration information also increases. However, the system has implemented compatibility measures for previous code.

For example: configUSE_QUEUE_SETS is an option defined in “FreeRTOSConfig.h”. If the user does not define it, there is a similar definition in “FreeRTOS.h“.

#ifndef configUSE_QUEUE_SETS

#define configUSE_QUEUE_SETS 0

#endif

When designing the FreeRTOS system, engineers certainly considered minimizing the development difficulty for developers. When we first learn to port FreeRTOS, most configurations in “FreeRTOSConfig.h” can be left at their defaults. Only after becoming familiar with it and needing more functions later on must we thoroughly understand each configuration.

For those not averse to English, I recommend referring to the official website, as the official materials are the most authoritative.

Official website address:

http://www.freertos.org/a00110.html

Upgraded FreeRTOSConfig.h Configuration File Guide

From the materials provided on the official website, we can see that “FreeRTOSConfig.h” divides configuration information into ten major categories, but many of these configurations can be left undefined (or unused).

Technical articles on WeChat accounts are not easy to be too lengthy, so this article focuses on general configurations for beginners.

General Configuration

This chapter, also known as basic configuration, consists of some configurations that we need to define, which are also quite important.

Note: Those marked with (*) are relatively easier to understand or are more important.

The FreeRTOSConfig.h configuration file involves many system-related terms, which may be difficult for many beginners to understand. For example: semaphores, message queues, mutexes, event groups, etc.

But don’t worry, just have a general understanding; I will focus on these topics again later.

1.configUSE_PREEMPTION

Scheduling Mode Configuration

Set to 0: cooperative scheduling, meaning time slices are executed in turn;

Set to 1: preemptive scheduling, meaning higher-priority tasks execute first;

Since we require real-time response, we set it to 1, using preemptive scheduling. Otherwise, it would not fulfill the role of a real-time operating system.

2.configCPU_CLOCK_HZ

CPU Clock, commonly referred to as the main frequency. Note: the unit is Hz.

For example: STM32F407 main frequency is 168M:

#define configCPU_CLOCK_HZ (168000000)

3.configTICK_RATE_HZ

System Tick, which refers to the number of ticks the system generates per second, can be thought of as the system’s heartbeat, but it needs to be distinguished from the main frequency. The value of the system tick should be based on the CPU’s main frequency; generally, the higher the main frequency, the larger the value, typically between 100 and 1000.

A simple example: the system tick determines vTaskDelay.

For example:

#define configTICK_RATE_HZ (1000)

Then:

vTaskDelay(1000), indicates a delay of 1 second.

4.configMAX_PRIORITIES

Maximum System Priority Value

The priority value configured when creating tasks cannot exceed this maximum value.

xTaskCreate(vAppTask1, “Task1”, TASK1_STACK_SIZE, NULL, TASK1_PRIORITY, NULL);

Note:

a. The principle of system priority is similar to that of interrupt priority; higher priority tasks will preempt lower priority ones, but the application scenarios for system and interrupt priorities must be distinguished.

b. In FreeRTOS, the higher the numerical value, the higher the priority. In UCOS, it is the opposite.

5.configMINIMAL_STACK_SIZE

Minimum Stack Size

In the system, it is generally used for idle, timing, and other system tasks. Of course, we can also use this defined stack size in some places.

Note the unit of the value; generally, in ARM, it is 4 bytes.

6.configTOTAL_HEAP_SIZE

Total Heap (Stack) Size

We need to define this value based on the situation we need to use. It cannot be defined too small, as small memory can easily overflow; nor can it be defined too large, as some chips have limited RAM (some only have a few K); if it is too large, we cannot define many global variables or allocate other stack space.

7.configMAX_TASK_NAME_LEN

Maximum Task Name Length

This is the string length for defining task names when creating tasks.

xTaskCreate(vAppTask1, “Task1“, TASK1_STACK_SIZE, NULL, TASK1_PRIORITY, NULL);

Note: The terminator ‘\0’ is also included.

8.configUSE_16_BIT_TICKS

Whether to use 16-bit tick count values

Set to 0: use 32-bit tick count values, generally configured as 0 in 32-bit processors;

Set to 1: use 16-bit tick count values, generally configured as 1 in 8-bit or 16-bit processors.

9.configIDLE_SHOULD_YIELD

Whether to allow the idle task to yield preemption

This means whether the idle task has the opportunity to preempt during the execution of tasks with the same priority as the idle task.

Set to 0: do not yield preemption;

Set to 1: yield preemption;

10.configUSE_MUTEXES

Whether to use mutexes

Set to 0: not used

Set to 1: used

Note: A mutex is also called a mutex semaphore, which means “locking” resources. Its function is to implement exclusive processing of shared resources between multiple tasks. In simple terms, a resource is only allowed to be processed by one task at a time, and only after processing is it allowed for other tasks to handle that resource.

For example: Task A has a higher priority than Task B; both tasks will use a serial port to send command data (which must be fully sent each time without interruption). When Task B is sending data, Task A is in a ready state (ready to interrupt Task B). Task B needs to use a mutex to occupy the serial port (lock, occupy the resource), and after sending the command, it releases the serial port (unlock, release the resource). Once the resource is released, Task A can use the serial port (resource).

11.configUSE_RECURSIVE_MUTEXES

Whether to use recursive mutexes

Set to 0: not used

Set to 1: used

13.configQUEUE_REGISTRY_SIZE(*)

Number of queue names that can be added (or registered)

This configuration information is difficult to translate; it mainly works with vQueueAddToRegistry and vQueueUnregisterQueue functions.

Directly showing the function interfaces:

void vQueueAddToRegistry(QueueHandle_t xQueue, const char *pcQueueName);

void vQueueUnregisterQueue(QueueHandle_t xQueue);

From the function interfaces, we can see that one function registers (already created) queue names; one function unregisters queue names;

The main purpose is to name (already created) queues for easier debugging and searching.

Note: Many beginners misunderstand this as “the maximum number of queues that can be created”; this configuration parameter is completely different in concept.

14.configUSE_QUEUE_SETS(*)

Whether to use message queue “SET” functionality

Set to 0: not used

Set to 1: used

This configuration information is also relatively difficult to understand.

Note: Many explanations online state: enable/disable message queues. This understanding is too general and there is a lot of information related to message queue configuration; I personally think it is incorrect.

15.configUSE_TIME_SLICING

Whether to use time slicing for scheduling

This parameter is used in conjunction with the first configuration parameter configUSE_PREEMPTION.

This configuration parameter was added in later versions; it seems it was not present before version V7. Therefore, it is not included in the FreeRTOSConfig.h configuration file by default but is defined in FreeRTOS.h.

#ifndef configUSE_TIME_SLICING

#define configUSE_TIME_SLICING 1

#endif

Highlights

The previously released eBook version received positive feedback. Therefore, I will continue to compile a PDF version of the FreeRTOS series tutorial for everyone.

[Note: WeChat accounts do not support external links]

FreeRTOS series tutorial PDF eBook download link:

http://pan.baidu.com/s/1nuHFF5n

Upgraded FreeRTOSConfig.h Configuration File Guide

Many online tutorials do not have accompanying demo examples. I hope that this series of tutorials, combined with demo examples, will make it easier for everyone to learn.

FreeRTOS_STM32F0_Demo download link:

http://pan.baidu.com/s/1qYbmfy0

FreeRTOS_STM32F1_Demo download link:

http://pan.baidu.com/s/1jHDHRPc

FreeRTOS_STM32F2_Demo download link:

http://pan.baidu.com/s/1mi3eIdq

FreeRTOS_STM32F3_Demo download link:

http://pan.baidu.com/s/1kUZu5G7

FreeRTOS_STM32F4_Demo download link:

http://pan.baidu.com/s/1bplLZ7x

Conclusion

Search for “EmbeddDeveloper” on WeChat or scan the QR code below to follow, and check out more exciting content!

Upgraded FreeRTOSConfig.h Configuration File Guide

Long press to recognize the QR code to follow

Previously, iOS users said they could not tip. Today I found a new feature; the mini-program supports tipping, which seems to be specifically for iOS users.

Upgraded FreeRTOSConfig.h Configuration File Guide

Today, I will test this feature. Will you be the first?

Leave a Comment

×