{"id":4008,"date":"2019-10-24T00:07:37","date_gmt":"2019-10-24T07:07:37","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4008"},"modified":"2021-03-17T08:57:06","modified_gmt":"2021-03-17T15:57:06","slug":"using-iar-arm-compiler-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/iar\/","title":{"rendered":"Using IAR ARM Compiler with Visual Studio and VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to configure VisualGDB to use the IAR ARM compiler instead of the GCC compiler. We will create a basic project from scratch and will show how to configure various parameters of it. For detailed instructions on importing existing projects, follow our <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/import\/iar\/\">IAR project importing tutorial<\/a> instead.<\/p>\n<p>Before you begin, install VisualGDB 5.5 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/01-newprj-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5306\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/01-newprj-1.png\" alt=\"\" width=\"1024\" height=\"710\" \/><\/a><\/li>\n<li>Specify the location and name for the created project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/02-iar-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5307\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/02-iar-1.png\" alt=\"\" width=\"1024\" height=\"710\" \/><\/a><\/li>\n<li>On the first page proceed with the default &#8220;Create a new project -&gt; Embedded Binary -&gt; MSBuild&#8221; option:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/03-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5308\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/03-msbuild.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>VisualGDB can also create GNU Make-based projects using the IAR compiler, however we recommend using MSBuild due to better performance and deeper integration into Visual Studio.<\/li>\n<li>On the next page select the IAR toolchain from the list. VisualGDB will automatically scan it for supported devices and allow simply choosing one from list. Select your device and press &#8220;Next&#8221; to go to the next page of the wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/04-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5309\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/04-target.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>If the IAR compiler is not found, locate and open the <strong>&lt;VisualGDB Directory&gt;\\Rules\\KnownToolchains.xml<\/strong> file. It contains the rules used by VisualGDB to locate the toolchains. E.g. for IAR the following rules will be used:\n<pre class=\"\">\t  &lt;PathDetectionKey&gt;SOFTWARE\\IAR Systems\\Embedded Workbench\\*\\EWARM\\InstallPath&lt;\/PathDetectionKey&gt;\r\n\t  &lt;ValidityTestFile&gt;arm\\bin\\iccarm.exe&lt;\/ValidityTestFile&gt;<\/pre>\n<p>Then verify that your registry contains the path of the IAR compiler as shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/reg.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5310\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/reg.png\" alt=\"\" width=\"1183\" height=\"227\" \/><\/a>If you are using a custom build of IAR that has a different registry path, simply contact our support with more details and we will update the rule file shipped with VisualGDB to locate it as well.<\/li>\n<li>As the IAR compiler itself does not provide any project samples, the sample selection page of the wizard will be empty. Simply click &#8220;Next&#8221; to go to the final page:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/05-nosample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5311\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/05-nosample.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Connect your JTAG\/SWD debugger to your computer and ensure VisualGDB detects it. Then, click &#8220;Finish&#8221; to complete the wizard and generate the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/06-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5313\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/06-debug.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>As the created project is initially empty, building it will result in an error:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/07-fail.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5314\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/07-fail.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a><\/li>\n<li>Use the Add-&gt;New Item context menu command to add a new source file:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/08-addsource.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5315\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/08-addsource.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a><\/li>\n<li>Add the following contents to the newly added file:\n<pre class=\"\">int main()\r\n{\r\n    asm(\"nop\");\r\n}<\/pre>\n<p>The project will now build successfully:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/09-nop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5316\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/09-nop.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a><\/li>\n<li>If the linking fails due to the unsupported &#8220;&#8211;text_out&#8221; parameter, you are likely using an older IAR version that does not support it yet. The parameter is controlled by the\u00a0<strong> Linker -&gt; Output -&gt; Output File Encoding<\/strong> setting under Visual Studio Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/10\/text_out.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7240\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/10\/text_out.png\" alt=\"\" width=\"876\" height=\"544\" \/><\/a>If your IAR compiler does not support it, simply clearing the setting for both configurations will resolve the issue.<\/li>\n<li>Set a breakpoint in <strong>main()<\/strong> and press F5 to start debugging the project. VisualGDB will automatically connect to the target, program it and the breakpoint will trigger:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/10-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5317\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/10-debug.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a><\/li>\n<li>Although IAR produces complex multi-line error messages, VisualGDB can properly recognize them and display the relevant information. E.g. try replacing the code in the main source file with this in order to trigger a template instantiation error:\n<pre class=\"\">template &lt;class _Type&gt;\r\nclass Demo\r\n{\r\n  public:\r\n    void func()\r\n    {\r\n        typename _Type::bad var;\r\n    }\r\n};\r\n\r\nint main()\r\n{\r\n    Demo&lt;int&gt; inst;\r\n    inst.func();\r\n}<\/pre>\n<\/li>\n<li>Try building the project. See how VisualGDB automatically extracts the &#8216;required from &lt;&#8230;&gt;&#8217; line and displays it under the error text:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/11-errors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5318\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/11-errors.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a><\/li>\n<li>Right-click on any error and choose &#8220;Go to build log&#8221;. This will automatically navigate to the corresponding part of the build log, letting you see even more details:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/12-log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5319\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/12-log.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a><\/li>\n<li>Right-click on the project in Solution Explorer and select &#8220;Properties&#8221;. This will open the regular Visual Studio property page window for the project. Note how VisualGDB automatically translated IAR-specific parameters to easily editable MSBuild settings:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/13-optimize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5320\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/13-optimize.png\" alt=\"\" width=\"1297\" height=\"763\" \/><\/a>You can set various properties for any subsets of projects, files or configurations, just like for regular Visual C++-based projects.<\/li>\n<\/ol>\n<p>Now that you got a basic project to build and debug, you can import your existing IAR projects into VisualGDB by following <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/import\/iar\/\">this tutorial<\/a>. Ensure you select the IAR compiler in the wizard while importing the project, as otherwise VisualGDB will use the GCC compiler instead of IAR.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to configure VisualGDB to use the IAR ARM compiler instead of the GCC compiler. We will<\/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,157,41],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4008"}],"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=4008"}],"version-history":[{"count":10,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4008\/revisions"}],"predecessor-version":[{"id":7241,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4008\/revisions\/7241"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}