Go Down

Topic: AVR Studio 5.1 - doing it the hard way (Read 6 times) previous topic - next topic


Is anyone feeling charitable enough to explain how I might use the Arduino libraries in AVR Studio 5.1?  I  know there are tutorials on this, and by following them, I've gotten close to having it work.  Specifically, I'm getting undefined reference errors, because, of course, the libcore.a library is not being linked.

Now, this is where I'm looking for guidance.  I don't really want to use a pre-compiled library.  I tinker with the whole gamut of devices:  ATmega8s running at 8MHz and 16MHz, 328s and 328Ps running at 16MHz, 1284Ps at 16MHz...  So, rather than keep up with maybe half a dozen commonly used variants, I'd like to just start a project, pick my target platform, add the F_CPU symbol, and have the core libs built from scratch, optimized for my target, like they do under the Arduino IDE.  The compile time doesn't bother me, I can wait an extra five seconds.

I'm self-taught, and my only prior experience with C is writing code in Kate, and compiling by hand in xterm, so I don't have a clue how to properly resolve dependencies in VS.


Have you checked your Makefile to make sure the core libraries are being linked in the right place?  AVR Studio 5 has a bug which places the "-Wl,-lcore" reference too early in the linker command, before it's actually needed.  The linker decides those files are irrelevant, doesn't link them, then when it reaches a later library that depends on them, can't find what it needs.  If you are linking with that method, you need to edit the Makefile by hand and move those flags to the very end of the command.  I'm fairly certain this wasn't fixed in 5.1.

Not sure if you've seen it but we have more background on that issue in our tutorial here: http://www.engblaze.com/tutorial-using-avr-studio-5-with-arduino-projects/#setup

Unfortunately, we use the pre-compiled strategy in that article because people tend to run into enough configuration issues already, without trying to get the core to compile.

If you really want to be device agnostic, have you tried adapting techniques #2 and 3 in the core library section for setting up Eclipse?  http://arduino.cc/playground/Code/Eclipse#Arduino_core_library

The interface steps will be different but Eclipse and AVR Studio use the same toolchain under the hood.


Yep, that's one of the guides that got me to where I am now.  But, it glosses over how all the Arduino .cpp files are involved in compiling the static libs.  FWIW, that's probably something I'm just expected to know, but again, IDE noob here.

I'm still pounding away at this, trying to make sense of how VS works.  I'm not sure if this is the right approach, but given the wording on step 3 (and taking a stab in the dark at how to translate instructions for one IDE that I've never used at all to another IDE I've never used before now), I've copied all the .cpp files from the cores folder (from the Arduino IDE) to a subdir in my project folder.

So, now I have C:\Users\Me\Documents\AVRStudio 5.1\Arduino-ATmega328P_16MHz\Arduino Core\*.cpp

I've added this folder to my project (a static library), went through the C, C++, and Linker settings and added the include paths, optimization, debug, char, enum, F_CPU, etc. etc.  I removed the default .cpp file it starts out with, using main.cpp from the distro instead.

Now, assuming I haven't stepped in anything up to this point, I try to build the project..... and it fails.

"'fabs'|'ceil' was not defined in this scope" (from the AVR lib's util/delay.h).  I understand this is simply a dependency that hasn't been met, so I checked the output log to see which file it was trying to compile.  Turns out, it's the first one:  CDC.cpp.  I can only assume it is compiling them in alphabetical order, and the majority of the dependencies don't get met until main.cpp includes Arduino.h.

Just for grins, I added back the project-titled .cpp file I got for free and added "#include <Arduino.h>" to the top, removing everything else that was added by default.  I thought maybe because the core files were in a subdir, this file might get built first.  Nope.

So, am I even taking the right approach here, or have I made a colossal blunder already?  If so far so good, how do I insist on a particular module being compiled first?  I know I could make a file called "_____MEFIRST.cpp", include Arduino.h, and I'd probably be set -- but that strikes me as a hack, and I would probably be better served by learning how to do this correctly.


I just encountered this too. When using AVRStudio you get a new version of the AVR library & it looks like their implementation of delay.h has changed since the Arduino folk got their AVR library. The new version of delay.h requires <math.h>, which implements the floating point functions you refer to. This library should have been included in delay.h in my view, since delay.h can't compile without it.

Anyway, you'll get it compile if you add #include <math.h> to
AVR Studio 5.1\extensions\Atmel\AVRGCC\\AVRToolchain\avr\include\util\delay.h

I put this #include just after #include <util/delay_basic.h>

Unfortunately, after solving this problem, and figuring out how to make AVRDude send the file to the Arduino, I still don't get the blink program to upload and run correctly. Be keen to hear if you make more progress.

Incidentally, I use this command line with AVRDude:

-C C:\Programming\Languages\Arduino\IDE\arduino-1.0\hardware\tools\avr\etc\avrdude.conf -v -v -p m2560 -c wiring -P COM7 -b 115200 -D -U flash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i

I was able to load a program created with the Arduino IDE into the device & have it run, so I think the problem lies in the build step.
Program with Atmel Studio; upload to Arduino with MegunoLink. Plus real-time plotting, logging, & monitoring Arduino data: http://www.MegunoLink.com


Ah, that makes sense!  I'll have to try this later today.  Thanks for the update!

Go Up