{"id":4170,"date":"2018-10-15T10:08:27","date_gmt":"2018-10-15T17:08:27","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4170"},"modified":"2018-10-15T10:08:27","modified_gmt":"2018-10-15T17:08:27","slug":"developing-code-for-arm-based-arduino-boards-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arduino\/arm\/","title":{"rendered":"Developing code for ARM-based Arduino boards with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to use the VisualGDB Advanced Arduino\u00a0Project Subsystem to develop projects for ARM-based Arduino-compatible boards. In this tutorial we will create a basic &#8220;Blinking LED&#8221; project for the Arduino Due board and will show how to FLASH it using the built-in bootloader and debug it using Segger J-Link.<\/p>\n<p>Before you begin, install VisualGDB 5.4 Preview 4 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Arduino Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4171\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj1.png\" alt=\"01-newprj\" width=\"941\" height=\"653\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj1.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj1-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj1-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/01-newprj1-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>On the first page of the wizard,\u00a0proceed with the default &#8220;Blinking LED&#8221; choice:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4172\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink2.png\" alt=\"02-blink\" width=\"856\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink2.png 856w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/02-blink2-300x243.png 300w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/li>\n<li>On the next page select your board.\u00a0In this tutorial we will use the Arduino Due board. If\u00a0this is the first time you are creating a project for this platform, VisualGDB will suggest automatically downloading and installing the\u00a0related Arduino packages. Click &#8220;Install&#8221; to proceed with the installation:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-due.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4173\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-due.png\" alt=\"03-due\" width=\"872\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-due.png 872w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/03-due-300x238.png 300w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/a><\/li>\n<li>Once the package is installed, VisualGDB will display a more detailed list of boards reported by the installed package. The Arduino Due board could be programmed either via the programming port (P), or the native USB port (N):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/ports.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4187\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/ports.jpg\" alt=\"ports\" width=\"1186\" height=\"500\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/ports.jpg 1186w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/ports-300x126.jpg 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/ports-1024x432.jpg 1024w\" sizes=\"(max-width: 1186px) 100vw, 1186px\" \/><\/a><\/li>\n<li>In this tutorial we will use the\u00a0native USB port. Connect the board to it and select &#8220;Arduino Due (Native USB Port)&#8221;\u00a0on the Arduino Device page, then select the COM port corresponding to your board:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-port.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4174\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-port.png\" alt=\"04-port\" width=\"872\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-port.png 872w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/04-port-300x238.png 300w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/a><\/li>\n<li>Before we proceed\u00a0with the JTAG debugging setup, we will show how to FLASH the firmware using the Arduino bootloader and use the built-in USB port, so select &#8220;Built-in GDB simulator&#8221; as the debug method:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-nodebug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4175\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-nodebug.png\" alt=\"05-nodebug\" width=\"872\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-nodebug.png 872w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/05-nodebug-300x238.png 300w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to generate the project.\u00a0The created project will be using the Advanced Arduino Project Subsystem that will recognize both the sketch files and the core\/libraries. The Advanced Arduino projects query the\u00a0detailed project structure\u00a0directly from the Arduino build tools, so they show the accurate information in the Solution Explorer and configure IntelliSense to work precisely the same way as the Arduino compiler does. Build the project by pressing Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4176\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build3.png\" alt=\"06-build\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build3.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/06-build3-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>Right-click on the project node in the Solution Explorer and select &#8220;Program FLASH memory&#8221;:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4177\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program3.png\" alt=\"07-program\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program3.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/07-program3-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a>VisualGDB will invoke the Arduino\u00a0programming tools to automatically program the FLASH memory. Once the memory is programmed, the on-board LED will begin to blink.<\/li>\n<li>Now we will\u00a0show how to use the built-in serial port. Replace your sketch contents with the following code:\n<pre class=\"\">#include &lt;HardwareSerial.h&gt;\r\n\r\nvoid setup()\r\n{\r\n    pinMode(LED_BUILTIN, OUTPUT);\r\n    SerialUSB.begin(115200);\r\n}\r\n\r\nint g_Iter = 0;\r\n\r\nvoid loop()\r\n{\r\n    digitalWrite(LED_BUILTIN, HIGH);\r\n    delay(1000);\r\n    digitalWrite(LED_BUILTIN, LOW);\r\n    delay(1000);\r\n \r\n    char tmp[32];\r\n    sprintf(tmp, \"Iteration %d\\r\\n\", g_Iter++);\r\n    SerialUSB.write(tmp);\r\n}<\/pre>\n<p>Then build it via Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-sercode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4178\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-sercode.png\" alt=\"08-sercode\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-sercode.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/08-sercode-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>Open VisualGDB Project Properties and enable the Arduino Serial Terminal (ensure that the baud rate in VisualGDB Project Properties matches the baud rate in the sketch):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-term.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4179\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-term.png\" alt=\"09-term\" width=\"930\" height=\"684\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-term.png 930w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/09-term-300x221.png 300w\" sizes=\"(max-width: 930px) 100vw, 930px\" \/><\/a><\/li>\n<li>Program the FLASH memory again, then right-click in Solution Explorer and select &#8220;Open Serial Terminal&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-openterm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4180\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-openterm.png\" alt=\"10-openterm\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-openterm.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/10-openterm-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>VisualGDB will open a terminal pane\u00a0in Visual Studio window, showing the output from your Arduino sketch:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-termoutput.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4181\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-termoutput.png\" alt=\"11-termoutput\" width=\"954\" height=\"706\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-termoutput.png 954w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/11-termoutput-300x222.png 300w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/li>\n<li>Now we will show how to debug the board. Connect your ARM debugger (e.g. Segger J-Link or Olimex ARM-USB-OCD-H) to the board and plug it into a USB port:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-segger.png\"><br \/>\n<\/a><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/jtagsetup1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4189\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/jtagsetup1.jpg\" alt=\"jtagsetup\" width=\"1209\" height=\"859\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/jtagsetup1.jpg 1209w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/jtagsetup1-300x213.jpg 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/jtagsetup1-1024x728.jpg 1024w\" sizes=\"(max-width: 1209px) 100vw, 1209px\" \/><\/a><\/li>\n<li>Open VisualGDB Project Properties and select the debug probe in the &#8220;Debug\u00a0using&#8221; field:<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4182\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-segger.png\" alt=\"12-segger\" width=\"839\" height=\"555\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-segger.png 839w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/12-segger-300x198.png 300w\" sizes=\"(max-width: 839px) 100vw, 839px\" \/><\/li>\n<li>Press &#8220;OK&#8221; to\u00a0save the new settings and hit F5 to begin debugging. The Advanced Arduino projects will offer the same debugging experience as the regular C\/C++ projects: you will be able to set breakpoints, evaluate variables and step through your code:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-debug1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4191\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-debug1.png\" alt=\"13-debug\" width=\"1174\" height=\"672\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-debug1.png 1174w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-debug1-300x172.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/13-debug1-1024x586.png 1024w\" sizes=\"(max-width: 1174px) 100vw, 1174px\" \/><\/a><\/li>\n<li>You can analyze the memory footprint of your project using the View-&gt;Embedded Memory Explorer command. The default view will show an overview of the RAM and FLASH\u00a0usage:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-eme2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4193\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-eme2.png\" alt=\"14-eme\" width=\"1174\" height=\"674\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-eme2.png 1174w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-eme2-300x172.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/14-eme2-1024x588.png 1024w\" sizes=\"(max-width: 1174px) 100vw, 1174px\" \/><\/a><\/li>\n<li>Click on &#8220;Explore details&#8221; to see a detailed list of functions and global variables together with their sizes and to\u00a0also display them as annotations in your code:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-eme-detail1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4192\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-eme-detail1.png\" alt=\"15-eme-detail\" width=\"1174\" height=\"675\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-eme-detail1.png 1174w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-eme-detail1-300x172.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-eme-detail1-1024x589.png 1024w\" sizes=\"(max-width: 1174px) 100vw, 1174px\" \/><\/a><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/15-eme-detail.png\"><br \/>\n<\/a><\/li>\n<li>The Advanced Arduino Project Subsystem automatically recognizes the libraries\u00a0available on\u00a0the selected platform. Simply include one of the corresponding header files and VisualGDB will automatically\u00a0display them in the Solution Explorer and will index their contents to support commands like Go to Definition, Find All References and Code Map:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-libs1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4194\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-libs1.png\" alt=\"16-libs\" width=\"1174\" height=\"673\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-libs1.png 1174w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-libs1-300x172.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-libs1-1024x587.png 1024w\" sizes=\"(max-width: 1174px) 100vw, 1174px\" \/><\/a><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/08\/16-libs.png\"><br \/>\n<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the VisualGDB Advanced Arduino\u00a0Project Subsystem to develop projects for ARM-based Arduino-compatible boards. In this<\/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,53],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4170"}],"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=4170"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4170\/revisions"}],"predecessor-version":[{"id":4195,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4170\/revisions\/4195"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}