Introduction To Free RTOS in STM32
Introduction To Free RTOS in STM32
This tutorial is the first in the series of many, and will cover the
following:-
1.) Setting up Free RTOS using CubeMX
2.) Benefit of using a RTOS. FreeRTOS Tutorials
#8 -> Software
3.) Creating tasks with or without CubeMX Timers
4.) Using priorities to sort out some common problems
CubeMX Setup
STM32
This website uses cookies to improve your experience. If you continue to use this site, you agree with ETHENRET
it. Ok
#2. UDP SERVER
1 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
After selecting the controller, the CubeMX will open the default
page for you. Now select the FREERTOS and follow the
screenshot below
STM32 ETHERNET
#3. UDP CLIENT
Next, go to the ‘tasks and queues‘ tab and here you will see a
default task, already created for you. Double click it and you can
see the following information.
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
2 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
Don’t worry about all this information. For now, you have to focus
only on the Task name, priority, and the entry function.
Now, we will create one task here, and below are the properties
of that task
Also one important thing about using RTOS is that, we can’t use
systick as the time base. So go to sys, and choose some other
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
3 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
After the code is generated, open the main.c file and it’s time to
know the importance of using RTOS.
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
4 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
Benefit of using a
RTOS
5 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
9 }
10 �� USER CODE END 5 ��
11 }
12
13 �� USER CODE BEGIN Header_Task2_init ��
14 ���
15 * @brief Function implementing the Task2 thread.
16 * @param argument: Not used
17 * @retval None
18 ��
19 �� USER CODE END Header_Task2_init ��
20 void Task2_init(void const * argument)
21 {
22 �� USER CODE BEGIN Task2_init ��
23 �� Infinite loop ��
24 for(��)
25 {
26 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
27 osDelay(1);
28 }
29 �� USER CODE END Task2_init ��
30 }
We will toggle the pin PA0 in the default task, and pin PA1 in the
Task2. This way the scheduler will schedule the time for both of
these tasks, so that they get enough time to be executed.
You can check below the oscilloscope reading, when the above
code was executed.
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
6 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
Creating a Task
1.) Define a ThreadID for the task. This variable will store the
unique ID of the task, once created. Later, all the operations will
require this ID.
1 osThreadId Task3Handle;
2.) Define the entry function for the task. This is the main
function of the task. Your program will be written inside it.
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
7 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
Remember that the tasks in the Free RTOS, are not designed to
handle any return value. So, the entry function should always
have an infinite loop, inside which, your whole program should
be written.
1 �� define thread
2 osThreadDef(Task3, Task3_init, osPriorityBelowNormal
3 ��create thread
4 Task3Handle = osThreadCreate(osThread (Task3), NULL)
Handling Priorities in
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
8 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
Free RTOS
• And similarly the third task will wait for the second one to
finish. You can see this in the video below, it’s better
explained there.
• Now the Task2 have the highest priority, than Default task,
and Task3 with the lowest.
9 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
RESULT
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
10 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
DOWNLOAD
SECTION
DOWNLOAD DONATE
Also Read:
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
11 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
STM32 Ethernet #8
FreeRTOS Tutorial UDP Client using FreeRTOS Tutorials
#3 -> How to use LWIP NETCONN #8 -> Software
Binary Semaphore (RTOS) Timers
STM32 Ethernet #7
UDP Server using
LWIP NETCONN STM32 ETHENRET STM32 ETHERNET
(RTOS) #2. UDP SERVER #3. UDP CLIENT
Subscribe Login
{} [+]
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
12 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
13 COMMENTS Newest
KomKGT
1 year ago
0 Reply
admin Author
https://www.freertos.org/FreeRTOS_Support_Forum_Archive/
April_2014/
freertos_Exact_task_stack_size_8c443f40j.html#:~:text=The%
20stack%20is%20managed%20by,n%27%20bytes%20of%20
stack%20space.
0 Reply
zengkai
2 years ago
very useful!
0 Reply
Charoon
2 years ago
0 Reply
misso
3 years ago
1 Reply
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
13 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
negin shiran
4 years ago
1 Reply
Farid
4 years ago
0 Reply
Ulhas
4 years ago
Please make single pdf file for this excellent tutorial series on
RTOS
6 Reply
noads
4 years ago
0 Reply
admin Author
Removing it
0 Reply
fraook
5 years ago
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
14 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
3 Reply
admin Author
sorry, i didn’t upload any code for it. This was a simple case.
just set everything from cube mx and run it.
2 Reply
Toan
5 years ago
1 Reply
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
15 of 16 09/06/25, 14:39
Introduction to Free RTOS in STM32 https://controllerstech.com/introduction-to-free-rtos-i...
HOME
ABOUT US
SHOP WITH US
DONATE HERE
CONTACT US
Search
© 2024 ControllersTech®
This website uses cookies to improve your experience. If you continue to use this site, you agree with it. Ok
16 of 16 09/06/25, 14:39