This post describes how to use ATMEL Studio 6 instead of the Arduino IDE to build applications. It presumes a certain level of knowledge and experience.
EDIT : Ive updated this post to refer to Atmel Studio 6 instead of AVR Studio 5, so many of the posts below should be read with that in mind ( ie problems with 5.0)

On his excellent website, Smiley http://www.smileymicros.com tries to persuade us to leave behind the Arduino libraries, the vast numbers of samples, and to convert to a "better way". (Hope Im not misquoting him!) While I see some advantages in this approach, in my case I had already half developed some applications and I didn't want to start again.

So I could stick with the Arduino IDE, but it was driving me crazy. A great way to start: copy and paste some example code into my "sketch", press upload and then bingo, the LED fashes. But Ive grown to dislike it. Its slow. It has no intellisense. The IDE sucks. I disliked the extra pass it makes to change my code in strange ways. (Thats fixed now though). There's no debugger. There are other things i dislike but they are of a petty nature; the first five are enough. So I went looking for alternatives, and came to think there are two, Eclipse or Visual Studio (ATMEL Studio 6 to be precise).

First off those that like Eclipse have it sorted I believe. You can read how to use Eclipse for Arduino here: http://arduino.cc/forum/index.ph... Ive used Eclipse to write code for my wifes Android phone "“ its pretty good. If you want cross platform, thats an obvious winner. But Ive been writing C++ with Visual Studio for longer than I care to admit (been in computing since 1973, which would trump most of the readers of this forum I would think), and for me, Visual Studio and Visual Assist is a winning combination (Visual Assist is great but not free). So I wanted to use VS. I went down a lot of tangents because Google led me to a lot of information that is no longer relevant. I had to especially make sure I didn't bother too much reading about WinAVR AVRStudio 5 or anything related to AVRStudio4. I havent used VisualMicro recently but I cant see the need for it.

My original post decribed AVR Studio 5 and how to use it. But there were annoying bugs, these have been fixed in version 6.

ATMEL Studio 6 is a winner.

When AVR Studio 5 got launched it looked to be perfect for me. BUT, it didn't support C++ all that well. They've fixed that now ( very recently) "“just install the C++ Extension which as of August 2011 is a beta release. Installation is through AVR Studio 5 Tools menu:
Tools -> Extension Manager -> Online Gallery -> AVRGCC CPP(Beta)
Ive found two minor bugs "“ more on that later.

The biggest challenge was to work out how to use the core Arduino libraries. You need to tell it where to find the headers, and setting the directories was easy enough. I had originally installed the Arduino IDE(version 22) to C:\arduino, so I just added C:\arduino\hardware\arduino\cores\arduino to my directories for the C++ compiler (Properties of the solution/ Toolchain). While I was at it, I added the folder for each of the libraries I wanted to use. To start off, I took a copy of the main source file with the PDE extension and gave it a CPP extension).

Almost there, but getting it to link proved harder.

Now when you use the Arduino IDE it builds a library from all the core source code "“ eg the code for Serial. This library gets built each time ( did I mention that I dislike how slow it is), and squirrels it away into a funny place that is difficult to find.(look for a folder with a name like C:\Users\fred\AppData\Local\Temp\build5690015305384173079.tmp) I grabbed a copy of it from there so I could use it as part of my VS project. Its name is libcore.a and I copied it to a place where all my projects live C:\Users\fred\Documents\Arduino

I then went to the "Toolchain\AVR/GNU C++ Linker\Miscellaneous" tab and added this
-Wl,-lcore -Wl,-L"C:\Users\fred\Documents\Arduino"

In version 5, one had to tweak the makefile to get past linker errors, but thankfully that is a thing of the past.

Now after adding this one line:
Serial.println("Start of loop");
everything builds.

I got this command from a verbose output from the Arduino IDE. But wow, I don't know why so many ""“v"options, where did they come from and what are they for? Anyway, it works, and so I made a button to do the upload and now its a simple click.

Finally I got nifty with the source code, so I can still compile things in the Arduino IDE if I really want to. ( Basically I gutted the source file with the PDE suffix and put everything in other source files)

In summary, was this worth the effort? Quite honestly, yes it was. My new environment is much faster and much more productive. The niggly problems got sorted by the AVR team - thanks - and now I have the best of both worlds.

A win!

This gives you a quick overview "“ Ive left out an awful lot of detail. And since this original post, others have described the process in more detail - eg http://www.jayconsystems.com/tut...

Suffice to say it is well worth doing.

[this is great stuff so I made it into a permanent tutorial - moderator]

Great post. I did all you said, but I'm still getting the undefined reference errors during link. I moved the -Wl, -lcore etc etc to the end of the Makefile, but stil the errors are there. Any other things I can try ?

