loading
I'm not a huge fan of Microsoft, but man, they do make one slick programming IDE.  In searching around for a solution to use the IDE to program AVR's I came across some scattered instructions.  As I love the intellisense feature of Visual Studio (VS) that automatically makes suggestions for class methods and structure functions and members, I tend to use the IDE when working in largish-sized AVR projects.

This brief instructable will show you how to setup Visual Studio 2008/2010 to use WinAVR and compile your AVR programs into Intel Hex format suitable for uploading to your AVR/Arduino with AVRDUDE and your favorite programmer.

P.S.  Don't forget that if there is an "i" in the upper corner of the picture, you can click it and select a a larger image!

Step 1: Create Your Makefile Project

Open Visual Studio 2010 and create a new Makefile project.
Select File->New->Project
Then select Visual C Projects and scroll until you see Makefile Project.
Select Makefile project, select a name for your project and whether you want VS to create a directory and import into Subversion or another version control management system.
Click Ok

Configure via Wizard
You will get a wizard dialog to create the Makefile project.
Select next to go to the first real page of the wizard.
In the next dialog (see below), you will fill in several boxes.
  1. For "Build Command Line" type make
  2. For "Clean commands: type make clean
  3. For "Rebuild command line:" type make all
  4. Change the name of the executable file output to the name of your hex file with the hex extension.
  5. In the "Include search path" type the name of the WinAVR include directory.  For me, it's C:\WinAVR\avr\include
Click NEXT.
Select the checkbox that makes the configuration the same for debug and deployment solutions, if not already checked. 
Click NEXT or FINISH.



Step 2: Configure Your Makefile Project

Visual Studio has now created your default Makefile project.  You must configure it a little more before you can start programming.

Select the project and right click to select Properties.

Under General, select Common Language Runtime and select the option for Common Language Runtime Support (/clr).  This option gives you that nifty Intellisense support.

Click on NMake and ensure that your values are there for the make build commands, as well as your output hex file and ensure your include search path has been prepended or appended to the Include Search Path text box.  If not, add it/them now.

Step 3: Create and Add Your Makefile

Create your Makefile the normal way you would under your normal AVR development environment.  If you use Arduino or AVR Studio's included Makefile utility, you can use mine I've included below.  Make sure you change the pertinent options, namely the MCU, FCPU, and TARGET variables, if needed.

Copy or move the Makefile into the second level of your VS directory.  For instance, if your directory structure looks like:

C:\Projects\ExampleAVR\ExampleAVR

be sure to put it in the second directory or wherever your project files are located.  If in doubt, you can create a main.cpp and see where it adds it, then add the Makefile there.

Once you've copied your Makefile into your working directory, add it to the resources tab of your project.
Right click "Resource Files" and select " Add -> Existing Item and browse to your Makefile and select it.  It should now be added as a resource file.  Select the properties tab while your Makefile is selected and change the Type from Document to Makefile.

Step 4: Code, Baby Code...

For this 'ible, I've created a main.cpp with the standard header and forever loop.  I added in a couple of port bit manipulations then compiled using either F6 or Build -> Build Solution.  The options Build -> Rebuild Solution and Build-> Clean Solution also work because you've added in those commands earlier.

Build your hex file with the above commands then program your AVR or Arduino with AVRDUDE from WinAVR like you normally would.

