How to compile an arduino sketch in visual studio using avr-gcc

by Visual Micro 11. April 2010 10:50

The following visual studio arduino compilation overview is for information only and is not required knowlege to make use of the addin

The gcc system is used to compile .hex files (*see note at the end of this document) that you will find in the _vsaddin folder of each project. In this folder you will also find the .bat files that visual micro uses to compile each sketch

When a project has been compiled a folder will be created called _vsaddin\_build. This folder will contain the .o object files from the gcc compiler and also the compiled .elf and .hex files

Prior to compile/rebuild, the addin creates a unique list of include paths from all of the .h files included in the project. These paths are passed to the gcc compiler along with the avr\include folder. 

The list of paths will also include the current projects' reference paths (see visual studio project options). (The arduino addin does not add or alter visual studio project reference paths, it just uses them if they exist)

note: in the initial version using build>solution from the visual studio solution menu fails to compile. Use either the solution rebuild option or use the compile buttons on the addin tool bar

The .\_vsaddin folder

The Build/Compiler Output Window

note: when you compile, if a previous compilation does not exist, you might see some warning messages in the visual studio output window. these can be ignored. the output window will show you if the compilation succeeds

 

arduino visual studio compiler .bat files

The following .bat files are created and maintained automatically by the addin. The events that cause these files to alter are as follows:-

When you switch board

When you add an arduino library

When you compile the project

 

Description of each file

avr_build.rules 

this is a static file containing the definition of the custom build.rules for the project. the file is configured custom build rules on the visual studio project menu 

this file is responsible for providing the GCC_C_AVR and GCC_CPP_AVR custom build tools. when you add .c or .cpp files to your project they should automically be assigned to the respective rule./tool

 

build_all_begin

clear temp files from prev build

build_env.bat

enviroment variables and board/port settings 

build_c_item.bat

called once for each .c file in the project. creates a filename.c.o file using avr-gcc

build_cpp_item.bat

called once for each .cpp file in the project. creates a filename.c.o file using avr-g++

link_all.bat

 

creates a .hex from all the .o files using the avr tools and/or uploads to the arduino using the avr upload tool

 

* The visual studio arduino compile option is provided as way for you to verify that your code is correct. You should not upload the resulting compilations (.hex) to your arduino unless you are happy to void the arduino warranty. These feature(s) are also provided by us without warranty or liability.

 

Arduino Visual Studio Overview

by Visual Micro 10. April 2010 22:21

Beta released 11th April 2010. Free version for private or student use is due for release end April 2010

Intellisense for the arduino is provided by Visual Studio. The 'Visual Micro' add-in simply helps to ensure that the files of a .pde project, the arduino core and arduino libraries are registered (or known) to the Visual Studio intellisense system.

Add-in preferences are set using the "Visual Studio Tools Options" window. When set the add-in will extend the Visual Studio menus and toolbars with additional controls to help you build arduino projects. (Note: all visual studio extensions created by the add-in are temporary)

The add-in is also able to retain board and port settings for each sketch (project). In most cases this means you will select a board and serial port once for the life of each project. That you can work on multiple projects at the same time, each project with its own board and port settings.

The add-in provides many other useful features.
Here are just a few...

> Automatic create new project from sketch

> Automatic link of all project items to intellisense

> Two way sketch compatibility with Arduino IDE

> Option to open the Arduino IDE loading the active visual micro studio project sketch.

> Automatic code completion (Visual Studio Style!)

> One click include of an Arduino Library

> Automatic LINK to arduino cores and libraries.

> When the arduino cores are updated your projects will automatically update (on next use)

> Standard copy/paste, highlight short cut keys

> All short cut keys user-definable

> Multi-instance Serial monitor enabling, for example, the output from two xbees to be monitored easily with auto port close if using the upload tools (see warning notes below about this!)

> Simple one click create of .c;.h with #include added to active .pde;.c or .cpp window.

> Code example helper makes it easy to create your own code examples for your projects.

> Examples/snippets are stored in an xml file in the same location of the code file.

 

 


Whilst not supported by Arduino or ourselves, the add-in allows you to switch on, at your own risk, "Compile and Upload" features. We have tried to ensure that these features are correct for Arduino and have been using our own boards without problem. We have found the Compile and Upload so useful we decided to leave it in the product (at your own risk!).

 

News - 2010

2nd May - Visual Studio 2010 - Navigating the Navigator with ArduPilot

18th April - Supports multiple sketch (pde) files in a single project (ArduPilot)

17th April - Supported on all windows language versions

14th April - First test success

11th April - The arduino visual studio beta was released today

Links and References

Visual Micro Forums here

Visit the Arduino forums here

A different solution here

Bob Powell's solution here

Ardupliot example here