1 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
7 <a target="_blank" href="https://www.freertos.org/">FreeRTOS</a> is one of the market leading real-time operating systems
8 (RTOS) for embedded microcontrollers. It is professionally developed,
9 <a target="_blank" href="https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html">strictly quality controlled</a>,
11 <a target="_blank" href="https://forums.freertos.org/">supported</a>
12 <a target="_blank" href="https://www.freertos.org/FreeRTOS_Support_Forum_Archive/freertos_support_forum_archive_index.html/">(archive)</a>,
13 free to <a target="_blank" href="https://www.freertos.org/a00114.html">use in commercial products</a> without a requirement to
14 expose proprietary source code, and has
15 <a target="_blank" href="https://www.freertos.org/differences-between-officially-supported-and-contributed-FreeRTOS-code.html">no IP infringement</a>
18 <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/index.html"><b>CMSIS-RTOS v2</b></a> is a common API for real-time
19 operating systems (RTOS). It provides a standardized programming interface that is portable to many RTOS and enables software
20 components that can work across multiple RTOS systems. It supports the Armv8-M architecture, dynamic object creation, for
21 multi-core systems, and has a binary compatible interface across ABI compliant compilers.
23 Using this software pack, users can choose between a native FreeRTOS implementation or one that is adhering to the
24 CMSIS-RTOS2 API and using FreeRTOS under the hood. The CMSIS-RTOS2 API enables programmers to create portable application
25 code to be used with different RTOS kernels (for example
26 <a class="el" href="https://developer.arm.com/Tools%20and%20Software/Keil%20MDK/RTX5%20RTOS/">Keil RTX5</a>).
28 This documentation shows you:
29 - how to \ref cre_freertos_proj "create a new microcontroller project" using FreeRTOS from scratch.
30 - Various \ref examples show you the usage of FreeRTOS in native and CMSIS-RTOS2 mode.
31 - the \ref tech_data of this implementation.
38 The CMSIS-FreeRTOS implementation is provided free of charge by Arm under the <a href="LICENSE">Apache 2.0 license</a>.<br/>
39 The FreeRTOS kernel source files are released under the <a href="LICENSE.md">MIT open source license</a>.
42 ARM::CMSIS-FreeRTOS Pack
43 ------------------------
45 The <b>ARM::CMSIS-FreeRTOS</b> pack contains the following:
47 File/Directory |Content
48 :--------------------------|:---------------------------------------------------------------------------------
49 \b CMSIS/Documentation | This documentation.
50 \b CMSIS/RTOS2 | CMSIS-RTOS2 compliant implementation of FreeRTOS.
51 \b License | FreeRTOS license agreement.
52 \b Source | FreeRTOS kernel source code.
53 \b ARM.CMSIS-FreeRTOS.pdsc | Package description file in CMSIS-Pack format.
56 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
58 \page cre_freertos_proj Create a FreeRTOS project
60 You can basically choose between two option when creating a FreeRTOS project:
61 -# \ref native_freertos using the FreeRTOS API and kernel.
62 -# \ref cmsis_freertos using the CMSIS-RTOS2 API with an underlying FreeRTOS kernel.
64 \section native_freertos Create a native FreeRTOS project
66 The steps to create a microcontroller application using FreeRTOS are:
67 - Create a new project and select a microcontroller device.
68 - In the Manage Run-Time Environment window, select <b>\::Device:Startup</b>, <b>\::RTOS:CORE</b> and
69 <b>\::RTOS:Config</b> in the \b FreeRTOS variant and an applicable <b>\::RTOS:Heap</b> scheme (for more
70 information on the heap schemes, visit the FreeRTOS documentation):
72 \image html manage_rte_freertos_native.png
75 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
76 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
77 \b %FreeRTOSConfig.h, the source code files, as well as the system and startup files:
79 \image html project_window_freertos_native.png
81 \subsection native_freertos_config Configure FreeRTOS
83 When you have created the native FreeRTOS project, you can configure the real-time operating system using the
84 \b FreeRTOSConfig.h file. Please refer to the
85 <a href="https://www.freertos.org/a00110.html" target="_blank">FreeRTOS documentation</a> for more information on the specific
88 \image html freertos_config_h_native.png
91 \subsection native_freertos_config_prio Interrupt priority configuration
93 FreeRTOS implements critical sections using the
94 <a href="https://developer.arm.com/documentation/dui0552/a/the-cortex-m3-processor/programmers-model/core-registers?lang=en" target="_blank">BASEPRI</a>
95 register (available in Armv7-M and Armv8-M architecture based devices) which masks only a subset of interrupts. This is
96 configured via the \c configMAX_SYSCALL_INTERRUPT_PRIORITY setting. Therefore, it is needed to properly configure this
97 setting. It is also needed to set appropriate interrupt priorities for interrupt service routines (ISR) that use RTOS
98 functions. This can especially impact drivers which typically use peripheral interrupts. Normally, these use the RTOS
99 directly or indirectly through registered callbacks.
101 Arm Cortex-M cores store interrupt priority values in the most significant bits of the interrupt priority registers which
102 can have a maximum of eight bits. Many implementations offer only three priority bits. These three bits are shifted up to be
103 bits five, six and seven respectively.
104 \c configMAX_SYSCALL_INTERRUPT_PRIORITY must not be 0 and can be xxx00000. This results in the following table:
106 | configMAX_SYSCALL_INTERRUPT_PRIORITY | Upper three bits | Priority |
107 |:---------------------------------------:|:----------------:|:-----------:|
108 | 32 | 001 | 1 (Highest) |
114 | 224 | 111 | 7 (Lowest) |
118 If you set \c configMAX_SYSCALL_INTERRUPT_PRIORITY to 32, then the priority of an interrupt service routine that uses RTOS
119 functions must then be higher or equal to 1. This ensures that this interrupt will be masked during critical a section.
121 A WiFi driver using the SPI interface registers a callback to SPI which is executed in an interrupt context. The callback
122 function in the WiFi driver uses RTOS functions. Therefore, the SPI interrupt priority must be set to a value equal or
123 higher to the FreeRTOS preempt priority, for example 1.
125 \note For a detailed description of how FreeRTOS is using Cortex-M code registers, refer to
126 <a href="https://www.freertos.org/RTOS-Cortex-M3-M4.html" target="_blank">Running the RTOS on a ARM Cortex-M Core</a>.
129 \subsection native_freertos_er Add Event Recorder Visibility
130 - To use the Event Recorder together with FreeRTOS, add the software component <b>\::Compiler:Event Recorder</b> to your project.
131 - Open \ref native_freertos_config "FreeRTOSConfig.h" and
132 - verify the header file \b freertos_evr.h is included
133 - add Event Recorder configuration definitions (see \ref cmsis_freertos_evr_config)
134 - Call <b>EvrFreeRTOSSetup()</b> in your application code (ideally in \c main()).
135 - If you are using simulation mode, add an initialization file with the following content:
137 MAP 0xE0001000, 0xE0001007 READ WRITE
138 signal void DWT_CYCCNT (void) {
141 _WWORD(0xE0001004, states);
146 - Build the application code and download it to the debug hardware or run it in simulation.
148 Once the target application generates event information, it can be viewed in the µVision debugger using the <b>Event Recorder</b>.
151 \section cmsis_freertos Create a CMSIS-FreeRTOS project
153 The steps to create a microcontroller application using CMSIS-FreeRTOS are:
154 - Create a new project and select a microcontroller device.
155 - In the Manage Run-Time Environment window, select <b>\::Device:Startup</b>, <b>\::CMSIS::RTOS2 (API)\::FreeRTOS</b>,
156 <b>\::RTOS:CORE</b> in the \b FreeRTOS variant, <b>\::RTOS:Config</b> in the \b CMSIS \b RTOS2 variant,
157 <b>\::RTOS:Timers</b>, <b>\::RTOS:Event Groups</b>, and an applicable <b>\::RTOS:Heap</b>
158 scheme (for more information on the heap schemes, visit the FreeRTOS documentation):
160 \image html manage_rte_freertos_rtos2.png
163 - If the <b>Validation Output</b> requires other components to be present, try to use the \b Resolve button.
164 - Click \b OK. In the \b Project window, you will see the files that have been automatically added to you project, such as
165 \b %FreeRTOSConfig.h, the source code files, as well as the system and startup files:
167 \image html project_window_freertos_rtos2.png
170 \subsection cmsis_freertos_config Configure CMSIS-FreeRTOS
172 When you have created the CMSIS-FreeRTOS project, you can configure the real-time operating system using the
173 \b FreeRTOSConfig.h file. It can be opened using the Configuration Wizard view:
175 \image html freertos_config_h_cmsis_rtos.png
177 The following main settings are available:
179 Name | \#define | Description |
180 -------------------------------|--------------------------------------|-----------------------------------------------------------------------|
181 Minimal stack size [words] | configMINIMAL_STACK_SIZE | Stack for idle task and default task stack in words. |
182 Total heap size [bytes] | configTOTAL_HEAP_SIZE | Heap memory size in bytes. |
183 Kernel tick frequency [Hz] | configTICK_RATE_HZ | Kernel tick rate in Hz. |
184 Timer task stack depth [words] | configTIMER_TASK_STACK_DEPTH | Stack for timer task in words. |
185 Timer task priority | configTIMER_TASK_PRIORITY | Timer task priority. |
186 Timer queue length | configTIMER_QUEUE_LENGTH | Timer command queue length. |
187 Preemption interrupt priority | configMAX_SYSCALL_INTERRUPT_PRIORITY | Maximum priority of interrupts that are safe to call FreeRTOS API. |
188 Use time slicing | configUSE_TIME_SLICING | Enable setting to use time slicing. |
189 Use tickless idle | configUSE_TICKLESS_IDLE | Enable low power tickless mode that stops tick interrupt when idle. |
190 Idle should yield | configIDLE_SHOULD_YIELD | Control Yield behavior of the idle task. |
191 Check for stack overflow | configCHECK_FOR_STACK_OVERFLOW | Enable or disable stack overflow checking. |
192 Use idle hook | configUSE_IDLE_HOOK | Enable callback function call on each idle task iteration. |
193 Use tick hook | configUSE_TICK_HOOK | Enable callback function call during each tick interrupt. |
194 Use daemon task startup hook | configUSE_DAEMON_TASK_STARTUP_HOOK | Enable callback function call when timer service starts. |
195 Use malloc failed hook | configUSE_MALLOC_FAILED_HOOK | Enable callback function call when out of dynamic memory. |
196 Queue registry size | configQUEUE_REGISTRY_SIZE | Define maximum number of queue objects registered for debug purposes. |
198 \note Refer to \ref native_freertos_config_prio for more information on the usage of \c configMAX_SYSCALL_INTERRUPT_PRIORITY.
200 <b> Event Recorder Configuration </b>
202 The following settings are available (see \ref cmsis_freertos_evr_config for details):
204 Name | \#define | Description |
205 -------------------------------|--------------------------------------|-----------------------------------------------------------------------------------------|
206 Initialize Event Recorder | configEVR_INITIALIZE | Initialize Event Recorder before FreeRTOS kernel start. |
207 Setup recording level filter | configEVR_SETUP_LEVEL | Enable configuration of FreeRTOS events recording level. |
208 Task functions | configEVR_LEVEL_TASKS | Define event recording level bitmask for events generated from Tasks functions. |
209 Queue functions | configEVR_LEVEL_QUEUE | Define event recording level bitmask for events generated from Queue functions. |
210 Timer functions | configEVR_LEVEL_TIMERS | Define event recording level bitmask for events generated from Timer functions. |
211 Event Groups functions | configEVR_LEVEL_EVENTGROUPS | Define event recording level bitmask for events generated from Event Groups functions. |
212 Heap functions | configEVR_LEVEL_HEAP | Define event recording level bitmask for events generated from Heap functions. |
213 Stream Buffer functions | configEVR_LEVEL_STREAMBUFFER | Define event recording level bitmask for events generated from Stream Buffer functions. |
215 <b> Memory Allocation Configuration </b>
217 The following settings are available:
219 Name | \#define | Description |
220 ---------------------------------------|--------------------------------------|------------------------------------------------------------------------------------|
221 Support static memory allocation | configSUPPORT_STATIC_ALLOCATION | Enable or disable support for static memory allocation. |
222 Support dynamic memory allocation | configSUPPORT_DYNAMIC_ALLOCATION | Enable or disable support for dynamic memory allocation. |
223 Use kernel provided static memory | configKERNEL_PROVIDED_STATIC_MEMORY | When enabled, FreeRTOS kernel provides static memory for Idle and Timer tasks. |
224 Use application allocated heap | configAPPLICATION_ALLOCATED_HEAP | When enabled, application must provide heap buffer externally. |
225 Use separate heap for stack allocation | configSTACK_ALLOCATION_FROM_SEPARATE_HEAP | Enable or disable stack allocation for any task from a separate heap. |
226 Use heap protector | configENABLE_HEAP_PROTECTOR | Enable or disable bounds checking and obfuscation to heap block pointers. |
228 <b> Port Specific Configuration </b>
230 The following settings are available:
232 Name | \#define | Description |
233 ----------------------------------|---------------------------------|------------------------------------------------------------------------------------|
234 Use Floating Point Unit | configENABLE_FPU | Enable or disable support for FPU when switching execution context. |
235 Use M-Profile Vector Extension | configENABLE_MVE | Enable or disable support for MVE when switching execution context. |
236 Use Memory Protection Unit | configENABLE_MPU | Enable or disable support for MPU on ARMv8-M MPU enabled ports. |
237 Use TrustZone Secure Side Only | configRUN_FREERTOS_SECURE_ONLY | Enable this setting when FreeRTOS runs on the Secure side only. |
238 Use TrustZone Security Extension | configENABLE_TRUSTZONE | Enable TrustZone when FreeRTOS runs on the Non-Secure side and calls functions from the Secure side.|
239 Minimal secure stack size [words] | configMINIMAL_SECURE_STACK_SIZE | Stack for idle task Secure side context in words. |
241 <b> Interrupt Controller Configuration </b>
243 \note Settings related to interrupt controller are relevant only on ARMv7-A ports where it is necessary to configure Arm Generic Interrupt Controller (GIC).
245 The following settings are available:
247 Name | \#define | Description |
248 ------------------------------------------|-------------------------------------------------|---------------------------------------------------------------|
249 Interrupt controller base address | configINTERRUPT_CONTROLLER_BASE_ADDRESS | Sets the base address of the interrupt controller peripheral. |
250 Interrupt controller CPU interface offset | configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET | Sets the offset from interrupt controller base address at which the CPU interface starts. |
251 Interrupt controller unique priorities | configUNIQUE_INTERRUPT_PRIORITIES | Sets the number of unique priorities that can be specified in the interrupt controller peripheral. |
253 <b> Symmetric Multiprocessing Configuration </b>
255 \note Symmetric Multiprocessing Configuration (SMP) settings are only relevant if FreeRTOS port implementation supports SMP.
257 The following settings are available:
259 Name | \#define | Description |
260 ----------------------------|-----------------------------|------------------------------------------------------------------|
261 Number of processor cores | configNUMBER_OF_CORES | Sets the number of available processor cores. |
262 Use processor core affinity | configUSE_CORE_AFFINITY | Enables the control for task to run on specific processor cores. |
263 Use passive idle hook | configUSE_PASSIVE_IDLE_HOOK | Enable callback function call on each idle task iteration. |
266 \subsection cmsis_freertos_er Add Event Recorder Visibility
267 - To use the Event Recorder together with FreeRTOS, add the software component <b>\::Compiler:Event Recorder</b> to your project.
268 - Open \ref native_freertos_config "FreeRTOSConfig.h" and
269 - verify the header file \b freertos_evr.h is included
270 - modify Event Recorder configuration definitions (see \ref cmsis_freertos_evr_config) to change default configuration
271 - Call <b>osKernelInitialize()</b> in your application code (ideally in \c main()) to setup Event Recorder according to configuration settings.
272 - If you are using simulation mode, add an initialization file with the following content:
274 MAP 0xE0001000, 0xE0001007 READ WRITE
275 signal void DWT_CYCCNT (void) {
278 _WWORD(0xE0001004, states);
283 - Build the application code and download it to the debug hardware or run it in simulation.
285 Once the target application generates event information, it can be viewed in the µVision debugger using the <b>Event Recorder.</b>
288 \section freertos_interfaces Create a mixed-interface project
290 Using CMSIS-RTOS2 API and native FreeRTOS API simultaneously is possible and some projects do require using the native FreeRTOS API and the CMSIS-RTOS2 API at the same time.
291 Such project should be \ref cmsis_freertos "created as CMSIS-FreeRTOS project".
293 Depending on the application requirements, FreeRTOS kernel can be started either by using FreeRTOS native API or by using CMSIS-RTOS2 API.
295 \subsection freertos_interface_rtos2 Start the kernel using CMSIS-RTOS2 API
299 Application thread: Initialize and start the Application
301 void app_main (void *argument) {
310 Main function: Initialize and start the kernel
313 SystemCoreClockUpdate();
315 // Initialize CMSIS-RTOS2
316 osKernelInitialize();
318 // Create application main thread
319 osThreadNew(app_main, NULL, NULL);
321 // Start the kernel and execute the first thread
330 After the kernel is started using CMSIS-RTOS2 API, FreeRTOS native API can be used with the following restrictions:
331 - vTaskStartScheduler must not be called
334 \subsection freertos_interface_native Start the kernel using native API
338 Application main thread: Initialize and start the application
340 void app_main (void *argument) {
349 Main function: Initialize and start the kernel
352 SystemCoreClockUpdate();
354 // Setup the Event Recorder (optionally)
357 // Create application main thread
358 xTaskCreate (app_main, "app_main", 64, NULL, tskIDLE_PRIORITY+1, NULL);
360 // Start the kernel and execute the first thread
361 vTaskStartScheduler();
369 After the kernel is started using FreeRTOS native API, CMSIS-RTOS2 API can be used without restrictions.
371 \section cmsis_freertos_evr_config Configure Event Recorder
373 This section describes the configuration settings for the <a href="https://arm-software.github.io/CMSIS-View/latest/evr.html" target="_blank">Event Recorder</a>
374 annotations. For more information refer to section \ref native_freertos_er "Add Event Recorder Visibility to native FreeRTOS project" or
375 \ref cmsis_freertos_er "Add Event Recorder Visibility to CMSIS-FreeRTOS project".
377 Use below definitions to configure Event Recorder initialization and recording level filter setup.
380 #define configEVR_INITIALIZE
383 Value | Description |
384 -------|---------------------------------------|
385 0 | Disable Event Recorder initialization |
386 1 | Enable Event Recorder initialization |
388 Definition configEVR_INITIALIZE enables Event Recorder initialization during execution of function \ref EvrFreeRTOSSetup. Default value is \token{1}.
391 #define configEVR_SETUP_LEVEL
394 Value | Description |
395 -------|---------------------------------------|
396 0 | Disable recording level filter setup |
397 1 | Enable recording level filter setup |
399 Definition configEVR_SETUP_LEVEL enables setup of recording level filter for events generated by FreeRTOS. Recording level is configured during execution of function \ref EvrFreeRTOSSetup. Default value is \token{1}.
402 #define configEVR_LEVEL_TASKS
403 #define configEVR_LEVEL_QUEUE
404 #define configEVR_LEVEL_TIMERS
405 #define configEVR_LEVEL_EVENTGROUPS
406 #define configEVR_LEVEL_HEAP
407 #define configEVR_LEVEL_STREAMBUFFER
410 Value | Description |
411 -------|--------------------------------------------------------|
412 0x00 | Disable event generation |
413 0x01 | Enable generation of error events |
414 0x05 | Enable generation of error and operational events |
415 0x07 | Enable generation of error, API and operational events |
416 0x0F | Enable generation of all events |
418 Definitions configEVR_LEVEL_x set the recording level bitmask for events generated by each function group. They are taken into account only when recording level filter setup is enabled. Default value is \token{0x05}.
421 \section dbg_cmsisfreertos Debug a CMSIS-FreeRTOS project
423 \note The following only applies when used with <a href="https://developer.arm.com/Tools%20and%20Software/Keil%20MDK" target="_blank">Arm Keil MDK</a>. If
424 you are using a different toolchain, please consult its user's manual.
426 Apart from the debug capabilities that \ref cmsis_freertos_evr_config "Event Recorder" offers, Keil MDK also supports thread
427 aware breakpoints, just like for the standard CMSIS-RTOS.
432 BS FuncN1, 1, "break = (CURR_TID == tid_phaseA) ? 1 : 0"
433 BS FuncN1, 1, "break = (CURR_TID == tid_phaseA || CURR_TID == tid_phaseD) ? 1 : 0"
434 BS \\Blinky\Blinky.c\FuncN1\179, 1, "break = (CURR_TID == tid_phaseA || CURR_TID == tid_phaseD) ? 1 : 0"
438 - For more information on conditional breakpoints in Keil MDK, consult the
439 <a href="https://developer.arm.com/documentation/101407/latest/Debugging/Debug-Windows-and-Dialogs/Breakpoints-Window" target="_blank">user's manual</a>.
440 - Enabling <a href="https://developer.arm.com/documentation/101407/latest/User-Interface/View-Menu" target="_blank">Periodic Window Update</a> is
441 required to capture register values for active running threads while executing. When turned off, only the current FreeRTOS
442 thread can be unwound after execution has been stopped.
446 - You cannot specify individual breakpoints on the same address. The following is not possible:
448 BS ThCallee, 1, "break = (CURR_TID==tid_phaseA) ? 1 : 0"
449 BS ThCallee, 1, "break = (CURR_TID==tid_phaseD) ? 1 : 0"
453 BS ThCallee, 1, "break= (CURR_TID==tid_phaseA || CURR_TID==tid_phaseD) ? 1 : 0"
456 - If you don't want to use
457 <a href="https://developer.arm.com/documentation/101407/latest/User-Interface/View-Menu" target="_blank">Periodic Window Update</a>, obtain the
458 thread and unwind information by adding a function that gets called from each thread of interest:
460 _attribute_((noinline)) int FuncN1 (int n1) {
464 Then, specify a thread aware breakpoint using an "invalid" thread ID:
466 BS FuncN1, 1, "break = (CURR_TID == tid_phaseA + 1) ? 1 : 0"
468 <tt>'tid_phaseA'</tt> would be valid, <tt>'tid_phaseA + 1'</tt> is not but will still capture the most recent registers and
469 store them to the actual thread context each time a thread aware breakpoint is checked.
471 - Function inlining typically causes thread aware breakpoints to fail. To avoid this, prepend the <tt>'noinline'</tt>
472 attribute to the function that is used to stop when the current FreeRTOS thread id matches:
474 _attribute_((noinline)) int FuncN1 (int n1) {
478 This helps to make thread aware breakpoints far less dependent on the compiler optimization level.
480 - Thread aware breakpoints should be setup using a
481 <a href="https://developer.arm.com/documentation/101407/latest/Debugging/Debug-Scripting" target="_blank">debug script</a>. Reason being
482 that thread aware breakpoints are of a 'hybrid' type, that is a combined address and condition expression that works best
483 when run from a debug script.
487 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
489 \page examples Example projects
491 This pack contains two example projects:
493 - \ref example_trustzone
495 The first example shows how to configure a simple application using FreeRTOS with CMSIS-RTOS2, whereas the second example
496 shows how to use the FreeRTOS with CMSIS-RTOS2 in an application that utilizes TrustZone secure/non-secure execution.
498 Provided examples use the
499 [CMSIS Solution Project File Format](https://github.com/Open-CMSIS-Pack/cmsis-toolbox/blob/main/docs/YML-Input-Format.md)
500 and can be build for multiple Cortex-M targets
501 - using [CMSIS Toolbox](https://github.com/Open-CMSIS-Pack/cmsis-toolbox/blob/main/docs/README.md#cmsis-toolbox)
502 either from the command line or
503 - from Visual Studio Code by using
504 [Arm Keil Studio Cloud extensions](https://developer.arm.com/documentation/108029/0000/?lang=en).
506 The \b Examples solution defines projects and build information for each project.
509 \section build_run Build and Run
511 The \b Examples solution supports only "Debug" Build-Type which is optimized for debugging. It disables
512 compiler optimization and retains all debug related information. By default, Arm Compiler 6 is used to
515 \subsection build_target_types Targets
517 Each example can be built for multiple target processors. The below table lists supported target processors
518 together with the corresponding context target-types and model executable that shall be used for running
519 the application image.
521 | Target processor | Target-Type | Model Executable |
522 |:-----------------|:------------|:-----------------------|
523 | Cortex-M0 | CM0 | FVP_MPS2_Cortex-M0 |
524 | Cortex-M0+ | CM0plus | FVP_MPS2_Cortex-M0plus |
525 | Cortex-M3 | CM3 | FVP_MPS2_Cortex-M3 |
526 | Cortex-M4 | CM4 | FVP_MPS2_Cortex-M4 |
527 | Cortex-M7 | CM7 | FVP_MPS2_Cortex-M7 |
528 | Cortex-M23 | CM23 | FVP_MPS2_Cortex-M23 |
529 | Cortex-M23 | CM23_noTZ | FVP_MPS2_Cortex-M23 |
530 | Cortex-M33 | CM33 | FVP_MPS2_Cortex-M33 |
531 | Cortex-M33 | CM33_noTZ | FVP_MPS2_Cortex-M33 |
532 | Cortex-M55 | CM55 | FVP_Corstone_SSE-300 |
533 | Cortex-M55 | CM55_noTZ | FVP_Corstone_SSE-300 |
534 | Cortex-M85 | CM85 | FVP_Corstone_SSE-310 |
535 | Cortex-M85 | CM85_noTZ | FVP_Corstone_SSE-310 |
537 \subsection build_vscode Build in VS Code using Arm Keil Studio Pack extensions
539 - See [Arm Keil Studio Visual Studio Code Extensions User Guide](https://developer.arm.com/documentation/108029/0000/?lang=en)
540 for more information about using the Keil Studio extensions.
541 - Search for [Arm Keil Studio Pack](https://marketplace.visualstudio.com/items?itemName=Arm.keil-studio-pack)
542 in the Visual Studio Marketplace to download the extensions.
544 To build a project using Keil Studio extensions open CMSIS view, open "Manage CMSIS Solution" view and select
545 "Active Context" and "Active Projects". Build Type is automatically selected since there is only
548 Once the context and projects are selected one can build them by selecting "Build" in CMSIS view.
550 \subsection build_cmdline Build via command line
552 - See [CMSIS-Toolbox documentation](https://github.com/Open-CMSIS-Pack/cmsis-toolbox/blob/main/docs/README.md)
553 to learn more about CMSIS Solution project build and management tools.
555 To build the project via command line one can use the following command syntax:
558 cbuild Examples.csolution.yml --context <project-name>.<build-type>+<target-type>
561 To list the available contexts execute the following command:
564 cbuild list contexts Examples.csolution.yml
567 \subsection example_exec Execute on Virtual Hardware Target
569 [Arm Virtual Hardware Target](https://www.arm.com/products/development-tools/simulation/virtual-hardware)
570 simulation models are used to execute the example application images.
572 To execute application image (axf or elf) on an simulation model use the following command syntax:
574 <model-executable> -f ./Target/<target_type>/fvp_config.txt -a ./out/<project>/<project>.axf
578 \section example_hello Hello World
580 The <b>Hello World</b> application can be used as a starting point when developing new application. Using it, one can verify
581 initial system setup and configuration.
583 The application is simple and shows how to use CMSIS-RTOS2:
584 - how to initialize and start the RTOS kernel
585 - how to create a new thread
586 - how to retarget stdout
588 <b>Build via command line</b>
590 The following cbuild command may be used to build Hello World example project for Cortex-M3:
592 cbuild Examples.csolution.yml --context Hello.Debug+CM3 --update-rte
595 <b>Execute via command line</b>
597 To execute simulation model and run Hello World project executable for Cortex-M3 use the following command:
599 FVP_MPS2_Cortex-M3 -f ./Target/CM3/fvp_config.txt -a ./out/Hello/Hello.axf
602 When executed, application outputs the following to the serial terminal:
604 \image html hello_out.png
605 (Press Ctrl + C to stop the simulation model.)
608 \section example_trustzone TrustZone
610 The <b>TrustZone</b> application explains how to setup projects for booting and execution from TrustZone secure to non-secure
611 domain and vice versa.
613 The application shows:
614 - how to boot from the secure domain and switch the execution to the non-secure domain
615 - how to create the interface functions between secure and non-secure domain
616 - how to use the secure/non-secure interface functions
618 <b>Build via command line</b>
620 TrustZone example must always be build in two steps:
622 1. Build secure side project for Cortex-M55
624 cbuild Examples.csolution.yml --context TZ_Secure.Debug+CM55 --update-rte
627 2. Build non-secure side project for Cortex-M55
629 cbuild Examples.csolution.yml --context TZ_NonSecure.Debug+CM55 --update-rte
632 <b>Execute via command line</b>
634 To execute simulation model and run TrustZone project executable for Cortex-M55 use the following command:
636 FVP_Corstone_SSE-300 -f ./Target/CM55/fvp_config.txt -a ./out/TZ_NonSecure/TZ_NonSecure.axf -a ./out/TZ_Secure/TZ_Secure.axf
639 When executed, application outputs the following to the serial terminal:
641 \image html trustzone_out.png
642 (Press Ctrl + C to stop the simulation model.)
645 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
647 \page tech_data Technical data and limitations
649 This lists the technical data of CMSIS-FreeRTOS.
652 \section td_limitations Limitations
654 The following list briefly describes the limitations and unsupported features of the CMSIS-RTOS2 wrapper for FreeRTOS:
655 - Static memory allocation will only work if \a all memory (from attributes structure) is provided statically. In order to
656 allocate object memory statically, you need to:
657 - provide the memory for control blocks and stack in the \c osThreadAttr_t structure for threads.
658 - provide the memory for control blocks and message data in the \c osMessageQueueAttr_t structure for memory queues.
659 - provide the memory for control blocks for other objects in the object's attributes structure.
660 - Each timer object requires additional 8 bytes of memory:
661 - to allocate all memory statically, provide the memory for control block of size (sizeof(StaticTimer_t) + 8 bytes)
662 - otherwise, additional 8 bytes of dynamic memory will be used
663 - \c osKernelSuspend and \c osKernelResume are not supported.
664 - \c osThreadDetach, \c osThreadJoin() and attribute \c osThreadJoinable are not supported (\c osThreadNew returns NULL when
665 osThreadJoinable attribute is specified).
666 - \c osThreadGetStackSize is not implemented.
667 - Event flags are limited to 24 bits.
668 - \c osEventFlagsGetName is not implemented.
669 - \c osEventFlagsWait cannot be called from an ISR.
670 - Priority inherit protocol is used as default mutex behavior (\c osMutexNew creates priority inherit mutex object by default
671 and ignores \c osMutexPrioInherit attribute when specified).
672 - Robust mutex objects are not supported (\c osMutexNew returns NULL when \c osMutexRobust attribute is specified).
673 - \c osMutexGetName is not implemented and always returns NULL.
674 - \c osSemaphoreGetName is not implemented and always returns NULL.
675 - \c osMessageQueueGetName is not implemented and always returns NULL.
676 - \c osMessageQueuePut and \c osMessageQueueGet always ignore message priority.
677 - <tt>Process Isolation (Functional Safety)</tt> functions are not implemented.
679 \section td_validation Validation suite results
682 <a target="_blank" href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/rtosValidation.html">CMSIS-RTOS2 validation suite</a> that can
683 be used to test a real-time operating system for compliance to the standard. The test suite has been executed successfully on the
684 CMSIS-FreeRTOS implementation (<a href="cmsis_rtos2_validation.txt">see results</a>).
686 The following table explains the exceptions:
688 <table class="doxtable" summary="Validation Exceptions">
696 <td>TC_osKernelGetState_2</td>
697 <td>not executed</td>
698 <td>unsupported feature</td>
700 Test attempts to call \c osKernelGetState after a \c osKernelSuspend call. osKernelSuspend is not implemented.
704 <td>TC_osKernelLock_2</td>
705 <td>not executed</td>
706 <td>unsupported feature</td>
708 Test attempts to call \c osKernelLock after a \c osKernelSuspend call. \c osKernelSuspend is not implemented.
712 <td>TC_osKernelUnlock_2</td>
713 <td>not executed</td>
714 <td>unsupported feature</td>
716 Test attempts to call \c osKernelUnlock after a \c osKernelSuspend call. \c osKernelSuspend is not implemented.
720 <td>TC_osKernelSuspend_1</td>
721 <td>not executed</td>
722 <td>unsupported feature</td>
724 Test validates \c osKernelSuspend which is not implemented.
728 <td>TC_osKernelResume_1</td>
729 <td>not executed</td>
730 <td>unsupported feature</td>
732 Test validates \c osKernelResume which is not implemented.
736 <td>TC_osThreadNew_3</td>
737 <td>not executed</td>
738 <td>unsupported feature</td>
740 Test attempts to create joinable thread using \c osThreadJoinable attribute. FreeRTOS does not support joinable threads.
744 <td>TC_osThreadGetName_1</td>
748 Test attempt to retrieve a name on an unnamed thread. An empty string is returned instead of NULL pointer.
752 <td>TC_osThreadGetState_3</td>
753 <td>not executed</td>
754 <td>unsupported feature</td>
756 Test attempts to retrieve a state of a terminated joinable thread. FreeRTOS does not support joinable threads.
760 <td>TC_osThreadDetach_1</td>
761 <td>not executed</td>
762 <td>unsupported feature</td>
764 Test validates \c osThreadDetach which is not implemented.
768 <td>TC_osThreadDetach_2</td>
769 <td>not executed</td>
770 <td>unsupported feature</td>
772 Test validates \c osThreadDetach which is not implemented.
776 <td>TC_osThreadJoin_1</td>
777 <td>not executed</td>
778 <td>unsupported feature</td>
780 Test validates \c osThreadJoin which is not implemented.
784 <td>TC_osThreadJoin_2</td>
785 <td>not executed</td>
786 <td>unsupported feature</td>
788 Test validates \c osThreadJoin which is not implemented.
792 <td>TC_osThreadJoin_3</td>
793 <td>not executed</td>
794 <td>unsupported feature</td>
796 Test validates \c osThreadJoin which is not implemented.
800 <td>TC_osThreadGetStackSize_1</td>
801 <td>not executed</td>
802 <td>unsupported feature</td>
804 Test validates \c osThreadGetStackSize which is not implemented.
808 <td>TC_ThreadReturn</td>
809 <td>not executed</td>
810 <td>unsupported feature</td>
812 Test attempts to terminate a thread by just returning from a thread. FreeRTOS threads may not return.
816 <td>TC_osEventFlagsSet_1</td>
820 Test attempts to set event flags by calling \c osEventFlagsSet multiple times without leaving ISR handler.<br>
821 To process ISR requests, FreeRTOS uses timer deamon which wakes-up after ISR execution.
825 <td>TC_osEventFlagsClear_1</td>
829 Test attempts to clear event flags by calling \c osEventFlagsClear multiple times without leaving ISR handler.<br>
830 To process ISR requests, FreeRTOS uses timer deamon which wakes-up after ISR execution.
834 <td>TC_osEventFlagsWait_1</td>
836 <td>unsupported feature</td>
838 Test attempts to wait for flags from ISR with zero timeout (try-semantic). FreeRTOS does not support such operation.
842 <td>TC_osEventFlagsGetName_1</td>
843 <td>not executed</td>
844 <td>unsupported feature</td>
846 Test validates \c osEventFlagsGetName which is not implemented.
850 <td>TC_osMutexNew_4</td>
851 <td>not executed</td>
852 <td>unsupported feature</td>
854 Test attempts to create a robust mutex. FreeRTOS implementation does not support robust mutexes.
858 <td>TC_osMutexGetName_1</td>
859 <td>not executed</td>
860 <td>unsupported feature</td>
862 Test validates \c osMutexGetName which is not implemented.
866 <td>TC_MutexRobust</td>
867 <td>not executed</td>
868 <td>unsupported feature</td>
870 Test attempts to validate robust mutex behavior. FreeRTOS implementation does not support robust mutexes.
874 <td>TC_MutexOwnership</td>
875 <td>not executed</td>
876 <td>unsupported feature</td>
878 Test attempts to release a mutex from a thread which is not the mutex owner.<br>
879 FreeRTOS implementation does not verify ownership on mutex release.
883 <td>TC_osSemaphoreGetName_1</td>
884 <td>not executed</td>
885 <td>unsupported feature</td>
887 Test validates \c osSemaphoreGetName which is not implemented.
891 <td>TC_osMessageQueueGetName_1</td>
892 <td>not executed</td>
893 <td>unsupported feature</td>
895 Test validates \c osMessageQueueGetName which is not implemented.
900 \section td_troubleshooting Troubleshooting
902 Users looking for help shall check <a href="https://www.freertos.org/Why-FreeRTOS/FAQs">subsection of the full FreeRTOS FAQ</a>.
903 It contains many useful information that also apply when using FreeRTOS in context of CMSIS-FreeRTOS.
905 Additionally, please take a look at the following:
909 <b>Interrupts are disabled when main is called or before the kernel is started</b>
911 Before the FreeRTOS kernel is started, threads (i.e. tasks) may be created together with other objects like
912 mutexes, semaphores, message queues etc. When functions like xTaskCreate, xSemaphoreCreateMutex, xQueueCreate and
913 others get called, they prevent interrupt handlers from calling FreeRTOS API functions in order to keep FreeRTOS kernel
914 variables and state machine consistent
915 (see also here <a href="https://www.freertos.org/Why-FreeRTOS/FAQs">Interrupts are not executing</a>).
917 In cases when interrupts may be executed after object creation and before the FreeRTOS kernel is started they can be re-enabled:
919 portENABLE_INTERRUPTS();
921 Make sure that the interrupts you execute in such case do not call FreeRTOS API.
928 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
930 \page functionOverview Function Overview
933 \section rtos_api2 CMSIS-RTOS2 API
935 Overview of all CMSIS-RTOS C API v2 functions that are implemented in CMSIS-FreeRTOS.
937 Kernel Information and Control
938 ------------------------------
939 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__KernelCtrl.html">API reference</a> for details about Kernel Information and Control functions.
940 - \b osKernelInitialize: supported
941 - \b osKernelGetInfo: supported
942 - \b osKernelGetState: supported
943 - \b osKernelStart: supported
944 - \b osKernelLock: supported
945 - \b osKernelUnlock: supported
946 - \b osKernelRestoreLock: supported
947 - \b osKernelSuspend: \token{not implemented}
948 - \b osKernelResume: \token{not implemented}
949 - \b osKernelProtect: \token{not implemented}
950 - \b osKernelDestroyClass: \token{not implemented}
951 - \b osKernelGetTickCount: supported
952 - \b osKernelGetTickFreq: supported
953 - \b osKernelGetSysTimerCount: supported
954 - \b osKernelGetSysTimerFreq: supported
958 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__ThreadMgmt.html">API reference</a> for details about Thread Management functions.
959 - \b osThreadNew: supported
960 - \b osThreadGetName: supported
961 - \b osThreadGetClass: \token{not implemented}
962 - \b osThreadGetZone: \token{not implemented}
963 - \b osThreadGetId: supported
964 - \b osThreadGetState: supported
965 - \b osThreadGetStackSize: \token{not implemented}
966 - \b osThreadGetStackSpace: supported
967 - \b osThreadSetPriority: supported
968 - \b osThreadGetPriority: supported
969 - \b osThreadYield: supported
970 - \b osThreadSuspend: supported
971 - \b osThreadResume: supported
972 - \b osThreadDetach: \token{not implemented}
973 - \b osThreadJoin: \token{not implemented}
974 - \b osThreadExit: supported
975 - \b osThreadTerminate: supported
976 - \b osThreadFeedWatchdog: \token{not implemented}
977 - \b osThreadProtectPrivileged: \token{not implemented}
978 - \b osThreadSuspendClass: \token{not implemented}
979 - \b osThreadResumeClass: \token{not implemented}
980 - \b osThreadTerminateZone: \token{not implemented}
981 - \b osThreadGetCount: supported
982 - \b osThreadEnumerate: supported
986 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__ThreadFlagsMgmt.html">API reference</a> for details about Thread Flags functions.
987 - \b osThreadFlagsSet: supported
988 - \b osThreadFlagsClear: supported
989 - \b osThreadFlagsGet: supported
990 - \b osThreadFlagsWait: supported
992 Generic Wait Functions
993 ----------------------
994 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__Wait.html">API reference</a> for details about Generic Wait functions.
995 - \b osDelay: supported
996 - \b osDelayUntil: supported
1000 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__TimerMgmt.html">API reference</a> for details about Timer Management functions.</a>
1001 - \b osTimerNew: supported
1002 - \b osTimerGetName: supported
1003 - \b osTimerStart: supported
1004 - \b osTimerStop: supported
1005 - \b osTimerIsRunning: supported
1006 - \b osTimerDelete: supported
1010 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__EventFlags.html">API reference</a> for details about Event Flags functions.
1011 All event flags are limited to 24 bits.
1012 - \b osEventFlagsNew: supported
1013 - \b osEventFlagsGetName: \token{not implemented}
1014 - \b osEventFlagsSet: supported
1015 - \b osEventFlagsClear: supported
1016 - \b osEventFlagsGet: supported
1017 - \b osEventFlagsWait: cannot be called from an ISR.
1018 - \b osEventFlagsDelete: supported
1022 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__MutexMgmt.html">API reference</a> for details about Mutex Management functions.\n
1023 Priority inherit protocol is used as default mutex behavior (osMutexNew creates priority inherit mutex object by default
1024 and ignores osMutexPrioInherit attribute when specified).\n
1025 Robust mutex objects are not supported (osMutexNew returns NULL when osMutexRobust attribute is specified).\n
1026 - \b osMutexNew: supported
1027 - \b osMutexGetName: \token{not implemented}
1028 - \b osMutexAcquire: supported
1029 - \b osMutexRelease: supported
1030 - \b osMutexGetOwner: supported
1031 - \b osMutexDelete: supported
1035 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__SemaphoreMgmt.html">API reference</a> for details about Semaphore functions.
1036 - \b osSemaphoreNew: supported
1037 - \b osSemaphoreGetName: \token{not implemented}
1038 - \b osSemaphoreAcquire: supported
1039 - \b osSemaphoreRelease: supported
1040 - \b osSemaphoreGetCount: supported
1041 - \b osSemaphoreDelete: supported
1045 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__PoolMgmt.html">API reference</a> for details about Memory Pool functions.
1046 - \b osMemoryPoolNew: supported
1047 - \b osMemoryPoolGetName: supported
1048 - \b osMemoryPoolAlloc: supported
1049 - \b osMemoryPoolFree: supported
1050 - \b osMemoryPoolGetCapacity: supported
1051 - \b osMemoryPoolGetBlockSize: supported
1052 - \b osMemoryPoolGetCount: supported
1053 - \b osMemoryPoolGetSpace: supported
1054 - \b osMemoryPoolDelete: supported
1058 See <a href="https://arm-software.github.io/CMSIS_6/latest/RTOS2/group__CMSIS__RTOS__Message.html">API reference</a> for details about Message Queue functions.
1059 - \b osMessageQueueNew: supported
1060 - \b osMessageQueueGetName: \token{not implemented}
1061 - \b osMessageQueuePut: ignores message priority.
1062 - \b osMessageQueueGet: ignores message priority.
1063 - \b osMessageQueueGetCapacity: supported
1064 - \b osMessageQueueGetMsgSize: supported
1065 - \b osMessageQueueGetCount: supported
1066 - \b osMessageQueueGetSpace: supported
1067 - \b osMessageQueueReset: supported
1068 - \b osMessageQueueDelete: supported
1071 /* ======================================================================================================================== */
1072 // Group creation for Reference
1074 \addtogroup freertos_specific CMSIS-FreeRTOS Specifics
1075 \brief This section describes CMSIS-FreeRTOS specifics.
1077 CMSIS-FreeRTOS interfaces to the
1078 <a href="https://arm-software.github.io/CMSIS-View/latest/evr.html" target="_blank"><b>Event Recorder</b></a>
1079 to provide event information which helps you to understand and analyze the operation. Refer to \ref freertos_evr for more