1 <!-- HTML header for doxygen 1.9.6-->
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
5 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6 <meta http-equiv="X-UA-Compatible" content="IE=11"/>
7 <meta name="viewport" content="width=device-width, initial-scale=1"/>
8 <title>CMSIS-FreeRTOS: Create a FreeRTOS Project</title>
9 <link href="doxygen.css" rel="stylesheet" type="text/css" />
10 <script type="text/javascript" src="jquery.js"></script>
11 <script type="text/javascript" src="dynsections.js"></script>
12 <script type="text/javascript" src="tabs.js"></script>
13 <script type="text/javascript" src="footer.js"></script>
14 <script type="text/javascript" src="navtree.js"></script>
15 <link href="navtree.css" rel="stylesheet" type="text/css"/>
16 <script type="text/javascript" src="navtreedata.js"></script>
17 <script type="text/javascript" src="navtree.js"></script>
18 <script type="text/javascript" src="resize.js"></script>
19 <script type="text/javascript" src="cookie.js"></script>
20 <link href="search/search.css" rel="stylesheet" type="text/css"/>
21 <script type="text/javascript" src="search/searchdata.js"></script>
22 <script type="text/javascript" src="search/search.js"></script>
23 <script type="text/javascript">
24 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
25 $(function() { init_search(); });
28 <script type="text/javascript" src="darkmode_toggle.js"></script>
29 <link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
30 <link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
31 <link href="extra_search.css" rel="stylesheet" type="text/css"/>
32 <link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
33 <link href="version.css" rel="stylesheet" type="text/css"/>
34 <script type="text/javascript" src="../version.js"></script>
37 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
39 <table cellspacing="0" cellpadding="0">
41 <tr style="height: 55px;">
42 <td id="projectlogo" style="padding: 1.5em;"><a href="https://www.keil.arm.com/cmsis" target="_blank"><img alt="Logo" src="cmsis_logo_white_small.png"/</a></td>
43 <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
44 <div id="projectname">CMSIS-FreeRTOS
45  <span id="projectnumber"><script type="text/javascript">
47 writeHeader.call(this);
48 writeVersionDropdown.call(this, "CMSIS-FreeRTOS");
53 <div id="projectbrief">CMSIS-RTOS2 compliant FreeRTOS Implementation</div>
55 <td> <div id="MSearchBox" class="MSearchBoxInactive">
57 <span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span>
58 <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
59 onfocus="searchBox.OnSearchFieldFocus(true)"
60 onblur="searchBox.OnSearchFieldFocus(false)"
61 onkeyup="searchBox.OnSearchFieldChange(event)"/>
62 </span><span class="right">
63 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
71 <!-- end header part -->
72 <div id="CMSISnav" class="tabs1">
74 <script type="text/javascript">
75 writeComponentTabs.call(this);
79 <!-- Generated by Doxygen 1.13.2 -->
80 <script type="text/javascript">
81 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
82 var searchBox = new SearchBox("searchBox", "search/",'.html');
85 <script type="text/javascript">
86 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
87 $(function() { codefold.init(0); });
91 <div id="side-nav" class="ui-resizable side-nav-resizable">
93 <div id="nav-tree-contents">
94 <div id="nav-sync" class="sync"></div>
97 <div id="splitbar" style="-moz-user-select:none;"
98 class="ui-resizable-handle">
101 <script type="text/javascript">
102 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
103 $(function(){initNavTree('page_create_project.html',''); initResizable(true); });
106 <div id="doc-content">
107 <!-- window showing the filter options -->
108 <div id="MSearchSelectWindow"
109 onmouseover="return searchBox.OnSearchSelectShow()"
110 onmouseout="return searchBox.OnSearchSelectHide()"
111 onkeydown="return searchBox.OnSearchSelectKey(event)">
114 <!-- iframe showing the search results (closed by default) -->
115 <div id="MSearchResultsWindow">
116 <div id="MSearchResults">
119 <div id="SRResults"></div>
120 <div class="SRStatus" id="Loading">Loading...</div>
121 <div class="SRStatus" id="Searching">Searching...</div>
122 <div class="SRStatus" id="NoMatches">No Matches</div>
128 <div><div class="header">
129 <div class="headertitle"><div class="title">Create a FreeRTOS Project</div></div>
131 <div class="contents">
132 <div class="textblock"><p><a class="anchor" id="md_src_2create__project"></a></p>
133 <p>You can basically choose between two options when creating a FreeRTOS project:</p>
135 <li><a class="el" href="#create_native_project">Using the FreeRTOS API and kernel</a>.</li>
136 <li><a class="el" href="#create_cmsis_project">Using the CMSIS-RTOS2 API with an underlying FreeRTOS kernel</a>.</li>
138 <h1><a class="anchor" id="create_native_project"></a>
139 Create a Native FreeRTOS Project</h1>
140 <p>The steps to create a microcontroller application using FreeRTOS are:</p>
142 <li>Create a new project and select a microcontroller device.</li>
143 <li>In the Manage Run-Time Environment window, select <b>::Device:Startup</b>, <b>::RTOS:CORE</b> and <b>::RTOS:Config</b> in the <b>FreeRTOS</b> variant and an applicable <b>::RTOS:Heap</b> scheme (for more information on the heap schemes, visit the FreeRTOS documentation):</li>
146 <img src="manage_rte_freertos_native.png" alt=""/>
147 <div class="caption">
148 Manage RTE FreeRTOS Native</div></div>
151 <li>If the <b>Validation Output</b> requires other components to be present, try to use the <b>Resolve</b> button.</li>
152 <li>Click <b>OK</b>. In the <b>Project</b> window, you will see the files that have been automatically added to your project, such as <b>FreeRTOSConfig.h</b>, the source code files, as well as the system and startup files:</li>
155 <img src="project_window_freertos_native.png" alt=""/>
156 <div class="caption">
157 Project Window FreeRTOS Native</div></div>
158 <h2><a class="anchor" id="configure_native_freertos"></a>
159 Configure FreeRTOS</h2>
160 <p>When you have created the native FreeRTOS project, you can configure the real-time operating system using the <b>FreeRTOSConfig.h</b> file. Please refer to the <a href="https://www.freertos.org/a00110.html">FreeRTOS documentation</a> for more information on the specific settings.</p>
162 <img src="freertos_config_h_native.png" alt=""/>
163 <div class="caption">
164 FreeRTOS Config H Native</div></div>
165 <h2><a class="anchor" id="interrupt_priority_config"></a>
166 Interrupt Priority Configuration</h2>
167 <p>FreeRTOS implements critical sections using the <a href="https://developer.arm.com/documentation/dui0552/a/the-cortex-m3-processor/programmers-model/core-registers?lang=en">BASEPRI</a> register (available in Armv7-M and Armv8-M architecture-based devices) which masks only a subset of interrupts. This is configured via the <code>configMAX_SYSCALL_INTERRUPT_PRIORITY</code> setting. Therefore, it is needed to properly configure this setting. It is also needed to set appropriate interrupt priorities for interrupt service routines (ISR) that use RTOS functions. This can especially impact drivers which typically use peripheral interrupts. Normally, these use the RTOS directly or indirectly through registered callbacks.</p>
168 <p>Arm Cortex-M cores store interrupt priority values in the most significant bits of the interrupt priority registers which can have a maximum of eight bits. Many implementations offer only three priority bits. These three bits are shifted up to be bits five, six and seven respectively. <code>configMAX_SYSCALL_INTERRUPT_PRIORITY</code> must not be 0 and can be xxx00000. This results in the following table:</p>
169 <table class="markdownTable">
170 <tr class="markdownTableHead">
171 <th class="markdownTableHeadCenter">configMAX_SYSCALL_INTERRUPT_PRIORITY </th><th class="markdownTableHeadCenter">Upper three bits </th><th class="markdownTableHeadCenter">Priority </th></tr>
172 <tr class="markdownTableRowOdd">
173 <td class="markdownTableBodyCenter">32 </td><td class="markdownTableBodyCenter">001 </td><td class="markdownTableBodyCenter">1 (Highest) </td></tr>
174 <tr class="markdownTableRowEven">
175 <td class="markdownTableBodyCenter">64 </td><td class="markdownTableBodyCenter">010 </td><td class="markdownTableBodyCenter">2 </td></tr>
176 <tr class="markdownTableRowOdd">
177 <td class="markdownTableBodyCenter">96 </td><td class="markdownTableBodyCenter">011 </td><td class="markdownTableBodyCenter">3 </td></tr>
178 <tr class="markdownTableRowEven">
179 <td class="markdownTableBodyCenter">128 </td><td class="markdownTableBodyCenter">100 </td><td class="markdownTableBodyCenter">4 </td></tr>
180 <tr class="markdownTableRowOdd">
181 <td class="markdownTableBodyCenter">160 </td><td class="markdownTableBodyCenter">101 </td><td class="markdownTableBodyCenter">5 </td></tr>
182 <tr class="markdownTableRowEven">
183 <td class="markdownTableBodyCenter">196 </td><td class="markdownTableBodyCenter">110 </td><td class="markdownTableBodyCenter">6 </td></tr>
184 <tr class="markdownTableRowOdd">
185 <td class="markdownTableBodyCenter">224 </td><td class="markdownTableBodyCenter">111 </td><td class="markdownTableBodyCenter">7 (Lowest) </td></tr>
188 <p>If you set <code>configMAX_SYSCALL_INTERRUPT_PRIORITY</code> to 32, then the priority of an interrupt service routine that uses RTOS functions must then be higher or equal to 1. This ensures that this interrupt will be masked during a critical section.</p>
189 <p>A WiFi driver using the SPI interface registers a callback to SPI which is executed in an interrupt context. The callback function in the WiFi driver uses RTOS functions. Therefore, the SPI interrupt priority must be set to a value equal or higher to the FreeRTOS preempt priority, for example 1.</p>
190 <blockquote class="doxtable">
193 <li>For a detailed description of how FreeRTOS is using Cortex-M code registers, refer to <a href="https://www.freertos.org/RTOS-Cortex-M3-M4.html">Running the RTOS on an ARM Cortex-M Core</a>. </li>
196 <h2><a class="anchor" id="native_freertos_add_evr"></a>
197 Add Event Recorder Visibility</h2>
199 <li>To use the Event Recorder together with FreeRTOS, add the software component <b>::Compiler:Event Recorder</b> to your project.</li>
200 <li>Open <a class="el" href="#configure_native_freertos">FreeRTOSConfig.h</a> and<ul>
201 <li>verify the header file <b>freertos_evr.h</b> is included</li>
202 <li>add Event Recorder configuration definitions (see <a class="el" href="#configure_evr">Event Recorder Configuration</a>)</li>
205 <li>Call <b><a class="el" href="group__freertos__setup.html#ga943f40b05c79f40c73d67b1adcbe3dbe" title="Setup Event Recorder configuration.">EvrFreeRTOSSetup()</a></b> in your application code (ideally in <code>main()</code>).</li>
206 <li>If you are using simulation mode, add an initialization file with the following content: <div class="fragment"><div class="line">MAP 0xE0001000, 0xE0001007 READ WRITE</div>
207 <div class="line">signal void DWT_CYCCNT (void) {</div>
208 <div class="line">while (1) {</div>
209 <div class="line"> rwatch(0xE0001004);</div>
210 <div class="line"> _WWORD(0xE0001004, states);</div>
211 <div class="line"> }</div>
212 <div class="line">}</div>
213 <div class="line">DWT_CYCCNT()</div>
214 </div><!-- fragment --></li>
215 <li>Build the application code and download it to the debug hardware or run it in simulation.</li>
217 <p>Once the target application generates event information, it can be viewed in the µVision debugger using the <b>Event Recorder</b>.</p>
218 <h1><a class="anchor" id="create_cmsis_project"></a>
219 Create a CMSIS-FreeRTOS Project</h1>
220 <p>The steps to create a microcontroller application using CMSIS-FreeRTOS are:</p>
222 <li>Create a new project and select a microcontroller device.</li>
223 <li>In the Manage Run-Time Environment window, select <b>::Device:Startup</b>, <b>::CMSIS::RTOS2 (API)::FreeRTOS</b>, <b>::RTOS:CORE</b> in the <b>FreeRTOS</b> variant, <b>::RTOS:Config</b> in the <b>CMSIS RTOS2</b> variant, <b>::RTOS:Timers</b>, <b>::RTOS:Event Groups</b>, and an applicable <b>::RTOS:Heap</b> scheme (for more information on the heap schemes, visit the FreeRTOS documentation):</li>
226 <img src="manage_rte_freertos_rtos2.png" alt=""/>
227 <div class="caption">
228 Manage RTE FreeRTOS RTOS2</div></div>
231 <li>If the <b>Validation Output</b> requires other components to be present, try to use the <b>Resolve</b> button.</li>
232 <li>Click <b>OK</b>. In the <b>Project</b> window, you will see the files that have been automatically added to your project, such as <b>FreeRTOSConfig.h</b>, the source code files, as well as the system and startup files:</li>
235 <img src="project_window_freertos_rtos2.png" alt=""/>
236 <div class="caption">
237 Project Window FreeRTOS RTOS2</div></div>
238 <h2><a class="anchor" id="configure_cmsis_freertos"></a>
239 Configure CMSIS-FreeRTOS</h2>
240 <p>When you have created the CMSIS-FreeRTOS project, you can configure the real-time operating system using the <b>FreeRTOSConfig.h</b> file. It can be opened using the Configuration Wizard view:</p>
242 <img src="freertos_config_h_cmsis_rtos.png" alt=""/>
243 <div class="caption">
244 FreeRTOS Config H CMSIS RTOS</div></div>
245 <p>The following main settings are available:</p>
246 <table class="markdownTable">
247 <tr class="markdownTableHead">
248 <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Configuration define </th><th class="markdownTableHeadNone">Description </th></tr>
249 <tr class="markdownTableRowOdd">
250 <td class="markdownTableBodyNone">Minimal stack size [words] </td><td class="markdownTableBodyNone">configMINIMAL_STACK_SIZE </td><td class="markdownTableBodyNone">Stack for idle task and default task stack in words. </td></tr>
251 <tr class="markdownTableRowEven">
252 <td class="markdownTableBodyNone">Total heap size [bytes] </td><td class="markdownTableBodyNone">configTOTAL_HEAP_SIZE </td><td class="markdownTableBodyNone">Heap memory size in bytes. </td></tr>
253 <tr class="markdownTableRowOdd">
254 <td class="markdownTableBodyNone">Kernel tick frequency [Hz] </td><td class="markdownTableBodyNone">configTICK_RATE_HZ </td><td class="markdownTableBodyNone">Kernel tick rate in Hz. </td></tr>
255 <tr class="markdownTableRowEven">
256 <td class="markdownTableBodyNone">Timer task stack depth [words] </td><td class="markdownTableBodyNone">configTIMER_TASK_STACK_DEPTH </td><td class="markdownTableBodyNone">Stack for timer task in words. </td></tr>
257 <tr class="markdownTableRowOdd">
258 <td class="markdownTableBodyNone">Timer task priority </td><td class="markdownTableBodyNone">configTIMER_TASK_PRIORITY </td><td class="markdownTableBodyNone">Timer task priority. </td></tr>
259 <tr class="markdownTableRowEven">
260 <td class="markdownTableBodyNone">Timer queue length </td><td class="markdownTableBodyNone">configTIMER_QUEUE_LENGTH </td><td class="markdownTableBodyNone">Timer command queue length. </td></tr>
261 <tr class="markdownTableRowOdd">
262 <td class="markdownTableBodyNone">Preemption interrupt priority </td><td class="markdownTableBodyNone">configMAX_SYSCALL_INTERRUPT_PRIORITY </td><td class="markdownTableBodyNone">Maximum priority of interrupts that are safe to call FreeRTOS API. </td></tr>
263 <tr class="markdownTableRowEven">
264 <td class="markdownTableBodyNone">Use time slicing </td><td class="markdownTableBodyNone">configUSE_TIME_SLICING </td><td class="markdownTableBodyNone">Enable setting to use time slicing. </td></tr>
265 <tr class="markdownTableRowOdd">
266 <td class="markdownTableBodyNone">Use tickless idle </td><td class="markdownTableBodyNone">configUSE_TICKLESS_IDLE </td><td class="markdownTableBodyNone">Enable low power tickless mode that stops tick interrupt when idle. </td></tr>
267 <tr class="markdownTableRowEven">
268 <td class="markdownTableBodyNone">Idle should yield </td><td class="markdownTableBodyNone">configIDLE_SHOULD_YIELD </td><td class="markdownTableBodyNone">Control Yield behavior of the idle task. </td></tr>
269 <tr class="markdownTableRowOdd">
270 <td class="markdownTableBodyNone">Check for stack overflow </td><td class="markdownTableBodyNone">configCHECK_FOR_STACK_OVERFLOW </td><td class="markdownTableBodyNone">Enable or disable stack overflow checking. </td></tr>
271 <tr class="markdownTableRowEven">
272 <td class="markdownTableBodyNone">Use idle hook </td><td class="markdownTableBodyNone">configUSE_IDLE_HOOK </td><td class="markdownTableBodyNone">Enable callback function call on each idle task iteration. </td></tr>
273 <tr class="markdownTableRowOdd">
274 <td class="markdownTableBodyNone">Use tick hook </td><td class="markdownTableBodyNone">configUSE_TICK_HOOK </td><td class="markdownTableBodyNone">Enable callback function call during each tick interrupt. </td></tr>
275 <tr class="markdownTableRowEven">
276 <td class="markdownTableBodyNone">Use daemon task startup hook </td><td class="markdownTableBodyNone">configUSE_DAEMON_TASK_STARTUP_HOOK </td><td class="markdownTableBodyNone">Enable callback function call when timer service starts. </td></tr>
277 <tr class="markdownTableRowOdd">
278 <td class="markdownTableBodyNone">Use malloc failed hook </td><td class="markdownTableBodyNone">configUSE_MALLOC_FAILED_HOOK </td><td class="markdownTableBodyNone">Enable callback function call when out of dynamic memory. </td></tr>
279 <tr class="markdownTableRowEven">
280 <td class="markdownTableBodyNone">Queue registry size </td><td class="markdownTableBodyNone">configQUEUE_REGISTRY_SIZE </td><td class="markdownTableBodyNone">Define maximum number of queue objects registered for debug purposes. </td></tr>
282 <blockquote class="doxtable">
285 <li>Refer to <a class="el" href="#interrupt_priority_config">Interrupt Priority Configuration</a> for more information on the usage of <code>configMAX_SYSCALL_INTERRUPT_PRIORITY</code>. </li>
288 <h3>Event Recorder Configuration</h3>
289 <p>The following settings are available (see <a class="el" href="#configure_evr">Event Recorder Configuration</a> for details):</p>
290 <table class="markdownTable">
291 <tr class="markdownTableHead">
292 <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Configuration define </th><th class="markdownTableHeadNone">Description </th></tr>
293 <tr class="markdownTableRowOdd">
294 <td class="markdownTableBodyNone">Initialize Event Recorder </td><td class="markdownTableBodyNone">configEVR_INITIALIZE </td><td class="markdownTableBodyNone">Initialize Event Recorder before FreeRTOS kernel start. </td></tr>
295 <tr class="markdownTableRowEven">
296 <td class="markdownTableBodyNone">Setup recording level filter </td><td class="markdownTableBodyNone">configEVR_SETUP_LEVEL </td><td class="markdownTableBodyNone">Enable configuration of FreeRTOS events recording level. </td></tr>
297 <tr class="markdownTableRowOdd">
298 <td class="markdownTableBodyNone">Task functions </td><td class="markdownTableBodyNone">configEVR_LEVEL_TASKS </td><td class="markdownTableBodyNone">Define event recording level bitmask for events generated from Tasks functions. </td></tr>
299 <tr class="markdownTableRowEven">
300 <td class="markdownTableBodyNone">Queue functions </td><td class="markdownTableBodyNone">configEVR_LEVEL_QUEUE </td><td class="markdownTableBodyNone">Define event recording level bitmask for events generated from Queue functions. </td></tr>
301 <tr class="markdownTableRowOdd">
302 <td class="markdownTableBodyNone">Timer functions </td><td class="markdownTableBodyNone">configEVR_LEVEL_TIMERS </td><td class="markdownTableBodyNone">Define event recording level bitmask for events generated from Timer functions. </td></tr>
303 <tr class="markdownTableRowEven">
304 <td class="markdownTableBodyNone">Event Groups functions </td><td class="markdownTableBodyNone">configEVR_LEVEL_EVENTGROUPS </td><td class="markdownTableBodyNone">Define event recording level bitmask for events generated from Event Groups functions. </td></tr>
305 <tr class="markdownTableRowOdd">
306 <td class="markdownTableBodyNone">Heap functions </td><td class="markdownTableBodyNone">configEVR_LEVEL_HEAP </td><td class="markdownTableBodyNone">Define event recording level bitmask for events generated from Heap functions. </td></tr>
307 <tr class="markdownTableRowEven">
308 <td class="markdownTableBodyNone">Stream Buffer functions </td><td class="markdownTableBodyNone">configEVR_LEVEL_STREAMBUFFER </td><td class="markdownTableBodyNone">Define event recording level bitmask for events generated from Stream Buffer functions. </td></tr>
310 <h3>Memory Allocation Configuration</h3>
311 <p>The following settings are available:</p>
312 <table class="markdownTable">
313 <tr class="markdownTableHead">
314 <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Configuration define </th><th class="markdownTableHeadNone">Description </th></tr>
315 <tr class="markdownTableRowOdd">
316 <td class="markdownTableBodyNone">Support static memory allocation </td><td class="markdownTableBodyNone">configSUPPORT_STATIC_ALLOCATION </td><td class="markdownTableBodyNone">Enable or disable support for static memory allocation. </td></tr>
317 <tr class="markdownTableRowEven">
318 <td class="markdownTableBodyNone">Support dynamic memory allocation </td><td class="markdownTableBodyNone">configSUPPORT_DYNAMIC_ALLOCATION </td><td class="markdownTableBodyNone">Enable or disable support for dynamic memory allocation. </td></tr>
319 <tr class="markdownTableRowOdd">
320 <td class="markdownTableBodyNone">Use kernel provided static memory </td><td class="markdownTableBodyNone">configKERNEL_PROVIDED_STATIC_MEMORY </td><td class="markdownTableBodyNone">When enabled, FreeRTOS kernel provides static memory for Idle and Timer tasks. </td></tr>
321 <tr class="markdownTableRowEven">
322 <td class="markdownTableBodyNone">Use application allocated heap </td><td class="markdownTableBodyNone">configAPPLICATION_ALLOCATED_HEAP </td><td class="markdownTableBodyNone">When enabled, application must provide heap buffer externally. </td></tr>
323 <tr class="markdownTableRowOdd">
324 <td class="markdownTableBodyNone">Use separate heap for stack allocation </td><td class="markdownTableBodyNone">configSTACK_ALLOCATION_FROM_SEPARATE_HEAP </td><td class="markdownTableBodyNone">Enable or disable stack allocation for any task from a separate heap. </td></tr>
325 <tr class="markdownTableRowEven">
326 <td class="markdownTableBodyNone">Use heap protector </td><td class="markdownTableBodyNone">configENABLE_HEAP_PROTECTOR </td><td class="markdownTableBodyNone">Enable or disable bounds checking and obfuscation to heap block pointers. </td></tr>
328 <h3>Port Specific Configuration</h3>
329 <p>The following settings are available:</p>
330 <table class="markdownTable">
331 <tr class="markdownTableHead">
332 <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Configuration define </th><th class="markdownTableHeadNone">Description </th></tr>
333 <tr class="markdownTableRowOdd">
334 <td class="markdownTableBodyNone">Use Floating Point Unit </td><td class="markdownTableBodyNone">configENABLE_FPU </td><td class="markdownTableBodyNone">Enable or disable support for FPU when switching execution context. </td></tr>
335 <tr class="markdownTableRowEven">
336 <td class="markdownTableBodyNone">Use M-Profile Vector Extension </td><td class="markdownTableBodyNone">configENABLE_MVE </td><td class="markdownTableBodyNone">Enable or disable support for MVE when switching execution context. </td></tr>
337 <tr class="markdownTableRowOdd">
338 <td class="markdownTableBodyNone">Use Memory Protection Unit </td><td class="markdownTableBodyNone">configENABLE_MPU </td><td class="markdownTableBodyNone">Enable or disable support for MPU on ARMv8-M MPU enabled ports. </td></tr>
339 <tr class="markdownTableRowEven">
340 <td class="markdownTableBodyNone">Use TrustZone Secure Side Only </td><td class="markdownTableBodyNone">configRUN_FREERTOS_SECURE_ONLY </td><td class="markdownTableBodyNone">Enable this setting when FreeRTOS runs on the Secure side only. </td></tr>
341 <tr class="markdownTableRowOdd">
342 <td class="markdownTableBodyNone">Use TrustZone Security Extension </td><td class="markdownTableBodyNone">configENABLE_TRUSTZONE </td><td class="markdownTableBodyNone">Enable TrustZone when FreeRTOS runs on the Non-Secure side and calls functions from the Secure side. </td></tr>
343 <tr class="markdownTableRowEven">
344 <td class="markdownTableBodyNone">Minimal secure stack size [words] </td><td class="markdownTableBodyNone">configMINIMAL_SECURE_STACK_SIZE </td><td class="markdownTableBodyNone">Stack for idle task Secure side context in words. </td></tr>
346 <h3>Interrupt Controller Configuration</h3>
347 <p><b>Note:</b> Settings related to interrupt controller are relevant only on ARMv7-A ports where it is necessary to configure Arm Generic Interrupt Controller (GIC).</p>
348 <p>The following settings are available:</p>
349 <table class="markdownTable">
350 <tr class="markdownTableHead">
351 <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Configuration define </th><th class="markdownTableHeadNone">Description </th></tr>
352 <tr class="markdownTableRowOdd">
353 <td class="markdownTableBodyNone">Interrupt controller base address </td><td class="markdownTableBodyNone">configINTERRUPT_CONTROLLER_BASE_ADDRESS </td><td class="markdownTableBodyNone">Sets the base address of the interrupt controller peripheral. </td></tr>
354 <tr class="markdownTableRowEven">
355 <td class="markdownTableBodyNone">Interrupt controller CPU interface offset </td><td class="markdownTableBodyNone">configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET </td><td class="markdownTableBodyNone">Sets the offset from interrupt controller base address at which the CPU interface starts. </td></tr>
356 <tr class="markdownTableRowOdd">
357 <td class="markdownTableBodyNone">Interrupt controller unique priorities </td><td class="markdownTableBodyNone">configUNIQUE_INTERRUPT_PRIORITIES </td><td class="markdownTableBodyNone">Sets the number of unique priorities that can be specified in the interrupt controller peripheral. </td></tr>
359 <h3>Symmetric Multiprocessing Configuration</h3>
360 <p><b>Note:</b> Symmetric Multiprocessing Configuration (SMP) settings are only relevant if FreeRTOS port implementation supports SMP.</p>
361 <p>The following settings are available:</p>
362 <table class="markdownTable">
363 <tr class="markdownTableHead">
364 <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Configuration define </th><th class="markdownTableHeadNone">Description </th></tr>
365 <tr class="markdownTableRowOdd">
366 <td class="markdownTableBodyNone">Number of processor cores </td><td class="markdownTableBodyNone">configNUMBER_OF_CORES </td><td class="markdownTableBodyNone">Sets the number of available processor cores. </td></tr>
367 <tr class="markdownTableRowEven">
368 <td class="markdownTableBodyNone">Use processor core affinity </td><td class="markdownTableBodyNone">configUSE_CORE_AFFINITY </td><td class="markdownTableBodyNone">Enables the control for task to run on specific processor cores. </td></tr>
369 <tr class="markdownTableRowOdd">
370 <td class="markdownTableBodyNone">Use passive idle hook </td><td class="markdownTableBodyNone">configUSE_PASSIVE_IDLE_HOOK </td><td class="markdownTableBodyNone">Enable callback function call on each idle task iteration. </td></tr>
372 <h2><a class="anchor" id="cmsis_freertos_add_evr"></a>
373 Add Event Recorder Visibility</h2>
375 <li>To use the Event Recorder together with FreeRTOS, add the software component <b>::Compiler:Event Recorder</b> to your project.</li>
376 <li>Open <a class="el" href="#configure_cmsis_freertos">FreeRTOSConfig.h</a> and<ul>
377 <li>verify the header file <b>freertos_evr.h</b> is included</li>
378 <li>modify Event Recorder configuration definitions (see <a class="el" href="#configure_evr">Event Recorder Configuration</a>) to change default configuration</li>
381 <li>Call <b>osKernelInitialize()</b> in your application code (ideally in <code>main()</code>) to setup Event Recorder according to configuration settings.</li>
382 <li>If you are using simulation mode, add an initialization file with the following content: <div class="fragment"><div class="line">MAP 0xE0001000, 0xE0001007 READ WRITE</div>
383 <div class="line">signal void DWT_CYCCNT (void) {</div>
384 <div class="line">while (1) {</div>
385 <div class="line"> rwatch(0xE0001004);</div>
386 <div class="line"> _WWORD(0xE0001004, states);</div>
387 <div class="line"> }</div>
388 <div class="line">}</div>
389 <div class="line">DWT_CYCCNT()</div>
390 </div><!-- fragment --></li>
391 <li>Build the application code and download it to the debug hardware or run it in simulation.</li>
393 <p>Once the target application generates event information, it can be viewed in the µVision debugger using the <b>Event Recorder</b>.</p>
394 <h1><a class="anchor" id="create_mixed_project"></a>
395 Create a Mixed-Interface Project</h1>
396 <p>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. Such project should be <a class="el" href="#create_cmsis_project">created as CMSIS-FreeRTOS project</a>.</p>
397 <p>Depending on the application requirements, FreeRTOS kernel can be started either by using FreeRTOS native API or by using CMSIS-RTOS2 API.</p>
398 <h2><a class="anchor" id="autotoc_md2"></a>
399 Start the Kernel Using CMSIS-RTOS2 API</h2>
400 <div class="fragment"><div class="line"><span class="comment">/*</span></div>
401 <div class="line"><span class="comment"> Application thread: Initialize and start the Application</span></div>
402 <div class="line"><span class="comment">*/</span></div>
403 <div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
404 <div class="line"> </div>
405 <div class="line"> <span class="keywordflow">while</span>(1) {</div>
406 <div class="line"> <span class="comment">// Application code</span></div>
407 <div class="line"> <span class="comment">// ...</span></div>
408 <div class="line"> }</div>
409 <div class="line">}</div>
410 <div class="line"> </div>
411 <div class="line"><span class="comment">/*</span></div>
412 <div class="line"><span class="comment"> Main function: Initialize and start the kernel</span></div>
413 <div class="line"><span class="comment">*/</span></div>
414 <div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
415 <div class="line"> SystemCoreClockUpdate();</div>
416 <div class="line"> </div>
417 <div class="line"> <span class="comment">// Initialize CMSIS-RTOS2</span></div>
418 <div class="line"> osKernelInitialize();</div>
419 <div class="line"> </div>
420 <div class="line"> <span class="comment">// Create application main thread</span></div>
421 <div class="line"> osThreadNew(app_main, NULL, NULL);</div>
422 <div class="line"> </div>
423 <div class="line"> <span class="comment">// Start the kernel and execute the first thread</span></div>
424 <div class="line"> osKernelStart();</div>
425 <div class="line"> </div>
426 <div class="line"> <span class="keywordflow">while</span>(1);</div>
427 <div class="line">}</div>
428 </div><!-- fragment --><h3>Restrictions</h3>
429 <p>After the kernel is started using CMSIS-RTOS2 API, FreeRTOS native API can be used with the following restrictions:</p>
431 <li><code>vTaskStartScheduler</code> must not be called</li>
433 <h2><a class="anchor" id="autotoc_md3"></a>
434 Start the Kernel Using Native API</h2>
435 <div class="fragment"><div class="line"><span class="comment">/*</span></div>
436 <div class="line"><span class="comment"> Application main thread: Initialize and start the application</span></div>
437 <div class="line"><span class="comment">*/</span></div>
438 <div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
439 <div class="line"> </div>
440 <div class="line"> <span class="keywordflow">while</span>(1) {</div>
441 <div class="line"> <span class="comment">// Application code</span></div>
442 <div class="line"> <span class="comment">// ...</span></div>
443 <div class="line"> }</div>
444 <div class="line">}</div>
445 <div class="line"> </div>
446 <div class="line"><span class="comment">/*</span></div>
447 <div class="line"><span class="comment"> Main function: Initialize and start the kernel</span></div>
448 <div class="line"><span class="comment">*/</span></div>
449 <div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
450 <div class="line"> SystemCoreClockUpdate();</div>
451 <div class="line"> </div>
452 <div class="line"> <span class="comment">// Setup the Event Recorder (optionally)</span></div>
453 <div class="line"> <a class="code hl_function" href="group__freertos__setup.html#ga943f40b05c79f40c73d67b1adcbe3dbe" title="Setup Event Recorder configuration.">EvrFreeRTOSSetup</a>(0);</div>
454 <div class="line"> </div>
455 <div class="line"> <span class="comment">// Create application main thread</span></div>
456 <div class="line"> xTaskCreate (app_main, <span class="stringliteral">"app_main"</span>, 64, NULL, tskIDLE_PRIORITY+1, NULL);</div>
457 <div class="line"> </div>
458 <div class="line"> <span class="comment">// Start the kernel and execute the first thread</span></div>
459 <div class="line"> vTaskStartScheduler();</div>
460 <div class="line"> </div>
461 <div class="line"> <span class="keywordflow">while</span>(1);</div>
462 <div class="line">}</div>
463 </div><!-- fragment --><h3>Restrictions</h3>
464 <p>After the kernel is started using FreeRTOS native API, CMSIS-RTOS2 API can be used without restrictions.</p>
465 <h1><a class="anchor" id="configure_evr"></a>
466 Configure Event Recorder</h1>
467 <p>This section describes the configuration settings for the <a href="https://arm-software.github.io/CMSIS-View/latest/evr.html">Event Recorder</a>. For more information refer to section <a class="el" href="#native_freertos_add_evr">Add Event Recorder Visibility to native FreeRTOS project</a> or <a class="el" href="#cmsis_freertos_add_evr">Add Event Recorder Visibility to CMSIS-FreeRTOS project</a>.</p>
468 <p>Use below definitions to configure Event Recorder initialization and recording level filter setup.</p>
469 <div class="fragment"><div class="line">#define configEVR_INITIALIZE</div>
470 </div><!-- fragment --><table class="markdownTable">
471 <tr class="markdownTableHead">
472 <th class="markdownTableHeadNone">Value </th><th class="markdownTableHeadNone">Description </th></tr>
473 <tr class="markdownTableRowOdd">
474 <td class="markdownTableBodyNone">0 </td><td class="markdownTableBodyNone">Disable Event Recorder initialization </td></tr>
475 <tr class="markdownTableRowEven">
476 <td class="markdownTableBodyNone">1 </td><td class="markdownTableBodyNone">Enable Event Recorder initialization </td></tr>
478 <p>Definition <code>configEVR_INITIALIZE</code> enables Event Recorder initialization during execution of function <code>EvrFreeRTOSSetup</code>. Default value is <code>1</code>.</p>
479 <div class="fragment"><div class="line">#define configEVR_SETUP_LEVEL</div>
480 </div><!-- fragment --><table class="markdownTable">
481 <tr class="markdownTableHead">
482 <th class="markdownTableHeadNone">Value </th><th class="markdownTableHeadNone">Description </th></tr>
483 <tr class="markdownTableRowOdd">
484 <td class="markdownTableBodyNone">0 </td><td class="markdownTableBodyNone">Disable recording level filter setup </td></tr>
485 <tr class="markdownTableRowEven">
486 <td class="markdownTableBodyNone">1 </td><td class="markdownTableBodyNone">Enable recording level filter setup </td></tr>
488 <p>Definition <code>configEVR_SETUP_LEVEL</code> enables setup of recording level filter for events generated by FreeRTOS. Recording level is configured during execution of function <code>EvrFreeRTOSSetup</code>. Default value is <code>1</code>.</p>
489 <div class="fragment"><div class="line">#define configEVR_LEVEL_TASKS</div>
490 <div class="line">#define configEVR_LEVEL_QUEUE</div>
491 <div class="line">#define configEVR_LEVEL_TIMERS</div>
492 <div class="line">#define configEVR_LEVEL_EVENTGROUPS</div>
493 <div class="line">#define configEVR_LEVEL_HEAP</div>
494 <div class="line">#define configEVR_LEVEL_STREAMBUFFER</div>
495 </div><!-- fragment --><table class="markdownTable">
496 <tr class="markdownTableHead">
497 <th class="markdownTableHeadNone">Value </th><th class="markdownTableHeadNone">Description </th></tr>
498 <tr class="markdownTableRowOdd">
499 <td class="markdownTableBodyNone">0x00 </td><td class="markdownTableBodyNone">Disable event generation </td></tr>
500 <tr class="markdownTableRowEven">
501 <td class="markdownTableBodyNone">0x01 </td><td class="markdownTableBodyNone">Enable generation of error events </td></tr>
502 <tr class="markdownTableRowOdd">
503 <td class="markdownTableBodyNone">0x05 </td><td class="markdownTableBodyNone">Enable generation of error and operational events </td></tr>
504 <tr class="markdownTableRowEven">
505 <td class="markdownTableBodyNone">0x07 </td><td class="markdownTableBodyNone">Enable generation of error, API and operational events </td></tr>
506 <tr class="markdownTableRowOdd">
507 <td class="markdownTableBodyNone">0x0F </td><td class="markdownTableBodyNone">Enable generation of all events </td></tr>
509 <p>Definitions <code>configEVR_LEVEL_x</code> 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 <code>0x05</code>.</p>
510 <h1><a class="anchor" id="autotoc_md4"></a>
511 Debug a CMSIS-FreeRTOS Project</h1>
512 <p><b>Note:</b> The following only applies when used with <a href="https://developer.arm.com/Tools%20and%20Software/Keil%20MDK">Arm Keil MDK</a>. If you are using a different toolchain, please consult its user's manual.</p>
513 <p>Apart from the debug capabilities that <a class="el" href="#configure_evr">Event Recorder</a> offers, Keil MDK also supports thread-aware breakpoints, just like for the standard CMSIS-RTOS.</p>
514 <h3>Code Example</h3>
515 <div class="fragment"><div class="line">BS FuncN1, 1, "break = (CURR_TID == tid_phaseA) ? 1 : 0"</div>
516 <div class="line">BS FuncN1, 1, "break = (CURR_TID == tid_phaseA || CURR_TID == tid_phaseD) ? 1 : 0"</div>
517 <div class="line">BS \\Blinky\Blinky.c\FuncN1\179, 1, "break = (CURR_TID == tid_phaseA || CURR_TID == tid_phaseD) ? 1 : 0"</div>
518 </div><!-- fragment --><blockquote class="doxtable">
521 <li>For more information on conditional breakpoints in Keil MDK, consult the <a href="https://developer.arm.com/documentation/101407/latest/Debugging/Debug-Windows-and-Dialogs/Breakpoints-Window">user's manual</a>.</li>
522 <li>Enabling <a href="https://developer.arm.com/documentation/101407/latest/User-Interface/View-Menu">Periodic Window Update</a> is required to capture register values for active running threads while executing. When turned off, only the current FreeRTOS thread can be unwound after execution has been stopped. </li>
527 <li>You cannot specify individual breakpoints on the same address. The following is not possible: <div class="fragment"><div class="line">BS ThCallee, 1, "break = (CURR_TID==tid_phaseA) ? 1 : 0"</div>
528 <div class="line">BS ThCallee, 1, "break = (CURR_TID==tid_phaseD) ? 1 : 0"</div>
529 </div><!-- fragment --> Instead, use this: <div class="fragment"><div class="line">BS ThCallee, 1, "break= (CURR_TID==tid_phaseA || CURR_TID==tid_phaseD) ? 1 : 0"</div>
530 </div><!-- fragment --></li>
531 <li>If you don't want to use <a href="https://developer.arm.com/documentation/101407/latest/User-Interface/View-Menu">Periodic Window Update</a>, obtain the thread and unwind information by adding a function that gets called from each thread of interest: <div class="fragment"><div class="line">_attribute_((noinline)) <span class="keywordtype">int</span> FuncN1 (<span class="keywordtype">int</span> n1) {</div>
532 <div class="line"> ...</div>
533 <div class="line">}</div>
534 </div><!-- fragment --> Then, specify a thread-aware breakpoint using an "invalid" thread ID: <div class="fragment"><div class="line">BS FuncN1, 1, "break = (CURR_TID == tid_phaseA + 1) ? 1 : 0"</div>
535 </div><!-- fragment --> ‘'tid_phaseA’<code>would be valid,</code>'tid_phaseA + 1'` is not but will still capture the most recent registers and store them to the actual thread context each time a thread-aware breakpoint is checked.</li>
536 <li>Function inlining typically causes thread-aware breakpoints to fail. To avoid this, prepend the ‘'noinline’` attribute to the function that is used to stop when the current FreeRTOS thread id matches: <div class="fragment"><div class="line">_attribute_((noinline)) <span class="keywordtype">int</span> FuncN1 (<span class="keywordtype">int</span> n1) {</div>
537 <div class="line"> ...</div>
538 <div class="line">}</div>
539 </div><!-- fragment --> This helps to make thread-aware breakpoints far less dependent on the compiler optimization level.</li>
540 <li>Thread-aware breakpoints should be setup using a <a href="https://developer.arm.com/documentation/101407/latest/Debugging/Debug-Scripting">debug script</a>. Reason being that thread-aware breakpoints are of a 'hybrid' type, that is a combined address and condition expression that works best when run from a debug script. </li>
542 </div></div><!-- contents -->
543 </div><!-- PageDoc -->
544 </div><!-- doc-content -->
545 <!-- start footer part -->
546 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
549 <script type="text/javascript">
551 writeFooter.call(this);