Go Down

Topic: Arduino with AVR Studiio? (Read 1 time) previous topic - next topic


Has anyone tried using AVR Studio with assembler or gcc for developing arduino programs?

Alyn Scott


Dec 05, 2007, 05:00 pm Last Edit: Dec 05, 2007, 05:47 pm by tboneus Reason: 1
Just for the hell of it I tried. (My version was 009, I have not tried 10 yet)

Copy the Arduino folder (within targets) to the winavr/avr/include

In Avr Studio got to Project->configuration options-> include directories and add the search path for the Arduino folder above. Set the Device, frequency and optimization (I used -01 as -00 gave a hex file bigger than the Arduino IDE).

There was no need for an external makefile as ARV Studio creates one for you and can upload to AAVRIsp or Stk500 no problem.

using the add existing source file in the Avr Studio tree add the following files:

Avr Studio does not allow cpp files (at least without creating a new make file so to test I copied the blink example and saved it as a .c file. Don't forget to put the #include "WProgram.h" at the top of your file.

There also needs to be a main function in this .c file

Code: [Select]
int main(void)

     for (;;)
     return 0;

so the complete code for the test.c file would be:

Code: [Select]
#include "WProgram.h"
* Blink
* The basic Arduino example.  Turns on an LED on for one second,
* then off for one second, and so on...  We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
* http://www.arduino.cc/en/Tutorial/Blink

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output

void loop()                     // run over and over again
 digitalWrite(ledPin, HIGH);   // sets the LED on
 delay(1000);                  // waits for a second
 digitalWrite(ledPin, LOW);    // sets the LED off
 delay(1000);                  // waits for a second
int main(void)

     for (;;)
     return 0;

compile and run...

There may have been a couple of other changes in the files (possibly an include in wiring.c) so if it does not work post back and I will compare the working files on an avr studio project to the original ones. Actually I was writing this to work for a Mega 16 on a stk500 as I have no 168 or 8's available.

What it does give you is the ability to debug the program (in the simulator or a JTag if one is connected) as all of the files are there. The elf file in the Arduino IDE created files only gave the debugging of the final assembly as there was no source cod available in the sketch folder.

It should also be possible to use the compiled .o files and link them to your project file but I have not got that working as of yet. If anyone has any ideas I would be grateful.


Just a note: some of the functions won't work unless you're using C++ (I believe the Serial commands, random(), and some others).  


Dec 05, 2007, 06:18 pm Last Edit: Dec 05, 2007, 06:44 pm by tboneus Reason: 1
Thank you for the heads up. As it does work in straight c I will try a new makefile (there is one on here for the command line) and use that in AVR Studio. Then it should be ok to go back and use the c++ files in the compile.

The problem is that AVR Studio does not display c++ or let you create them so my thoughts at this point is to use a .c project file and link the c++ files if they are in a library as these will only be needed to be compiled once.

If all else fails the library's are quite simple to convert to c. Just converted the LedControl for Max7221 SPI and it runs fine. This might be because it is a software implementation of the SPI as opposed to a hardware implementation that doesn't use bit-banging.

Arduino code makes a very nice clean framework to work with and as all of the base code is in place it is a very pleasurable experience as opposed to GCC code from scratch.

This is really neat. I am looking forward to see if I can get my Dragon to work when it comes.

Do you have specific instructions on how to get some of the libraries to work?
ie LCD, EEPROM etc

How do you link the .o files?

"Who left the fridge open?"
-Tugg Speedman
(Scorcher VI - Global Meltdown)


well i'am looking forward to this...
I've started a post in the same subject because i didn't found this one (I've used YaBB search function but didn't find it.... maybe because Studiio is spelled with 2i LOL: studi2o)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131