{"id":7747,"date":"2022-01-20T08:42:11","date_gmt":"2022-01-20T16:42:11","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7747"},"modified":"2022-01-20T08:42:11","modified_gmt":"2022-01-20T16:42:11","slug":"using-azure-rtos-with-stm32-devices-and-visualgdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/stm32\/azurertos\/","title":{"rendered":"Using Azure RTOS with STM32 Devices and VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to create, build and debug a basic project using the Azure RTOS (ThreadX) running on an STM32 device with Visual Studio and VisualGDB.<\/p>\n<p>Before you begin, install VisualGDB 5.6R3 or later.<\/p>\n<ol>\n<li>Start Visual Studio, click &#8220;File-&gt;New Project&#8221; and locate the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/11\/01-newprj-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7733\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/11\/01-newprj-3.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Enter the name and location for the newly created project, then click &#8220;Create&#8221; to proceed to the VisualGDB-specific part of the wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7748\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/01-newprj.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Proceed with the default settings on the &#8220;Project Type&#8221; page. We recommend using the Advanced CMake project subsystem for the best results:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/02-cmake.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7749\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/02-cmake.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the next page select the ARM toolchain and pick the device you would like to use: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/03-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7750\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/03-device.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the sample selection page, pick the &#8220;<strong>LEDBlink (AzureRTOS)<\/strong>&#8221; sample. It uses the same structure as the <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/stm32\/freertos\/\">FreeRTOS-based sample<\/a>,\u00a0 creating 2 independent threads, each one controlling one LED. You can configure the LED port\/pins to match your board pinout, or simply proceed with the default values:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/04-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7751\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/04-sample.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the last page of the wizard, pick the debug settings that work with your board and click &#8220;Finish&#8221; to create the project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/05-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7752\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/05-debug.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Once the project has been created, locate the main source file. Note how it contains one function for each thread (<strong>LED_Thread1<\/strong> and <strong>LED_Thread2<\/strong>). You can use Code Explorer to conveniently view the outline of a specific source file, or look through the symbols in the entire project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/06-threads.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7753\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/06-threads.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><\/li>\n<li>Press F5 to build the project and start debugging it. If you have configured the correct LED ports\/pins in the wizard, you will see the LEDs blink. If not, you can confirm that the program is running by locating the <strong>g_TickCount<\/strong> variable in <a href=\"https:\/\/visualgdb.com\/documentation\/livevars\/\">Live Watch<\/a>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/07-ticks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7754\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/07-ticks.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><\/li>\n<li>Pause the graph view in Live Watch and check the rate at which <strong>g_TickCount<\/strong> is incremented. It should be close to 1000 ticks per second:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/08-delta.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7755\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/08-delta.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><\/li>\n<li>If the observed timer frequency is different, adjust the <strong>SYSTEM_CLOCK<\/strong> variable in the <strong>tx_initialize_low_level.S<\/strong> file to match the clock frequency of your board:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/freq.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7758\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/freq.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><\/li>\n<li>Use the <strong>Debug-&gt;Break All<\/strong> command to force the program to stop (alternatively, simply set a breakpoint in one of the thread functions). VisualGDB will automatically recognize and display the ThreadX threads using our open-source <a href=\"https:\/\/github.com\/sysprogs\/RTOSPlugins\/tree\/master\/ThreadXPlugin\">ThreadX plugin<\/a> (requires the Custom edition or higher):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/09-stop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7756\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/09-stop.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><\/li>\n<li>You can select any thread in the Threads window and use the Call Stack window to see what exactly it was doing before the execution switched to another thread. In this example, both threads were waiting via a call to <strong>tx_thread_sleep()<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/10-stack.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7757\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/10-stack.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><\/li>\n<li>You can use the Globals view in VisualGDB Code Explorer to quickly explore the relations between different parts of your code (and the AzureRTOS), and locate the relevant functions, variables or types. E.g. try searching for <strong>TX_THREAD<\/strong> in the main Code Explorer window, and expanding the details to show references. VisualGDB will show all functions and structs that have a parameter (or field) of this type: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/refs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7759\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/01\/refs.png\" alt=\"\" width=\"1157\" height=\"688\" \/><\/a><a href=\"https:\/\/visualgdb.com\/documentation\/codeexplorer\/globals\/\">Code Explorer<\/a> can also quickly explore the call tree, inheritance tree, or find functions allocating\/deleting specific types.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create, build and debug a basic project using the Azure RTOS (ThreadX) running on an<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[53,244,61],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7747"}],"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=7747"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7747\/revisions"}],"predecessor-version":[{"id":7760,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7747\/revisions\/7760"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}