1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
6 <title>Create a FreeRTOS project</title>
7 <title>CMSIS-FreeRTOS: Create a FreeRTOS project</title>
8 <link href="tabs.css" rel="stylesheet" type="text/css"/>
9 <link href="cmsis.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="printComponentTabs.js"></script>
13 <link href="navtree.css" rel="stylesheet" type="text/css"/>
14 <script type="text/javascript" src="resize.js"></script>
15 <script type="text/javascript" src="navtree.js"></script>
16 <script type="text/javascript">
17 $(document).ready(initResizable);
18 $(window).load(resizeHeight);
20 <link href="search/search.css" rel="stylesheet" type="text/css"/>
21 <script type="text/javascript" src="search/search.js"></script>
22 <script type="text/javascript">
23 $(document).ready(function() { searchBox.OnSelectItem(0); });
27 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
29 <table cellspacing="0" cellpadding="0">
31 <tr style="height: 46px;">
32 <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
33 <td style="padding-left: 0.5em;">
34 <div id="projectname">CMSIS-FreeRTOS
35  <span id="projectnumber">Version 10.4.6</span>
37 <div id="projectbrief">CMSIS-RTOS2 compliant FreeRTOS Implementation</div>
43 <!-- end header part -->
44 <div id="CMSISnav" class="tabs1">
46 <script type="text/javascript">
48 writeComponentTabs.call(this);
53 <!-- Generated by Doxygen 1.8.6 -->
54 <script type="text/javascript">
55 var searchBox = new SearchBox("searchBox", "search",false,'Search');
57 <div id="navrow1" class="tabs">
59 <li><a href="index.html"><span>Main Page</span></a></li>
60 <li class="current"><a href="pages.html"><span>Usage and Description</span></a></li>
61 <li><a href="modules.html"><span>Reference</span></a></li>
63 <div id="MSearchBox" class="MSearchBoxInactive">
65 <img id="MSearchSelect" src="search/mag_sel.png"
66 onmouseover="return searchBox.OnSearchSelectShow()"
67 onmouseout="return searchBox.OnSearchSelectHide()"
69 <input type="text" id="MSearchField" value="Search" accesskey="S"
70 onfocus="searchBox.OnSearchFieldFocus(true)"
71 onblur="searchBox.OnSearchFieldFocus(false)"
72 onkeyup="searchBox.OnSearchFieldChange(event)"/>
73 </span><span class="right">
74 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
81 <div id="side-nav" class="ui-resizable side-nav-resizable">
83 <div id="nav-tree-contents">
84 <div id="nav-sync" class="sync"></div>
87 <div id="splitbar" style="-moz-user-select:none;"
88 class="ui-resizable-handle">
91 <script type="text/javascript">
92 $(document).ready(function(){initNavTree('cre_freertos_proj.html','');});
94 <div id="doc-content">
95 <!-- window showing the filter options -->
96 <div id="MSearchSelectWindow"
97 onmouseover="return searchBox.OnSearchSelectShow()"
98 onmouseout="return searchBox.OnSearchSelectHide()"
99 onkeydown="return searchBox.OnSearchSelectKey(event)">
100 <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Pages</a></div>
102 <!-- iframe showing the search results (closed by default) -->
103 <div id="MSearchResultsWindow">
104 <iframe src="javascript:void(0)" frameborder="0"
105 name="MSearchResults" id="MSearchResults">
110 <div class="headertitle">
111 <div class="title">Create a FreeRTOS project </div> </div>
113 <div class="contents">
114 <div class="textblock"><p>You can basically choose between two option when creating a FreeRTOS project:</p>
116 <li><a class="el" href="cre_freertos_proj.html#native_freertos">Create a native FreeRTOS project</a> using the FreeRTOS API and kernel.</li>
117 <li><a class="el" href="cre_freertos_proj.html#cmsis_freertos">Create a CMSIS-FreeRTOS project</a> using the CMSIS-RTOS2 API with an underlying FreeRTOS kernel.</li>
119 <h1><a class="anchor" id="native_freertos"></a>
120 Create a native FreeRTOS project</h1>
121 <p>The steps to create a microcontroller application using FreeRTOS are:</p>
123 <li>Create a new project and select a microcontroller device.</li>
124 <li><p class="startli">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):</p>
126 <img src="manage_rte_freertos_native.png" alt="manage_rte_freertos_native.png"/>
128 <p class="startli"><br/>
131 <li>If the <b>Validation Output</b> requires other components to be present, try to use the <b>Resolve</b> button.</li>
132 <li><p class="startli">Click <b>OK</b>. In the <b>Project</b> window, you will see the files that have been automatically added to you project, such as <b>FreeRTOSConfig.h</b>, the source code files, as well as the system and startup files:</p>
134 <img src="project_window_freertos_native.png" alt="project_window_freertos_native.png"/>
138 <h2><a class="anchor" id="native_freertos_config"></a>
139 Configure FreeRTOS</h2>
140 <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="http://www.freertos.org/a00110.html" target="_blank">FreeRTOS documentation</a> for more information on the specific settings.</p>
142 <img src="freertos_config_h_native.png" alt="freertos_config_h_native.png"/>
144 <h2><a class="anchor" id="native_freertos_config_prio"></a>
145 Interrupt priority configuration</h2>
146 <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" target="_blank">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>
147 <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>
148 <table class="doxtable">
150 <th align="center"><code>configMAX_SYSCALL_INTERRUPT_PRIORITY</code> </th><th align="center">Upper three bits </th><th align="center">Priority </th></tr>
152 <td align="center">32 </td><td align="center">001 </td><td align="center">1 (Highest) </td></tr>
154 <td align="center">64 </td><td align="center">010 </td><td align="center">2 </td></tr>
156 <td align="center">96 </td><td align="center">011 </td><td align="center">3 </td></tr>
158 <td align="center">128 </td><td align="center">100 </td><td align="center">4 </td></tr>
160 <td align="center">160 </td><td align="center">101 </td><td align="center">5 </td></tr>
162 <td align="center">196 </td><td align="center">110 </td><td align="center">6 </td></tr>
164 <td align="center">224 </td><td align="center">111 </td><td align="center">7 (Lowest) </td></tr>
166 <p><b>Example</b> </p>
167 <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 critical a section.</p>
168 <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>
169 <dl class="section note"><dt>Note</dt><dd>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" target="_blank">Running the RTOS on a ARM Cortex-M Core</a>.</dd></dl>
170 <h2><a class="anchor" id="native_freertos_er"></a>
171 Add Event Recorder Visibility</h2>
173 <li>To use the Event Recorder together with FreeRTOS, add the software component <b>::Compiler:Event Recorder</b> to your project.</li>
174 <li>Open <a class="el" href="cre_freertos_proj.html#native_freertos_config">FreeRTOSConfig.h</a> and<ul>
175 <li>verify the header file <b>freertos_evr.h</b> is included</li>
176 <li>add Event Recorder configuration definitions (see <a class="el" href="cre_freertos_proj.html#cmsis_freertos_evr_config">Configure Event Recorder</a>)</li>
179 <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>
180 <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>
181 <div class="line">signal <span class="keywordtype">void</span> DWT_CYCCNT (<span class="keywordtype">void</span>) {</div>
182 <div class="line"><span class="keywordflow">while</span> (1) {</div>
183 <div class="line"> rwatch(0xE0001004);</div>
184 <div class="line"> _WWORD(0xE0001004, states);</div>
185 <div class="line"> }</div>
186 <div class="line">}</div>
187 <div class="line">DWT_CYCCNT()</div>
188 </div><!-- fragment --></li>
189 <li>Build the application code and download it to the debug hardware or run it in simulation.</li>
191 <p>Once the target application generates event information, it can be viewed in the µVision debugger using the <b>Event Recorder</b>.</p>
192 <h1><a class="anchor" id="cmsis_freertos"></a>
193 Create a CMSIS-FreeRTOS project</h1>
194 <p>The steps to create a microcontroller application using CMSIS-FreeRTOS are:</p>
196 <li>Create a new project and select a microcontroller device.</li>
197 <li><p class="startli">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</b> <b>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):</p>
199 <img src="manage_rte_freertos_rtos2.png" alt="manage_rte_freertos_rtos2.png"/>
201 <p class="startli"><br/>
204 <li>If the <b>Validation Output</b> requires other components to be present, try to use the <b>Resolve</b> button.</li>
205 <li><p class="startli">Click <b>OK</b>. In the <b>Project</b> window, you will see the files that have been automatically added to you project, such as <b>FreeRTOSConfig.h</b>, the source code files, as well as the system and startup files:</p>
207 <img src="project_window_freertos_rtos2.png" alt="project_window_freertos_rtos2.png"/>
211 <h2><a class="anchor" id="cmsis_freertos_config"></a>
212 Configure CMSIS-FreeRTOS</h2>
213 <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>
215 <img src="freertos_config_h_cmsis_rtos.png" alt="freertos_config_h_cmsis_rtos.png"/>
217 <p>The following settings are available:</p>
218 <table class="doxtable">
220 <th>Name </th><th>#define </th><th>Description </th></tr>
222 <td>Minimal stack size [words] </td><td>configMINIMAL_STACK_SIZE </td><td>Stack for idle task and default task stack in words. </td></tr>
224 <td>Total heap size [bytes] </td><td>configTOTAL_HEAP_SIZE </td><td>Heap memory size in bytes. </td></tr>
226 <td>Kernel tick frequency [Hz] </td><td>configTICK_RATE_HZ </td><td>Kernel tick rate in Hz. </td></tr>
228 <td>Timer task stack depth [words] </td><td>configTIMER_TASK_STACK_DEPTH </td><td>Stack for timer task in words. </td></tr>
230 <td>Timer task priority </td><td>configTIMER_TASK_PRIORITY </td><td>Timer task priority. </td></tr>
232 <td>Timer queue length </td><td>configTIMER_QUEUE_LENGTH </td><td>Timer command queue length. </td></tr>
234 <td>Preemption interrupt priority </td><td>configMAX_SYSCALL_INTERRUPT_PRIORITY </td><td>Maximum priority of interrupts that are safe to call FreeRTOS API. </td></tr>
236 <td>Use time slicing </td><td>configUSE_TIME_SLICING </td><td>Enable setting to use time slicing. </td></tr>
238 <td>Idle should yield </td><td>configIDLE_SHOULD_YIELD </td><td>Control Yield behavior of the idle task. </td></tr>
240 <td>Check for stack overflow </td><td>configCHECK_FOR_STACK_OVERFLOW </td><td>Enable or disable stack overflow checking. </td></tr>
242 <td>Use idle hook </td><td>configUSE_IDLE_HOOK </td><td>Enable callback function call on each idle task iteration. </td></tr>
244 <td>Use tick hook </td><td>configUSE_TICK_HOOK </td><td>Enable callback function call during each tick interrupt. </td></tr>
246 <td>Use daemon task startup hook </td><td>configUSE_DAEMON_TASK_STARTUP_HOOK </td><td>Enable callback function call when timer service starts. </td></tr>
248 <td>Use malloc failed hook </td><td>configUSE_MALLOC_FAILED_HOOK </td><td>Enable callback function call when out of dynamic memory. </td></tr>
250 <td>Queue registry size </td><td>configQUEUE_REGISTRY_SIZE </td><td>Define maximum number of queue objects registered for debug purposes. </td></tr>
252 <dl class="section note"><dt>Note</dt><dd>Refer to <a class="el" href="cre_freertos_proj.html#native_freertos_config_prio">Interrupt priority configuration</a> for more information on the usage of <code>configMAX_SYSCALL_INTERRUPT_PRIORITY</code>.</dd></dl>
253 <p><b> Event Recorder Configuration </b></p>
254 <p>The following settings are available (see <a class="el" href="cre_freertos_proj.html#cmsis_freertos_evr_config">Configure Event Recorder</a> for details):</p>
255 <table class="doxtable">
257 <th>Name </th><th>#define </th><th>Description </th></tr>
259 <td>Initialize Event Recorder </td><td>configEVR_INITIALIZE </td><td>Initialize Event Recorder before FreeRTOS kernel start. </td></tr>
261 <td>Setup recording level filter </td><td>configEVR_SETUP_LEVEL </td><td>Enable configuration of FreeRTOS events recording level. </td></tr>
263 <td>Task functions </td><td>configEVR_LEVEL_TASKS </td><td>Define event recording level bitmask for events generated from Tasks functions. </td></tr>
265 <td>Queue functions </td><td>configEVR_LEVEL_QUEUE </td><td>Define event recording level bitmask for events generated from Queue functions. </td></tr>
267 <td>Timer functions </td><td>configEVR_LEVEL_TIMERS </td><td>Define event recording level bitmask for events generated from Timer functions. </td></tr>
269 <td>Event Groups functions </td><td>configEVR_LEVEL_EVENTGROUPS </td><td>Define event recording level bitmask for events generated from Event Groups functions. </td></tr>
271 <td>Heap functions </td><td>configEVR_LEVEL_HEAP </td><td>Define event recording level bitmask for events generated from Heap functions. </td></tr>
273 <td>Stream Buffer functions </td><td>configEVR_LEVEL_STREAMBUFFER </td><td>Define event recording level bitmask for events generated from Stream Buffer functions. </td></tr>
275 <h2><a class="anchor" id="cmsis_freertos_er"></a>
276 Add Event Recorder Visibility</h2>
278 <li>To use the Event Recorder together with FreeRTOS, add the software component <b>::Compiler:Event Recorder</b> to your project.</li>
279 <li>Open <a class="el" href="cre_freertos_proj.html#native_freertos_config">FreeRTOSConfig.h</a> and<ul>
280 <li>verify the header file <b>freertos_evr.h</b> is included</li>
281 <li>modify Event Recorder configuration definitions (see <a class="el" href="cre_freertos_proj.html#cmsis_freertos_evr_config">Configure Event Recorder</a>) to change default configuration</li>
284 <li>Call <b>osKernelInitialize()</b> in your application code (ideally in <code>main()</code>) to setup Event Recorder according to configuration settings.</li>
285 <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>
286 <div class="line">signal <span class="keywordtype">void</span> DWT_CYCCNT (<span class="keywordtype">void</span>) {</div>
287 <div class="line"><span class="keywordflow">while</span> (1) {</div>
288 <div class="line"> rwatch(0xE0001004);</div>
289 <div class="line"> _WWORD(0xE0001004, states);</div>
290 <div class="line"> }</div>
291 <div class="line">}</div>
292 <div class="line">DWT_CYCCNT()</div>
293 </div><!-- fragment --></li>
294 <li>Build the application code and download it to the debug hardware or run it in simulation.</li>
296 <p>Once the target application generates event information, it can be viewed in the µVision debugger using the <b>Event Recorder.</b></p>
297 <h1><a class="anchor" id="freertos_interfaces"></a>
298 Create a mixed-interface project</h1>
299 <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="cre_freertos_proj.html#cmsis_freertos">created as CMSIS-FreeRTOS project</a>.</p>
300 <p>Depending on the application requirements, FreeRTOS kernel can be started either by using FreeRTOS native API or by using CMSIS-RTOS2 API.</p>
301 <h2><a class="anchor" id="freertos_interface_rtos2"></a>
302 Start the kernel using CMSIS-RTOS2 API</h2>
303 <div class="fragment"><div class="line"><span class="comment">/*</span></div>
304 <div class="line"><span class="comment"> Application thread: Initialize and start the Application</span></div>
305 <div class="line"><span class="comment">*/</span></div>
306 <div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
307 <div class="line"></div>
308 <div class="line"> <span class="keywordflow">while</span>(1) {</div>
309 <div class="line"> <span class="comment">// Application code</span></div>
310 <div class="line"> <span class="comment">// ...</span></div>
311 <div class="line"> }</div>
312 <div class="line">}</div>
313 <div class="line"></div>
314 <div class="line"><span class="comment">/*</span></div>
315 <div class="line"><span class="comment"> Main function: Initialize and start the kernel</span></div>
316 <div class="line"><span class="comment">*/</span></div>
317 <div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
318 <div class="line"> SystemCoreClockUpdate();</div>
319 <div class="line"> </div>
320 <div class="line"> <span class="comment">// Initialize CMSIS-RTOS2</span></div>
321 <div class="line"> osKernelInitialize();</div>
322 <div class="line"> </div>
323 <div class="line"> <span class="comment">// Create application main thread</span></div>
324 <div class="line"> osThreadNew(app_main, NULL, NULL);</div>
325 <div class="line"> </div>
326 <div class="line"> <span class="comment">// Start the kernel and execute the first thread</span></div>
327 <div class="line"> osKernelStart();</div>
328 <div class="line"> </div>
329 <div class="line"> <span class="keywordflow">while</span>(1);</div>
330 <div class="line">}</div>
331 </div><!-- fragment --><p><b>Restrictions</b> </p>
332 <p>After the kernel is started using CMSIS-RTOS2 API, FreeRTOS native API can be used with the following restrictions:</p>
334 <li>vTaskStartScheduler must not be called</li>
336 <h2><a class="anchor" id="freertos_interface_native"></a>
337 Start the kernel using native API</h2>
338 <div class="fragment"><div class="line"><span class="comment">/*</span></div>
339 <div class="line"><span class="comment"> Application main thread: Initialize and start the application</span></div>
340 <div class="line"><span class="comment">*/</span></div>
341 <div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
342 <div class="line"></div>
343 <div class="line"> <span class="keywordflow">while</span>(1) {</div>
344 <div class="line"> <span class="comment">// Application code</span></div>
345 <div class="line"> <span class="comment">// ...</span></div>
346 <div class="line"> }</div>
347 <div class="line">}</div>
348 <div class="line"></div>
349 <div class="line"><span class="comment">/*</span></div>
350 <div class="line"><span class="comment"> Main function: Initialize and start the kernel</span></div>
351 <div class="line"><span class="comment">*/</span></div>
352 <div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
353 <div class="line"> SystemCoreClockUpdate();</div>
354 <div class="line"> </div>
355 <div class="line"> <span class="comment">// Setup the Event Recorder (optionally)</span></div>
356 <div class="line"> <a class="code" href="group__freertos__setup.html#ga943f40b05c79f40c73d67b1adcbe3dbe">EvrFreeRTOSSetup</a>(0);</div>
357 <div class="line"> </div>
358 <div class="line"> <span class="comment">// Create application main thread</span></div>
359 <div class="line"> xTaskCreate (app_main, <span class="stringliteral">"app_main"</span>, 64, NULL, tskIDLE_PRIORITY+1, NULL);</div>
360 <div class="line"> </div>
361 <div class="line"> <span class="comment">// Start the kernel and execute the first thread</span></div>
362 <div class="line"> vTaskStartScheduler();</div>
363 <div class="line"> </div>
364 <div class="line"> <span class="keywordflow">while</span>(1);</div>
365 <div class="line">}</div>
366 </div><!-- fragment --><p><b>Restrictions</b> </p>
367 <p>After the kernel is started using FreeRTOS native API, CMSIS-RTOS2 API can be used without restrictions.</p>
368 <h1><a class="anchor" id="cmsis_freertos_evr_config"></a>
369 Configure Event Recorder</h1>
370 <p>This section describes the configuration settings for the <a href="http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html" target="_blank">Event Recorder</a> annotations. For more information refer to section <a class="el" href="cre_freertos_proj.html#native_freertos_er">Add Event Recorder Visibility to native FreeRTOS project</a> or <a class="el" href="cre_freertos_proj.html#cmsis_freertos_er">Add Event Recorder Visibility to CMSIS-FreeRTOS project</a>.</p>
371 <p>Use below definitions to configure Event Recorder initialization and recording level filter setup.</p>
372 <div class="fragment"><div class="line"><span class="preprocessor">#define configEVR_INITIALIZE</span></div>
373 </div><!-- fragment --><table class="doxtable">
375 <th>Value </th><th>Description </th></tr>
377 <td>0 </td><td>Disable Event Recorder initialization </td></tr>
379 <td>1 </td><td>Enable Event Recorder initialization </td></tr>
381 <p>Definition configEVR_INITIALIZE enables Event Recorder initialization during execution of function <a class="el" href="group__freertos__setup.html#ga943f40b05c79f40c73d67b1adcbe3dbe">EvrFreeRTOSSetup</a>. Default value is <span class="XML-Token">1</span>.</p>
382 <div class="fragment"><div class="line"><span class="preprocessor">#define configEVR_SETUP_LEVEL</span></div>
383 </div><!-- fragment --><table class="doxtable">
385 <th>Value </th><th>Description </th></tr>
387 <td>0 </td><td>Disable recording level filter setup </td></tr>
389 <td>1 </td><td>Enable recording level filter setup </td></tr>
391 <p>Definition configEVR_SETUP_LEVEL enables setup of recording level filter for events generated by FreeRTOS. Recording level is configured during execution of function <a class="el" href="group__freertos__setup.html#ga943f40b05c79f40c73d67b1adcbe3dbe">EvrFreeRTOSSetup</a>. Default value is <span class="XML-Token">1</span>.</p>
392 <div class="fragment"><div class="line"><span class="preprocessor">#define configEVR_LEVEL_TASKS</span></div>
393 <div class="line"><span class="preprocessor"></span><span class="preprocessor">#define configEVR_LEVEL_QUEUE</span></div>
394 <div class="line"><span class="preprocessor"></span><span class="preprocessor">#define configEVR_LEVEL_TIMERS</span></div>
395 <div class="line"><span class="preprocessor"></span><span class="preprocessor">#define configEVR_LEVEL_EVENTGROUPS</span></div>
396 <div class="line"><span class="preprocessor"></span><span class="preprocessor">#define configEVR_LEVEL_HEAP</span></div>
397 <div class="line"><span class="preprocessor">#define configEVR_LEVEL_STREAMBUFFER</span></div>
398 </div><!-- fragment --><table class="doxtable">
400 <th>Value </th><th>Description </th></tr>
402 <td>0x00 </td><td>Disable event generation </td></tr>
404 <td>0x01 </td><td>Enable generation of error events </td></tr>
406 <td>0x05 </td><td>Enable generation of error and operational events </td></tr>
408 <td>0x0F </td><td>Enable generation of all events </td></tr>
410 <p>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 <span class="XML-Token">0x05</span>.</p>
411 <h1><a class="anchor" id="dbg_cmsisfreertos"></a>
412 Debug a CMSIS-FreeRTOS project</h1>
413 <dl class="section note"><dt>Note</dt><dd>The following only applies when used with <a href="https://www2.keil.com/mdk5" target="_blank">Arm Keil MDK</a>. If you are using a different toolchain, please consult its user's manual.</dd></dl>
414 <p>Apart from the debug capabilities that <a class="el" href="cre_freertos_proj.html#cmsis_freertos_evr_config">Event Recorder</a> offers, Keil MDK also supports thread aware breakpoints, just like for the standard CMSIS-RTOS.</p>
415 <p><b>Code</b> <b>Example</b> </p>
416 <div class="fragment"><div class="line">BS FuncN1, 1, <span class="stringliteral">"break = (CURR_TID == tid_phaseA) ? 1 : 0"</span></div>
417 <div class="line">BS FuncN1, 1, <span class="stringliteral">"break = (CURR_TID == tid_phaseA || CURR_TID == tid_phaseD) ? 1 : 0"</span></div>
418 <div class="line">BS \\Blinky\Blinky.c\FuncN1\179, 1, <span class="stringliteral">"break = (CURR_TID == tid_phaseA || CURR_TID == tid_phaseD) ? 1 : 0"</span></div>
419 </div><!-- fragment --><dl class="section note"><dt>Note</dt><dd><ul>
420 <li>For more information on conditional breakpoints in Keil MDK, consult the <a href="https://www.keil.com/support/man/docs/uv4/uv4_db_dbg_breakpnts.htm" target="_blank">user's manual</a>.</li>
421 <li>Enabling <a href="https://www.keil.com/support/man/docs/uv4/uv4_ui_view.htm" target="_blank">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>
424 <p><b>Caveats</b> </p>
426 <li>You cannot specify individual breakpoints on the same address. The following is not possible: <div class="fragment"><div class="line">BS ThCallee, 1, <span class="stringliteral">"break = (CURR_TID==tid_phaseA) ? 1 : 0"</span></div>
427 <div class="line">BS ThCallee, 1, <span class="stringliteral">"break = (CURR_TID==tid_phaseD) ? 1 : 0"</span></div>
428 </div><!-- fragment --> Instead, use this: <div class="fragment"><div class="line">BS ThCallee, 1, <span class="stringliteral">"break= (CURR_TID==tid_phaseA || CURR_TID==tid_phaseD) ? 1 : 0"</span></div>
429 </div><!-- fragment --></li>
430 <li>If you don't want to use <a href="https://www.keil.com/support/man/docs/uv4/uv4_ui_view.htm" target="_blank">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)) int FuncN1 (<span class="keywordtype">int</span> n1) {</div>
431 <div class="line"> ...</div>
432 <div class="line">} </div>
433 </div><!-- fragment --> Then, specify a thread aware breakpoint using an "invalid" thread ID: <div class="fragment"><div class="line">BS FuncN1, 1, <span class="stringliteral">"break = (CURR_TID == tid_phaseA + 1) ? 1 : 0"</span></div>
434 </div><!-- fragment --> <code>'tid_phaseA'</code> would be valid, <code>'tid_phaseA + 1'</code> 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>
435 <li>Function inlining typically causes thread aware breakpoints to fail. To avoid this, prepend the <code>'noinline'</code> attribute to the function that is used to stop when the current FreeRTOS thread id matches: <div class="fragment"><div class="line">_attribute_((noinline)) int FuncN1 (<span class="keywordtype">int</span> n1) {</div>
436 <div class="line"> ...</div>
437 <div class="line">}</div>
438 </div><!-- fragment --> This helps to make thread aware breakpoints far less dependent on the compiler optimization level.</li>
439 <li>Thread aware breakpoints should be setup using a <a href="https://www.keil.com/support/man/docs/uv4/uv4_db_scripting.htm" target="_blank">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>
441 </div></div><!-- contents -->
442 </div><!-- doc-content -->
443 <!-- start footer part -->
444 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
446 <li class="footer">Generated on Tue Nov 16 2021 09:08:40 for CMSIS-FreeRTOS by ARM Ltd. All rights reserved.
448 <a href="http://www.doxygen.org/index.html">
449 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6