{"id":4121,"date":"2018-10-01T09:14:58","date_gmt":"2018-10-01T16:14:58","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4121"},"modified":"2019-05-21T11:23:18","modified_gmt":"2019-05-21T18:23:18","slug":"debugging-arduino-avr-boards-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arduino\/avr\/debug\/","title":{"rendered":"Debugging Arduino AVR boards with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to debug the AVR-based Arduino boards using Visual Studio and the Advanced Arduino Project Subsystem of VisualGDB. Before you begin, install VisualGDB 5.4 Preview 4 or later, get an AVR debug probe (e.g. AVR Dragon) and follow\u00a0our\u00a0<a href=\"https:\/\/visualgdb.com\/tutorials\/arduino\/\">basic Arduino tutorial<\/a> to create a simple project.<\/p>\n<p><strong>Warning: due to the limitations of the AVR architecture, the AVR devices need to be explicitly switched between the production mode (DWEN fuse not set) and the debug mode (DWEN fuse set). Enabling the debug mode makes regular FLASH programming via bootloader unusable; disabling it makes the debugging impossible. For all\u00a0new designs, we\u00a0recommend using ARM-based or ESP32-based devices\u00a0that don&#8217;t have this limitation. If you\u00a0are already using an AVR-based Arduino board, follow the instructions in this tutorial to enable and disable the debug mode.<\/strong><\/p>\n<ol>\n<li>The original Arduino Uno board contains\u00a0a capacitor that\u00a0facilitates\u00a0resetting the board into bootloader programmatically, however\u00a0this capacitor\u00a0prevents the AVR debug probes from debugging the board properly. Before we proceed with debugging, we need to modify the board to allow\u00a0disconnecting the capacitor. Locate the &#8220;RESET-EN&#8221; pad on the board (see the\u00a0<a href=\"https:\/\/www.arduino.cc\/en\/uploads\/Main\/arduino-uno-schematic.pdf\">schematic<\/a>) and cut the line between the 2 pads. Then solder\u00a0a pair of jumper terminals to the pads:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-jumper.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4134\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-jumper.jpg\" alt=\"01-jumper\" width=\"1280\" height=\"875\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-jumper.jpg 1280w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-jumper-300x205.jpg 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-jumper-1024x700.jpg 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-jumper-130x90.jpg 130w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a>As long as the jumper is not installed, the board can be debugged using an AVR debug probe, however\u00a0programming FLASH memory via a bootloder won&#8217;t work. Installing the jumper will prevent debugging, but will restore the original\u00a0bootloader functionality.<\/li>\n<li>Connect your AVR debug probe to the ICSP connector on the Arduino Uno board:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-jtag1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4136\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-jtag1.jpg\" alt=\"02-jtag\" width=\"1280\" height=\"931\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-jtag1.jpg 1280w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-jtag1-300x218.jpg 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-jtag1-1024x745.jpg 1024w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a><\/li>\n<li>The last step required before we can proceed with debugging is\u00a0to program the DWEN fuse on the device. The easiest way to do this is via\u00a0the Tools-&gt;Device Programming command in Atmel Studio:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/00-tdp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4123\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/00-tdp.png\" alt=\"00-tdp\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/00-tdp.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/00-tdp-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>Select your AVR probe and the device (ATmega328P for AVR Uno) and click &#8220;Apply&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-studio-connect.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4124\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-studio-connect.png\" alt=\"01-studio-connect\" width=\"746\" height=\"593\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-studio-connect.png 746w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-studio-connect-300x238.png 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/a><\/li>\n<li>Then set the &#8220;HIGH.DWEN&#8221; fuse and click &#8220;Program&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-program.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4125\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-program.png\" alt=\"02-program\" width=\"746\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-program.png 746w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-program-300x258.png 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/a><\/li>\n<li>Click &#8220;Continue&#8221; to confirm programming:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-confirm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4126\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-confirm.png\" alt=\"03-confirm\" width=\"436\" height=\"353\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-confirm.png 436w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-confirm-300x243.png 300w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/a><\/li>\n<li>Once the Arduino Uno board is configured for programming,\u00a0open your VisualGDB project\u00a0from the <a href=\"https:\/\/visualgdb.com\/tutorials\/arduino\/\">basic AVR tutorial<\/a>. Then\u00a0open VisualGDB Project Properties, go to the Debug Settings page and select your debug probe. Ensure you set <strong>Debug Interface<\/strong> to <strong>DebugWire<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4127\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-config.png\" alt=\"04-config\" width=\"863\" height=\"685\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-config.png 863w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-config-300x238.png 300w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/a><\/li>\n<li>Set a breakpoint in the loop()\u00a0function and press F5 to begin debugging:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4128\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-debug.png\" alt=\"05-debug\" width=\"1251\" height=\"786\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-debug.png 1251w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-debug-300x188.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-debug-1024x643.png 1024w\" sizes=\"(max-width: 1251px) 100vw, 1251px\" \/><\/a>As long as the AVR board is properly setup for debugging,\u00a0VisualGDB will\u00a0provide the same debugging experience as with any other supported target. The FLASH memory will be\u00a0automatically programmed and VisualGDB will let you set breakpoints and step\u00a0through your code. However,\u00a0while the AVR chip is in the debugging mode, it will only run with a debugger connected and won&#8217;t let\u00a0you use the bootloader for programming the FLASH memory.<\/li>\n<li>To\u00a0turn the debug mode off, go back to Atmel Studio and create an empty project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-pseudoprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4129\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-pseudoprj.png\" alt=\"06-pseudoprj\" width=\"786\" height=\"558\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-pseudoprj.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-pseudoprj-300x213.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>Select your\u00a0AVR chip in the Device Selection dialog:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4130\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-target.png\" alt=\"08-target\" width=\"752\" height=\"524\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-target.png 752w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-target-300x209.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-target-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-target-130x90.png 130w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/a><\/li>\n<li>Open Debug Settings, pick your debug probe and ensure &#8220;Skip programming&#8221; is selected:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-skipprog.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4131\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-skipprog.png\" alt=\"09-skipprog\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-skipprog.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-skipprog-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>Start a debugging session, then click &#8220;Debug-&gt;Disable debugWIRE and Close&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-disable.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4132\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-disable.png\" alt=\"10-disable\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-disable.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-disable-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>If the &#8220;Disable debugWIRE and Close&#8221; command doesn&#8217;t appear, ensure you have the advanced profile enabled via Tools-&gt;Select Profile:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-profile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4133\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-profile.png\" alt=\"11-profile\" width=\"617\" height=\"287\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-profile.png 617w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-profile-300x140.png 300w\" sizes=\"(max-width: 617px) 100vw, 617px\" \/><\/a><\/li>\n<li>Finally, set the jumper\u00a0between the &#8220;RESET-EN&#8221; terminals to restore the bootloader functionality:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-jumper-on.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4137\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-jumper-on.jpg\" alt=\"03-jumper-on\" width=\"1280\" height=\"974\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-jumper-on.jpg 1280w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-jumper-on-300x228.jpg 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-jumper-on-1024x779.jpg 1024w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a><\/li>\n<li>Now Arduino Uno will run normally without the debugger and you will be able to use the regular &#8220;Program FLASH&#8221; memory command again to program the memory using the bootloader.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug the AVR-based Arduino boards using Visual Studio and the Advanced Arduino Project Subsystem of<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[170,171],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4121"}],"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=4121"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4121\/revisions"}],"predecessor-version":[{"id":4656,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4121\/revisions\/4656"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}