Go Down

Topic: Is AVR studio more code-space efficient than Arduino IDE? (Read 725 times) previous topic - next topic

lightaiyee

Dear Arduino experts,

I am thinking of switching to AVR Studio 6 instead of Arduino IDE. The main motivation comes from reducing code space but I am not sure if using AVR Studio will help in this aspect. I will still like to retain the use of some wonderful Arduino libraries like SoftwareSerial. Can anyone with experience of using both AVR studio and Arduino IDE answer my question?

Thank you.

tobyb121

The compiler used is the same, the only difference in terms of code space is that the IDE creates a setup and loop function and includes the Arduino library. If you are going to want to use the Arduino library anyway it's going to save you a few bytes using AVR studio. In other words, it isn't worth doing. If you are really struggling with code space you may need a larger microcontroller.

lightaiyee

What if I include only selected Arduino libraries and not all of the basic libraries? Will it help?

tobyb121

The compiler only includes the files that actually get used for example if you just make a completely basic sketch:
Code: [Select]

void setup(){}
void loop(){}

It compiles to 466 bytes.
If you then add in a basic Serial call:
Code: [Select]

void setup(){
  Serial.begin(9600);
}
void loop(){}

It goes up to 1744 bytes
If you copy that line again:
Code: [Select]

void setup(){
  Serial.begin(9600);
  Serial.begin(9600);
}
void loop(){}

This is 1768 bytes

This means that the call to Serial.begin takes 24 bytes, and so including the serial library takes 1254 bytes, and more importantly only gets included when you call a function from the library.
To get the size down you would get much better results by writing to the registers directly, e.g. using the PORT registers rather than digital read/write. Effectively scrapping the libraries  ;)

PeterH


The main motivation comes from reducing code space


How much are you using, and how much do you need to reduce it by?

Often, if you investigate what the code space is being used for you will find that there are relatively few pieces of code using large amounts of it, and these are where your optimisation efforts are best spent.
I only provide help via the forum - please do not contact me for private consultancy.

JimEli

#5
May 06, 2013, 08:42 pm Last Edit: May 06, 2013, 09:25 pm by JimEli Reason: 1
Are you talking about the code on the PC or the arduino?

The arduino IDE compiled code includes some routines for timing, pwm, pin manipulation and the like. So there is some room for small reductions if you're not using those functions.  With AVR Studio, you could also ditch the bootloader and gain space there as well. But as said above, same compiler, so same results for identical source.

retrolefty


What if I include only selected Arduino libraries and not all of the basic libraries? Will it help?


The arduino gcc linker only includes library code that your sketch is actually using so no opportunity there.

Go Up