Voila!  A complete working AVR programming environment using Visual Studio with all it's embedded goodiness and intelligence.  Now, what are you waiting for?  Make that next AVR killer app!
<p>Nice tutorial, great.</p><p>When I follow the steps as described on the tutorial I got the following error:</p><p>1&gt;------ Build started: Project: Sidewinder, Configuration: Debug Win32 ------<br>1&gt; 'make' is not recognized as an internal or external command,<br>1&gt; operable program or batch file.<br>1&gt;C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command &quot;make&quot; exited with code 9009.<br>========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========</p><p>I assume the command &quot;make&quot; as defined on &quot; Step 1: Create your Makefile Project, For Build Command Line type <strong>make</strong>&quot; cannot be fined.</p><p>So what can I do about it?</p><p>The first part of the makefile:</p><p>1 # Hey Emacs, this is a -*- makefile<br>-*-</p><p>2 </p><p>3 # AVR-GCC Makefile template,<br>derived from the WinAVR template (which</p><p>4 # is public domain), believed to be<br>neutral to any flavor of &quot;make&quot;</p><p>5 # (GNU make, BSD make, SysV make)</p><p>6 </p><p>7 </p><p>8 MCU = atmega1280</p><p>9 FORMAT = ihex</p><p>10 TARGET =<br>C:\Users\Robert\Documents\Arduino\SidewinderInterface\software</p><p>11 SRC = $(TARGET).c</p><p>12 ASRC = </p><p>13 OPT = s</p><p>14 </p><p>15 # Name of this Makefile (used for<br>&quot;make depend&quot;).</p><p>16 MAKEFILE =<br>C:\Users\Robert\Documents\Arduino\SidewinderInterface\software\Makefile</p><p>17 </p><p>18 # Debugging format.</p><p>19 # Native formats for AVR-GCC's -g are<br>stabs [default], or dwarf-2.</p><p>20 # AVR (extended) COFF requires stabs,<br>plus an avr-objcopy run.</p><p>21 DEBUG = stabs</p><p>22 </p><p>23 # Compiler flag to set the C Standard<br>level.</p><p>24 # c89 - &quot;ANSI&quot; C</p><p>25 # gnu89 - c89 plus GCC extensions</p><p>26 # c99 - ISO C99 standard (not yet fully<br>implemented)</p><p>27 # gnu99 - c99 plus GCC extensions</p><p>28 CSTANDARD = -std=gnu99</p><p>29 </p><p>30 # Place -D or -U options here</p><p>31 CDEFS = -DF_CPU=16000000</p><p>32 </p><p>33 # Place -I options here</p><p>34 CINCS = -I</p><p>35 </p><p>36 </p><p>37 CDEBUG = -g$(DEBUG)</p><p>38 CWARN = -Wall -Wstrict-prototypes</p><p>39 CTUNING = -funsigned-char<br>-funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections<br>-fdata-sections -finline-limit=3 -fno-inline-small-functions<br>-fno-tree-scev-cprop -fno-split-wide-types -fno-jump-tables </p><p>40 LDTUNING =<br>-Wl,--gc-sections,--relax,--print-gc-sections</p><p>41 #CEXTRA = -Wa,-adhlns=$(&lt;:.c=.lst)</p><p>42 CFLAGS = $(CTUNING) $(CDEBUG)<br>$(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)</p>
Nice tutorial! thanks a lot. <br> <br>By the way, where's the MakeFile that you referred to in Step 3?
Thanks! Sorry for the late reply. As for the Makefile I mention, I assumed you'd be creating the makefile based on your project requirements. If you need an example, I could always post one or email you one.
again, nice tutorial :) <br> <br>can you please upload your make-file?
Hi, Thanks for the nice words :) I've uploaded one of my makefiles, but I don't see it yet on the server. If for some reason it hasn't loaded yet I've also put it up here: <a href="http://www.unix-arm.org/Makefile" rel="nofollow">http://www.unix-arm.org/Makefile</a><br> <br> Good luck!
Thanks for the guide but I ran into problems with Intellisense. I have added WinAVR include directory to the search path for IntelliSense but Intellisense is still giving a lot of errors about the codes. But the codes compile without problems. It's annoying and confusing. Do you have a solution for this?
That's happened to me before, too. However, I use a custom-compiled AVRGCC on windows and not WinAVR. These instructions might still be applicable to your setup if you map them to the appropriate directories under WinAVR. My AVRGCC is in C:\avrgcc and I include the following directories:<br><br>\avrgcc\avr\include<br>\avrgcc\avr\include\avr<br>\avrgcc\avr\include\compat<br>\avrgcc\avr\include\util<br><br>Not sure that'll help or not but may be worth a try.<br>Good luck!<br>
And what about gcc error handling by visual studio?
As far as I've used it, it just passes stdout/stderr to the console in VS.
So, do you have to have the real version of Visual Studio 2010 or will the express version work?
I have and used the professional version of VS2010, but the express version will work just fine.<br><br>Good luck!

About This Instructable

47,656views

34favorites

License:

Bio: Gian is a computational biologist and is the Managing Director at Open Design Strategies, LLC. He holds a BA in Molecular/Cellular Biology and an ... More »
More by nevdull:Create A Custom Medieval-/Fantasy-Style Calligraphy Quill Practical DACs Using Enumerated Types as Bitflags 
Add instructable to: