Essential Configurations for FreeRTOS Configuration Files

Follow+Star Public Account Number, don’t miss wonderful content

Essential Configurations for FreeRTOS Configuration Files

Author | strongerHuang

WeChat Public Account | strongerHuang

The content of the “FreeRTOSConfig.h” configuration in FreeRTOS increases with the addition of versions (features), meaning that as system functionality increases, the corresponding configuration information also increases.

However, in order to maintain compatibility with previous code, the system itself has made compatibility provisions. 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 must have thought about minimizing the development difficulty for developers. When we first learn to port FreeRTOS, most configurations in “FreeRTOSConfig.h” can be chosen as defaults. Only after becoming familiar with it and needing to use more features later, must we thoroughly understand the various configurations inside.
For friends who are not averse to English, it is recommended to refer to the official website, as the official materials are the most authoritative.

Official website address:

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

Essential Configurations for FreeRTOS Configuration Files

General Configuration

Basic configuration is a set of configurations that we need to define, and it is also quite important.
The FreeRTOSConfig.h configuration file involves many terms related to the system, 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 explaining it later.
1.configUSE_PREEMPTION
Scheduling Mode Configuration
Set to 0: cooperative scheduling, i.e., time slices are executed in turn;
Set to 1: preemptive scheduling, i.e., tasks with higher priority execute first;
Since we require real-time response, set it to 1, using preemptive scheduling. Otherwise, it will not fulfill the role of a real-time operating system.
2.configCPU_CLOCK_HZ
CPU Clock, which is commonly referred to as the main frequency. Note: the unit is Hz.
For example: the main frequency of STM32F407 is 168M:
#define configCPU_CLOCK_HZ      (168000000)
3.configTICK_RATE_HZ
System Tick, which is the number of ticks per second, can be said to be the heartbeat of the system, but it needs to be distinguished from the main frequency. The value of the system tick should be based on the CPU main frequency; generally, the higher the main frequency, the larger the value, usually between 100 and 1000.
For example: the system tick determines vTaskDelay.
For example:
#define configTICK_RATE_HZ (1000)
Then:
vTaskDelay(1000), which indicates a delay of 1S.
4.configMAX_PRIORITIES
Maximum System Priority Value
When we create tasks, the configured priority value cannot exceed this maximum value.
xTaskCreate(vAppTask1, “Task1”, TASK1_STACK_SIZE, NULL, TASK1_PRIORITY, NULL);
Tip:
a. The system priority is similar to interrupt priority; higher priority will preempt lower priority, but the application scenarios of system and interrupt priorities need to be distinguished.
b. In FreeRTOS, the larger the priority 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 4 bytes in ARM.
6.configTOTAL_HEAP_SIZE
Total Heap (Stack) Size of the System
We need to define this value based on the usage situation. It cannot be defined too small, as too small memory is prone to overflow;
It cannot be defined too large; some chips have limited RAM (some only have a few K), and if it is too large, we won’t be able to define many global variables or allocate other stack space.
7.configMAX_TASK_NAME_LEN
Maximum Length of Task Name
This is the string length of the task name defined when creating a task.
xTaskCreate(vAppTask1, “Task1“, TASK1_STACK_SIZE, NULL, TASK1_PRIORITY, NULL);
Tip: The terminator ‘\0’ is also included.
8.configUSE_16_BIT_TICKS
Whether to use 16-bit tick count value
Set to 0: then use a 32-bit tick count value, which is generally set to 0 in 32-bit processors;
Set to 1: then use a 16-bit tick count value, generally set to 1 in 8-bit or 16-bit processors.
9.configIDLE_SHOULD_YIELD
Whether to let idle tasks “yield” preemption
That is, during the execution of tasks with the same priority as the idle task, whether the idle task has the opportunity to preempt.
Set to 0: do not yield preemption;
Set to 1: yield preemption;
10.configUSE_MUTEXES
Whether to use mutexes
Set to 0: do not use
Set to 1: use
Tip: Mutexes are also called mutex semaphores, which means “locking” the resource. Their role is to achieve exclusive processing of shared resources among multiple tasks. In simple terms, at any given time, a resource is only allowed to be processed by one task, and only after processing is completed can other tasks process that resource.
For example: Task A has a high priority, and Task B has a low priority; both tasks A and B will use a serial port to send command data (i.e., it must be completed each time, and cannot be interrupted halfway).
When Task B is sending data, Task A is in a ready state (ready to interrupt Task B). Then Task B needs to use a mutex to occupy that serial port (lock, occupy that resource); after sending the command, it releases that serial port (unlock, release that resource). Once the resource is released, Task A can use that serial port (resource).
11.configUSE_RECURSIVE_MUTEXES
Whether to use recursive mutexes
Set to 0: do not use
Set to 1: use
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 the functions vQueueAddToRegistry and vQueueUnregisterQueue.
Directly to the function interface:
void vQueueAddToRegistry(QueueHandle_t xQueue, const char *pcQueueName);void vQueueUnregisterQueue(QueueHandle_t xQueue);
From the function interface, one function registers (an already created) queue name; one function unregisters the queue name;
In fact, the main purpose is to name (already created) queues for easier debugging.
Tip: 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: do not use
Set to 1: use
This configuration information is also relatively difficult to understand.
Tip: Many online explanations are: enabling/disabling 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 together with the above configuration parameter configUSE_PREEMPTION.
This configuration parameter was added in later versions; it seems that it was not available before version V7. Therefore, it is not default in the FreeRTOSConfig.h configuration file but is defined in FreeRTOS.h.
#ifndef configUSE_TIME_SLICING  #define configUSE_TIME_SLICING 1#endif

———— END ————

Essential Configurations for FreeRTOS Configuration Files

● Column “Embedded Tools

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials from the Embedded Column

Follow the public account reply “Add Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Essential Configurations for FreeRTOS Configuration Files

Essential Configurations for FreeRTOS Configuration Files

Click “Read Original” to see more shares.

Leave a Comment

×