{"id":1661,"date":"2023-09-26T21:09:07","date_gmt":"2023-09-27T04:09:07","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=1661"},"modified":"2023-09-27T15:54:11","modified_gmt":"2023-09-27T22:54:11","slug":"debugging-external-projects-with-embedded-quick-debug","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/quickdebug\/","title":{"rendered":"Debugging External Projects with Embedded Quick Debug"},"content":{"rendered":"<p>This tutorial shows how to quickly debug embedded projects built outside VisualGDB using the Embedded Quick Debug feature introduced in VisualGDB 5.1.<\/p>\n<p>In this tutorial we will show how to build the USB CDC sample for the MCUXpresso SDK for the i.MXRT1050 board using the CMake-based build system from MCUXpresso and will debug it from VisualGDB without converting it to a VisualGDB project.<\/p>\n<p>Before you begin, install VisualGDB 5.1 or later, build the MCUXpresso SDK for your device, and make sure it includes support for the ARM GCC compiler. Install the <a href=\"http:\/\/gnutoolchains.com\/arm-eabi\/\">Sysprogs ARM toolchain<\/a> if you are missing one.<\/p>\n<ol>\n<li>Go to the toolchain binary directory and copy the <strong>make.exe<\/strong> file to <strong>mingw32-make.exe<\/strong>. This is necessary because the KSDK build scripts expect the Make tool to be named like that:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/03-make.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1672\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/03-make.png\" alt=\"03-make\" width=\"721\" height=\"351\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/03-make.png 721w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/03-make-300x146.png 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/a><\/li>\n<li>Open a command prompt window and add both CMake and ARM toolchain directories to PATH. Also set the ARMGCC_DIR variable to the location of your ARM toolchain, e.g.:\n<pre class=\"\">set PATH=%PATH%;C:\\Program Files (x86)\\CMake\\bin;C:\\SysGCC\\arm-eabi\\bin\r\nset ARMGCC_DIR=c:\\sysgcc\\arm-eabi<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/01-start.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8421\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/01-start.png\" alt=\"\" width=\"979\" height=\"512\" \/><\/a><\/li>\n<li>Go to the build directory of the CDC device example (<strong>&lt;SDK&gt;\\boards\\evkbimxrt1050\\demo_apps\\hello_world_virtual_com\\armgcc<\/strong>) and launch the <strong>build_debug.bat<\/strong> script:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/02-built.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8422\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/02-built.png\" alt=\"\" width=\"979\" height=\"512\" \/><\/a>Make sure the build succeeds and take a note of the built executable name (<strong>hello_world_virtual_com.elf<\/strong> in this example)<\/li>\n<li>Now that the example was built successfully, you can debug it from Visual Studio using the VisualGDB Quick Debug feature. Start Visual Studio and select <strong>Debug-&gt;Quick Debug with GDB<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/03-quickdebug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8423\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/03-quickdebug.png\" alt=\"\" width=\"1121\" height=\"742\" \/><\/a><\/li>\n<li>If you already used Quick Debug for other project types, click &#8220;<strong>Add a new preset<\/strong>&#8221; to avoid changing the existing setups:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/04-addnew-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8425\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/04-addnew-1.png\" alt=\"\" width=\"986\" height=\"615\" \/><\/a><\/li>\n<li>Select &#8220;Embedded firmware&#8221;, locate the ELF file built by CMake (<strong>boards\\evkbimxrt1050\\demo_apps\\hello_world_virtual_com\\armgcc\\debug\\hello_world_virtual_com.elf<\/strong>) and provide the following settings:<br \/>\n<table style=\"border-collapse: collapse; width: 100%; height: 120px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">Toolchain<\/td>\n<td style=\"width: 50%; height: 24px;\">ARM<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">Device <strong>(2)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">the debugged device is not listed<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">Initial stop<\/td>\n<td style=\"width: 50%; height: 24px;\">function: main<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">Debug using<\/td>\n<td style=\"width: 50%; height: 24px;\">Segger J-Link<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">Debugged device <strong>(5)<\/strong><\/td>\n<td style=\"width: 50%; height: 24px;\">MIMXRT&#8230;.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/05-setup-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8427\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/05-setup-1.png\" alt=\"\" width=\"986\" height=\"813\" \/><\/a>Ensure you set the &#8220;Save the preset as&#8221; checkbox so that the settings you enter are saved and you won&#8217;t need to enter them next time.<\/li>\n<li>Note that the Quick Debug window has 2 different device selection fields. If you have installed a regular VisualGDB BSP for the device, you can select it in the first field <strong>(2)<\/strong>. VisualGDB will load additional information for it (e.g. hardware register definition) and will automatically filter out incompatible debug methods (e.g. won&#8217;t suggest ESP32 OpenOCD for ARM devices). However, if the SDK is missing or does not contain a complete device definition, VisualGDB may report that there are no compatible debug methods:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/nodevs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8428\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/nodevs.png\" alt=\"\" width=\"939\" height=\"156\" \/><\/a>If this happens, check the &#8220;<strong>The debugged device is not listed<\/strong>&#8221; checkbox and manually select the debug method below. Most debug methods (e.g. Segger J-Link) have their own list of compatible devices that can be selected via the lower field <strong>(5)<\/strong> and does not require installing a VisualGDB BSP.<\/li>\n<li>Connect your board to the USB port and connect the Segger J-Link to it. VisualGDB will program your ELF file into the board and stop at the <strong>main()<\/strong> function:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/06-main.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8430\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/06-main.png\" alt=\"\" width=\"1117\" height=\"738\" \/><\/a> Note the because you did not create a VisualGDB project, the IntelliSense engine won&#8217;t be able to locate all files, so functionality like go-to-definition and automatic highlighting of inactive <strong>#ifdef<\/strong> blocks won&#8217;t work.<\/li>\n<li>Step through the <strong>main()<\/strong> function to verify that the debugging is working:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/07-config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8431\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/07-config.png\" alt=\"\" width=\"1117\" height=\"738\" \/><\/a><\/li>\n<li>Now we will test out the USB functionality. Connect the second USB connector to the board and ensure that the device shows up in the Device Manager:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/usb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1676\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/usb.png\" alt=\"usb\" width=\"774\" height=\"308\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/usb.png 774w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/03\/usb-300x119.png 300w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/a>If Windows does not recognize it, try installing the driver from the &lt;KSDK&gt;\\examples\\frdmkl25z\\demo_apps\\usb\\device\\cdc\\virtual_com\\inf directory.<\/li>\n<li>Set a breakpoint in the <strong>main() <\/strong>function on\u00a0 the line calling <strong>PUTCHAR()<\/strong> and connect to the COM port via <a href=\"http:\/\/smartty.sysprogs.com\/\">SmarTTY<\/a>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/08-smartty.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8432\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/08-smartty.png\" alt=\"\" width=\"674\" height=\"440\" \/><\/a>Observe the &#8220;hello world&#8221; output from the board.<\/li>\n<li>Try typing something in SmarTTY. The breakpoint should trigger and you should see the character you typed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/09-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8433\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/09-bkpt.png\" alt=\"\" width=\"1117\" height=\"738\" \/><\/a><\/li>\n<li>You can step through the code as usual, set breakpoints, view variable values, use Live Watch, etc.:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/10-stepped.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8434\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/04\/10-stepped.png\" alt=\"\" width=\"1117\" height=\"738\" \/><\/a>VisualGDB will automatically save your debugging settings in the Quick Debug setup, so next time you want to debug the same executable, you can simply click <strong>Debug-&gt;Quick Debug with GDB<\/strong> and get a debug session running without having to re-enter anything.<\/li>\n<\/ol>\n<p>If you would like to preserve additional settings (e.g. breakpoints) or have better control over IntelliSense, consider <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/import\/\">importing the project as an externally built one<\/a>. This way you won&#8217;t need to convert the project to the VisualGDB build system (it will just run an arbitrary command line for building it), but can still make use of better IntelliSense or have multiple debugging configurations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to quickly debug embedded projects built outside VisualGDB using the Embedded Quick Debug feature introduced in<\/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,57,82,71],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/1661"}],"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=1661"}],"version-history":[{"count":5,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/1661\/revisions"}],"predecessor-version":[{"id":8436,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/1661\/revisions\/8436"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=1661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=1661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=1661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}