{"id":3686,"date":"2018-02-16T11:35:32","date_gmt":"2018-02-16T19:35:32","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=3686"},"modified":"2018-02-16T11:35:32","modified_gmt":"2018-02-16T19:35:32","slug":"using-freertos-with-nordic-nrf5x-devices","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/nrf51\/freertos\/","title":{"rendered":"Using FreeRTOS-with Nordic nRF5x Devices"},"content":{"rendered":"<p>This tutorial shows how to use the FreeRTOS real-time\u00a0operating system with the Nordic nRF5x devices. We will show how to create a basic project using FreeRTOS, change its configuration, view\u00a0the real-time thread trace and understand the program\u00a0timings by using the embedded profiler. Before you begin, install VisualGDB 5.3 or later and get the latest\u00a0Nordic BSP via the VisualGDB Package Manager.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/01-demo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3687\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/01-demo.png\" alt=\"01-demo\" width=\"882\" height=\"582\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/01-demo.png 882w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/01-demo-300x198.png 300w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/a><\/li>\n<li>On the first page of the wizard select &#8220;Create a new project with MSBuild&#8221; -&gt; &#8220;Embedded Binary&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/02-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3688\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/02-msbuild.png\" alt=\"02-msbuild\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/02-msbuild.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/02-msbuild-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>On the next page select your ARM toolchain and pick\u00a0the Nordic device you are targeting. In this\u00a0tutorial we will target the nRF52840 device:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/03-nosoftdev.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3689\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/03-nosoftdev.png\" alt=\"03-nosoftdev\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/03-nosoftdev.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/03-nosoftdev-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a>As the Nordic FreeRTOS sample does not include the necessary configuration parameters for the softdevice, select &#8220;Softdevice: None&#8221; before proceeding to the next page. You can still use FreeRTOS with softdevice-enabled projects, however you would need to ensure that they include both FreeRTOS and Softdevice configuration files.<\/li>\n<li>On the next page select &#8220;Show basic samples&#8221; and pick the LEDBlink (FreeRTOS) sample and proceed with the default configuration:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/04-board.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3690\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/04-board.png\" alt=\"04-board\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/04-board.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/04-board-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Connect your\u00a0development board to\u00a0your computer. VisualGDB will automatically detect the best debug settings for the board. If you have multiple boards, or debug interfaces, select the matching one manually:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/05-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3691\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/05-debug.png\" alt=\"05-debug\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/05-debug.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/05-debug-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the project. VisualGDB will create an MSBuild-based project based on the FreeRTOS sample. Build it by pressing Ctrl-Shift-B and start debugging by pressing F5:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/06-run.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3692\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/06-run.png\" alt=\"06-run\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/06-run.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/06-run-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/06-run-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>Now we will\u00a0use the RTOS analysis\u00a0functionality to understand how\u00a0the sample works. First of all,\u00a0set a breakpoint in the led_toggle_timer_callback() function and\u00a0open the Threads view once the breakpoint hits:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/07-threads.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3693\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/07-threads.png\" alt=\"07-threads\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/07-threads.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/07-threads-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/07-threads-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a>VisualGDB will\u00a0show all\u00a0FreeRTOS threads (and their stacks) in the Threads view.<\/li>\n<li>Now we will use the\u00a0VisualGDB profiler to see\u00a0which functions are called by each thread (RTOS thread view and profiling requires the Custom edition of VisualGDB). Select Analyze-&gt;Analyze Performance with VisualGDB:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/08-profile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3694\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/08-profile.png\" alt=\"08-profile\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/08-profile.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/08-profile-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/08-profile-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>VisualGDB\u00a0profiler works by inserting the profiler framework code into your project and instrumenting the functions in your code to report their timing. This doesn&#8217;t require any extra hardware, although results in an extra overhead while profiling.\u00a0\u00a0First time you select &#8220;Analyze Performance with VisualGDB&#8221;, it will suggest referencing the profiler framework and preparing the code for instrumentation. Select &#8220;Instrumentation&#8221; in the message box:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/09-instr.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3695\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/09-instr.png\" alt=\"09-instr\" width=\"730\" height=\"164\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/09-instr.png 730w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/09-instr-300x67.png 300w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/a><\/li>\n<li>Once the\u00a0profiler framework is referenced, select &#8220;Instrument functions to record their time&#8221; and press OK:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/10-instr-run.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3696\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/10-instr-run.png\" alt=\"10-instr-run\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/10-instr-run.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/10-instr-run-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/10-instr-run-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>VisualGDB will start a profiling session. Use the Live Profiling view to see the\u00a0functions that are being invoked at real time. See how most of the\u00a0the time is spent in the prvIdleTask:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/11-stats.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3697\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/11-stats.png\" alt=\"11-stats\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/11-stats.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/11-stats-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/11-stats-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>Once you exit a profiling session, you can use the Profiling\u00a0Reports window to\u00a0list and open the\u00a0profiling reports from previous profiling sessions:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/12-report.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3698\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/12-report.png\" alt=\"12-report\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/12-report.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/12-report-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/12-report-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>Although profiling provides detailed view of your\u00a0program&#8217;s internals,\u00a0instrumenting\u00a0each and every function results in overhead.\u00a0An less intrusive way of analyzing your program&#8217;s\u00a0performance would be\u00a0using the real-time watch. Open VisualGDB Project Properties on the Dynamic Analysis page and enable RTOS event tracing and function tracing:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/13-trace.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3699\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/13-trace.png\" alt=\"13-trace\" width=\"1007\" height=\"735\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/13-trace.png 1007w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/13-trace-300x219.png 300w\" sizes=\"(max-width: 1007px) 100vw, 1007px\" \/><\/a>Unlike the profiling mode, functions instrumented\u00a0for real-time watch will only report their actual run time to VisualGDB if you specifically\u00a0add them to the real-time watch window,\u00a0reducing the profiling overhead.<\/li>\n<li>Before you begin\u00a0the real-time watch session, we recommend increasing the MAX_TASK_NAME_LEN parameter in the FreeRTOSConfig.h file to 8 so that the thread names won&#8217;t get truncated:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/14-task.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3700\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/14-task.png\" alt=\"14-task\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/14-task.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/14-task-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/14-task-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>Start debugging and\u00a0select &#8220;Debug-&gt;Break All&#8221; once the LEDs start blinking. Open real-time watch, select &#8220;RTOS threads&#8221; and resume debugging. VisualGDB will show the precise timing of all 3 threads and the computed CPU utilization:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/15-times.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3701\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/15-times.png\" alt=\"15-times\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/15-times.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/15-times-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/15-times-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>You can\u00a0use the mouse wheel to zoom the real-time watch window, and click-and-drag to measure distances between events:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/16-period.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3702\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/16-period.png\" alt=\"16-period\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/16-period.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/16-period-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/16-period-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>Real-time watch also allows\u00a0measuring run times of specific functions. Add the <strong>led_toggle_timer_callback()<\/strong> and <strong>bsp_board_led_invert<\/strong> functions to the real-time watch list and resume your program. VisualGDB will show\u00a0their riming. E.g. you can see that <strong>bsp_board_led_invert<\/strong> is called by both the timer thread and the LED0 thread:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/17-functions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3703\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/17-functions.png\" alt=\"17-functions\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/17-functions.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/17-functions-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/17-functions-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>Zoom into the invocation of <strong>bsp_board_led_event<\/strong> to\u00a0measure the time between different events (e.g. between switching to the Tmr Svc thread and actually invoking the function):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/18-overheads.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3704\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/18-overheads.png\" alt=\"18-overheads\" width=\"1090\" height=\"704\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/18-overheads.png 1090w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/18-overheads-300x194.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/18-overheads-1024x661.png 1024w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/a><\/li>\n<li>You can add a reference to FreeRTOS for an existing project by using the Embedded Frameworks page of VisualGDB Project Properties:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/19-freertos.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3705\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/19-freertos.png\" alt=\"19-freertos\" width=\"786\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/19-freertos.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/02\/19-freertos-300x227.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the FreeRTOS real-time\u00a0operating system with the Nordic nRF5x devices. We will show how to<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[67,95],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3686"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=3686"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3686\/revisions"}],"predecessor-version":[{"id":3706,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3686\/revisions\/3706"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=3686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=3686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=3686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}