On his excellent website, Smiley http://www.smileymicros.com tries to persuade us to leave behind the Arduino libraries, the vast numbers of samples, and to convert to a â€œbetter wayâ€. (Hope Im not misquoting him!) While I see some advantages in this approach, in my case I had already half developed some applications and I didnâ€™t want to start again.

The blog entry is at:http://smileymicros.com/blog/201...
And I want to be clear, I love the Arduino and I think it is absolutely the best solution for the novice and even for the professional wanting to make quick tests. That said, I felt that the Arduino libraries were lacking some important functionality that in order to implement one really needed to move on to regular C programming and the standard tools: AVRStudio, WinAVR, and avrdude.

I've been too scared to try AS5 so I'll have to take this tutorial as validation that it actually works on something. The other issue here is C++ which I've yet to be convinced makes sense for >me< in a microcontroller environment, though frankly some of the Arduino libraries have come close to convincing me to move on up. Time will tell. Also since AS5 accepts .NET plugins I've been thinking that someone could go ahead and add a DTR pulse to reset the Arduino and let avrdude upload to the board and pretty much entirely replace the Arduino IDE for more advanced work. Now if I can just find time...

What you need to do, is to move it to the end of the line that it was on. That way the order of the parameters for the linker is better.
So here are the steps:
1. Uncheck the option "Use External Makefile"
2. Add the -Wl,-lcore -Wl,-L"C:\Arduino" (or similar) to "Other Linker Flags"
3. Check the option "Use External Makefile"
4. Edit the makefile, search for the string you entered at step 2, move it to the end of that line and save the file
All done!
BTW, AVR Support have acknowledged this as a bug, so I expect it will get fixed at some stage.

Thank you very much for this. However, I still get "undefined references".

1) core.a is located at C:\Users\computer\Documents\Arduino
2) Using external Makefile: C:\Users\computer\Documents\AVRStudio\ArduinoTest\ArduinoTest\Debug\Makefile
3) moved the "-Wl, lcore etc." to the end of the line (see below)

BTW, I'm still geeked - in just a day I've moved from simple Arduino programming with "println" debugging up to using an AVR Dragon with JTAG debugging and AVR Studio 5 with breakpoints. Very cool! Now, if I can get this part working I can ditch the Arduino IDE and have a much smoother workflow...

* Find the core.a file in the \buildXXXXXX.tmp directory.
* put it in a known directory (e.g. C:\Lib)
- RENAME it to libcore.a (found out via this page: http://gcc.gnu.org/onlinedocs/gc...)
* Make sure that all directories you added according the the original instructions are added as full paths (NOT relative)
* No reason to use external makefile here. It works fine both with the additional linker flags, but also if i add the lib (core) and directory (c:\lib) (still not as relative path) under the libraries tab under GNU/C++ Linker.

* No reason to use external makefile here. It works fine both with the additional linker flags, but also if i add the lib (core) and directory (c:\lib) (still not as relative path) under the libraries tab under GNU/C++ Linker.

Just to note that there's currently a bug in AS5 that means this will work if you are building a C project that links to libcore.a but the library will not be found if you are building a C++ project as the -Wl,-l option does not seem to be passed.

Just to note that there's currently a bug in AS5 that means this will work if you are building a C project that links to libcore.a but the library will not be found if you are building a C++ project as the -Wl,-l option does not seem to be passed.

That's true - I see that now. And it seems that I also needed to insert a:

extern "C" void __cxa_pure_virtual() { while (1); }

when building as a C++ project.

Anyway - this is so cool - being able to use the Arduino libraries and still have a _real_ integrated development environment! :)

Hello,
I am trying to follow this step by step but I am not able to compile.
The error that is showing is:

Quote:

'pinMode' was not declared in this scope
.././AVRGCC1.cpp: In function 'void loop()':
'HIGH' was not declared in this scope
'digitalWrite' was not declared in this scope
'delay' was not declared in this scope
'LOW' was not declared in this scope

The code I'm trying to compile is:

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

"undefined reference" means that none of the .o or .a files provided to the linker contain those functions. So you either need to add a library or some .c/.cpp source files (I haven't read the whole of this thread but I suspect it's a lib in fact)

I struggled with adding the LiquidCrystal library for a few hours... due to inexperience with C++, but got it figured out, so I thought I would share...Order of the object files in the linker command are important, as stated above.

To include the LiquidCrystal library I put the LiquidCrystal.o object file from the Arduino temp directory in the same location as the libcore.a library. Then I added it before the libcore.a library in command below. Any library that LiquidCrystal.o depends on goes before it in the command below and their corresponding object files need to be copied into the common location.

