Introduction: Use Visual Studio IDE to Program AVR/Arduino
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
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.
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.
- For "Build Command Line" type make
- For "Clean commands: type make clean
- For "Rebuild command line:" type make all
- Change the name of the executable file output to the name of your hex file with the hex extension.
- In the "Include search path" type the name of the WinAVR include directory. For me, it's C:\WinAVR\avr\include
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
Copy or move the Makefile into the second level of your VS directory. For instance, if your directory structure looks like:
C:\Projects\ExampleAVR\ExampleAVRbe 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!