{"id":30142,"date":"2022-03-10T00:01:39","date_gmt":"2022-03-10T00:01:39","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=30142"},"modified":"2022-03-10T00:01:39","modified_gmt":"2022-03-10T00:01:39","slug":"vscode-embedded-development","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/vscode-embedded-development\/","title":{"rendered":"Embedded Software Development in Visual Studio Code"},"content":{"rendered":"<p>We are happy to announce that we have released the Embedded Tools extension for Visual Studio Code. These capabilities are the same as what we recently announced for <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/visual-studio-embedded-development\/\">Visual Studio 2022<\/a>. Used in conjunction with the new <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/vcpkg-artifacts\/\">vcpkg artifact capabilities<\/a> you can quickly bootstrap an embedded development machine and get started.<\/p>\n<p>In this post we will walk you through how to acquire embedded tool dependencies with vcpkg, then demonstrate edit, build, deploy, and debugging directly in VS Code with new peripheral register and RTOS object views. We will demonstrate all of this with an Azure RTOS ThreadX project.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30146\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded.png\" alt=\"VS Code embedded development screenshot\" width=\"1671\" height=\"1044\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded.png 1671w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded-300x187.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded-1024x640.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded-768x480.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vscode_embedded-1536x960.png 1536w\" sizes=\"(max-width: 1671px) 100vw, 1671px\" \/><\/a><\/p>\n<p>Azure RTOS ThreadX is a widely used Real Time Operating System (RTOS) used on billions of microcontrollers (MCUs) in products around the world. We have dedicated pages for VS Code usage in the getting started guides for the <a href=\"https:\/\/github.com\/azure-rtos\/getting-started\/blob\/master\/MXChip\/AZ3166\/vscode.md\">Azure IoT DevKit<\/a>, <a href=\"https:\/\/github.com\/azure-rtos\/getting-started\/blob\/master\/NXP\/MIMXRT1060-EVK\/vscode.md\">NXP 1060<\/a>, and STMicro STM32L4_L4+ IOT01A boards (<a href=\"https:\/\/github.com\/azure-rtos\/getting-started\/blob\/master\/STMicroelectronics\/B-L475E-IOT01A\/vscode.md\">L475E<\/a> or <a href=\"https:\/\/github.com\/azure-rtos\/getting-started\/blob\/master\/STMicroelectronics\/B-L4S5I-IOT01A\/vscode.md\">L4S5I<\/a>). The techniques used for interacting with these boards should be applicable to other targets by changing configuration information we\u2019ll highlight throughout.<\/p>\n<h4>Installation<\/h4>\n<p>To get started install VS Code, then in the extensions side bar search for Embedded Tools and install it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_embedded_tools.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30147\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_embedded_tools.png\" alt=\"Embedded Tools extension page screenshot\" width=\"624\" height=\"167\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_embedded_tools.png 624w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_embedded_tools-300x80.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<h4>Using vcpkg to acquire embedded tools<\/h4>\n<p>One of the challenges in embedded development is getting the tools necessary installed and configured. It is not uncommon to have different compilers used for different projects, custom debug tools, etc. This is where the new <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/vcpkg-artifacts\/\">artifact capabilities in vcpkg<\/a> \u00a0can help us. Today we\u2019ll demonstrate using vcpkg from a PowerShell prompt to activate our embedded development environment, but you can use the shell you prefer on your platform. In a future release this will be integrated into a Visual Studio Code extension for a more seamless experience.<\/p>\n<p>From a PowerShell prompt, clone the Azure RTOS getting started repo. This sample will serve as our example project for the remainder of this post.<\/p>\n<pre>git clone --recursive https:\/\/github.com\/azure-rtos\/getting-started.git<\/pre>\n<p>Navigate to the subfolder for the board you are using, here I\u2019m using the Azure IoT DevKit.<\/p>\n<pre>cd .\/getting-started\/MXChip\/AZ3166<\/pre>\n<p>If you haven\u2019t already, install vcpkg.<\/p>\n<p>Linux\/macOS<\/p>\n<pre>. &lt;(curl https:\/\/aka.ms\/vcpkg-init.sh -L)<\/pre>\n<p>PowerShell<\/p>\n<pre>iex (iwr -useb https:\/\/aka.ms\/vcpkg-init.ps1)<\/pre>\n<p>CMD Shell<\/p>\n<pre>curl -LO https:\/\/aka.ms\/vcpkg-init.cmd &amp;&amp; .\\vcpkg-init.cmd<\/pre>\n<p>In the project folder, there is a file vcpkg_configuration.json. This manifest file was created with vcpkg and has recorded the tools you need to build and debug this project. See the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/vcpkg-artifacts\/\">vcpkg artifacts post<\/a> for details on how to create your own manifest. Running the vcpkg activate command will use this file to determine if I have those tools, install them if I do not, then activate them in my environment for use.<\/p>\n<pre>vcpkg activate<\/pre>\n<p>So, in three commands we have cloned our embedded project, installed vcpkg, acquired and activated the necessary tools for building the project.<\/p>\n<h4>Using VS Code for embedded development<\/h4>\n<p>In the previous section we used vcpkg to acquire the tools for our embedded project. Today vcpkg is not integrated in Visual Studio Code. So, at present we need to launch VS Code from the environment we activated at the command line so those tools are available for its use as well.<\/p>\n<pre>code .<\/pre>\n<p>Now that we have the project open in VS Code it is ready to go as any other CMake project. <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cmake-presets-integration-in-visual-studio-and-visual-studio-code\/\">VS Code can run the CMake build using the preconfigured CMakePresets file<\/a> with the compilers vcpkg acquired. Select the preset arm-gcc-cortex-m4 when prompted on opening the folder.<\/p>\n<p>All the editing power of VS Code is now available for use with the embedded project. With this Azure RTOS project we\u2019ll cover code navigation, IntelliSense, build, deploy, debugging. We\u2019ll also cover new diagnostic capabilities around peripheral registers and RTOS object views.<\/p>\n<h5>Code Navigation and IntelliSense<\/h5>\n<p>Use Ctrl + T to open symbol search and type button_a_callback, select the button_a_callback function to navigate to it. Note on hover that this function expands to TIM3-&gt;CCR1 which is a peripheral register on the board which we\u2019ll inspect while we are debugging.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_inspectregdef.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30148\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_inspectregdef.png\" alt=\"IntelliSense function expansion screenshot\" width=\"538\" height=\"327\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_inspectregdef.png 538w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_inspectregdef-300x182.png 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/a><\/p>\n<h5>Build, Deploy, and Debug on hardware<\/h5>\n<p>Set a breakpoint on RGB_LED_SET_R().<\/p>\n<p>To see how the launch is controlled in the sidebar open .vscode\/launch.json and look at the launch configuration. You can see the miDebuggerPath set to use arm-none-eabi-gdb while the debugServerPath is set to invoke openocd with the configuration script in debugServerArgs. The information for describing peripheral registers is provided by the MCU manufacturer in an SVD file that we point to with svdPath. This project is configured to break on entry with the property stopAtConnect.<\/p>\n<p>Now, with your board plugged into the PC with <a href=\"https:\/\/www.st.com\/en\/development-tools\/stsw-link009.html\">ST-LINK drivers installed<\/a>, select the debug icon in the activity bar and make sure Run and Debug is set to Launch. Now F5 will work using openocd acquired by vcpkg to flash and debug the attached board. Execution stops at the entry function, so here we see the assembly code for that. We can also view the disassembly by right clicking the function in the call stack window, Open Disassembly View.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_assemblyonentry.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30149\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_assemblyonentry.png\" alt=\"Assembly source and disassembly screenshot\" width=\"1047\" height=\"177\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_assemblyonentry.png 1047w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_assemblyonentry-300x51.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_assemblyonentry-1024x173.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_assemblyonentry-768x130.png 768w\" sizes=\"(max-width: 1047px) 100vw, 1047px\" \/><\/a><\/p>\n<p>Press continue to let execution continue.<\/p>\n<h5>Peripheral Registers<\/h5>\n<p>Now press the A button on the board. This has triggered our breakpoint. We can now go to the command palette Ctrl + Shift + P \u00a0and enter \u201cperipheral\u201d, select Focus on Peripheral View View. This opens the peripheral register view using the information from our SVD file specified in the launch configuration. We can now scroll through this list to find the register we are interested in, here TIM3-&gt;CCR1 which will update when we step over the RGB_LED_SET_R function.<\/p>\n<p>On break<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regbefore_new.png\"><img decoding=\"async\" class=\"alignnone wp-image-30259 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regbefore_new.png\" alt=\"Register before stepping\" width=\"847\" height=\"405\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regbefore_new.png 847w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regbefore_new-300x143.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regbefore_new-768x367.png 768w\" sizes=\"(max-width: 847px) 100vw, 847px\" \/><\/a><\/p>\n<p>After stepping<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regafter_new.png\"><img decoding=\"async\" class=\"alignnone wp-image-30260 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regafter_new.png\" alt=\"Register after stepping\" width=\"898\" height=\"410\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regafter_new.png 898w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regafter_new-300x137.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_regafter_new-768x351.png 768w\" sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/a><\/p>\n<h5>RTOS Object Views<\/h5>\n<p>VS Code threads view won\u2019t show you the threads in our Azure RTOS application. Why not? A good explanation can be found in this <a href=\"https:\/\/azure.microsoft.com\/resources\/real-time-operating-system\">white paper on Real Time Operating Systems<\/a>.<\/p>\n<p>\u201cA Real-Time Operating System is system software that provides services and manages processor resources for applications. These resources include processor cycles, memory, peripherals, and interrupts. The main purpose of a Real-Time Operating System is to allocate processing time among various duties the embedded software must perform. This typically involves a division of the software into pieces, commonly called \u201ctasks\u201d or \u201cthreads,\u201d and creating a run-time environment that provides each thread with its own virtual microprocessor (\u201cMultithreading\u201d). Basically, a virtual microprocessor consists of a virtual set of microprocessor resources, e.g., register set, program counter, stack memory area, and a stack pointer. Only while executing does a thread use the physical microprocessor resources, but each thread retains its own copy of the contents of these resources as if they were its own private resources (the thread\u201ds \u201ccontext\u201d).\u201d<\/p>\n<p>So for embedded development ideally you would have views that could show you information about these RTOS objects. To see the new available RTOS objects views, go to the command palate Ctrl + Shift + P\u00a0 and enter \u201crtos\u201d then select Focus on RTOS viewer view<\/p>\n<p>This will open the threads view that shows at a glance much of the information you would commonly need during embedded development, thread ids and names, how many times they have run, where the stack starts, ends, and its size as well as the maximum stack usage.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_RTOSthreads.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30153\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_RTOSthreads.png\" alt=\"RTOS threads window\" width=\"1277\" height=\"167\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_RTOSthreads.png 1277w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_RTOSthreads-300x39.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_RTOSthreads-1024x134.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_RTOSthreads-768x100.png 768w\" sizes=\"(max-width: 1277px) 100vw, 1277px\" \/><\/a><\/p>\n<p>There are other views for additional ThreadX objects like block and byte pools, events, mutexes, queues, and timers. You can find these by selecting the three dots in the RTOS Viewer panel.<\/p>\n<p>We also have RTOS object views for FreeRTOS though the available objects there differ based on what it supports.<\/p>\n<h5>Hardware breakpoint limits<\/h5>\n<p>One last debugging capability to call out is that embedded hardware targets commonly have a limited set of hardware breakpoints available. Setting too many can corrupt the debugger state. As such we have added hardwareBreakpoints to launch.json. For this board that is set to what it supports which is 6. If we set more than that we will see the breakpoint is not set but will show as a gray empty circle.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_hwbreakpoint.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30154\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_hwbreakpoint.png\" alt=\"Hardware breakpoint example screenshot\" width=\"328\" height=\"66\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_hwbreakpoint.png 328w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/03\/vsc_hwbreakpoint-300x60.png 300w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/a><\/p>\n<p>If you mouse over the breakpoint in the breakpoints view you will see a warning that it won\u2019t be hit. This prevents corrupting the connection to the board and allows us the opportunity to unset some other breakpoints and continue debugging uninterrupted.<\/p>\n<h4>Send us your feedback<\/h4>\n<p>We hope that these new capabilities will enable you to choose VS Code for your embedded development needs and make you more productive. We are very interested in your feedback to continue to improve this experience. The comments below are open, or you can find us on Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>), or via email at <a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we will walk through the new Visual Studio Code Embedded Tools extension. We&#8217;ll show how to acquire embedded tool dependencies with vcpkg then edit, build, deploy, and debug an Azure RTOS ThreadX project highlighting the new peripheral register and RTOS object views.<\/p>\n","protected":false},"author":677,"featured_media":30146,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3903,317,230],"tags":[],"class_list":["post-30142","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded","category-iot","category-new-feature"],"acf":[],"blog_post_summary":"<p>In this post we will walk through the new Visual Studio Code Embedded Tools extension. We&#8217;ll show how to acquire embedded tool dependencies with vcpkg then edit, build, deploy, and debug an Azure RTOS ThreadX project highlighting the new peripheral register and RTOS object views.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/677"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=30142"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30142\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/30146"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=30142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=30142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=30142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}