I had some trouble using the Windows "search" to find core.a, but method below may help someone:
1. Locate the Sketch Preferences.txt (instructions on the Arduino website)
2. Add the following lines (I think only one is needed, but I added both of them oh well):

link.verbose=true
build.verbose=true

3. Then verify and compile an example sketch.

4. Look in the bottom of the sketch where the output is stored and search for core.a

5. Copy core.a from the path selected and you can rename it to libCore.a or something if desired and reference it from the project.

Also since AS5 accepts .NET plugins I've been thinking that someone could go ahead and add a DTR pulse to reset the Arduino and let avrdude upload to the board and pretty much entirely replace the Arduino IDE for more advanced work. Now if I can just find time...

I just created a batch file with MODE COM3 DTR=ON on a line preceding AVRDUDE

Note that on an 8bit AVR micro this is not necessarily the most efficient way to implement two state variables. The AVRs (for about 6-7 years) have had GPIOR0 which is the perfect place to store eight very fast access bool variables by casting a struct of 1-bit bitfields onto the location (as explained in another tutorial here in fact)

First thanks for this post, super useful for debugging step by step with JTAG on AVR Studio!

Here is my issue, I have a perfect setup on one computer, everything works perfectly, from compiling to debugging. I did the same setup on another computer (both computers run wndows 7 64-bits), got the compiling working well, AVR Studio code transfer runs but debug fails (F5 command).
There is no explicit error, only that the status goes to "Running" then "Ready" but the code isn't executed, breakpoints are not reached and when I pause the program AVR Studio opens a "No Source Available" page. So it seems like my code isn't transfered properly. I erased the memory many times and tried a AVR C++ project without arduino code, latest works OK. I took my main CPP file, converted it to ".pde" file (Arduino Software version 0022), compiled it, uploaded it, code works fine.

I checked again and again the GNU directories and libraries path to check that everything was correct, indeed it seems to be as compiling is fine.

I am now running out of ideas to know where the issue is.
Does anybody has any opinion on this one?

I have a question regarding the post on Dec 21, 2011 by Cisco25. I am working on Arduino on AVR Studio and only include additional Arduino library (such as AndroidAccessory) I have same issue. no source available page when I pose program. Break point does not work neither. However, I have no issue when I don't use any library. I believe that my library is correctly included, but this point I have no way to check with any experts.

Perhaps if I explain how source level debugging works you'll see what's going on?

First for a code to even be debuggable it has to be built with the -g option (often either -gdwarf-2 or just -g1/2/3). What this says is "for each block of opcodes generated make a note of which file on disk and which line number within it contains the source that generated this block". So if you have:

in a file main.c then the DDRB line will generate two opcodes to load R24 with 0xFF and then OUT that value to the DDRB address. The PORTB line will generate maybe four opcodes to load a register with 0xFF (actually the value from the first code may be re-used) then IN from PORTB, EOR with that 0xFF value then OUT back to PORTB.

The first two ocodes will be tagged in the ELF file as "main.c line 4" and the four opcodes as "main.c line 6".

As long as main.c remains in the same place on your hard drive then when you load the ELF file into the debugger it sees the "main.c:4 " and "main.c:6" information (DWARF2) and so loads main.c and extracts lines 4 an 6 and puts those against the blocks of opcodes in the debugger.

If you either delete main.c or if someone gives you some prebuilt code that either was not built with -g or that contains references to files on their system where the lib was built and not a current location on your system then when the debugger encounters those files it will say "source not found".

So were the libs you are using built on your own system? Are the source files used still in the same place? Was the library built with a -g option?

Knowing a little of how Arduino works I believe:

(a) they may not specify -g. Why would they? You don't normally load Arduino code into a debugger

(b) the build usually occurs in %TEMP% with source files being copied there just during the build then deleted afterwards. As such the source may no longer exist in the location used during the build even if -g is used.

Can I start a new Arduino project in AS7 and have all the Arduino libraries available automatically? I don't use Arduino, but some of the libraries are tempting. Or is that selection when starting a new project in AS7 only for importing an existing Arduino sketch. It seems even in that case the Arduino libraries must be available to AS7.

Thanks so much, David. That is what I wanted to know. I think the only Arduino library I would likely use is the SoftwareSerial, if I needed an additional UART channel with a Mega that only has one. Most of the other stuff I have my own code I use. I was just curious how much AtmelStudio had integrated with Arduino when I saw the option of an Arduino sketch in AS7 for new projects.

I think the only Arduino library I would likely use is the SoftwareSerial, if I needed an additional UART channel with a Mega that only has one.

Is it worth tying yourself up in knots simply to get access to a soft-UART? Have a look in the Projects section here - there are several available. Some by "danni" I think so they are bound to be good (talking of which, what has happened to Peter Danneger ?)