2

Author Topic: reducing program size  (Read 1522 times)

0 Members and 1 Guest are viewing this topic.

Offline sonictjTopic starter

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
reducing program size
« on: August 15, 2009, 02:08:54 AM »
I remember there was a revision in the arduino language that would only compile functions and variables etc. used during a given program.  This saved on flash and sram memory.  How can I implement something like this with my code in avr studio?  I've written a ton of libraries now, and I don't necessarily use them all at once.  However when I compile my code with unnecessary #includes or not the program still takes up the same amount of space.  Is this a simple matter of preprocessor commands? 

Offline guncha

  • Jr. Member
  • **
  • Posts: 40
  • Helpful? 0
Re: reducing program size
« Reply #1 on: August 15, 2009, 11:41:09 AM »
It has to do with linker still linking in your libraries (the actual code) even if you have not #included and don't use them. I wouldn't know how to change that in avr studio as I don't use it, but typically in the makefile there is a line like this:
Code: [Select]
OBJECTS    = a2d.o main.othat defines what is going to end up in the final executable.

I'm quite sure, that there are some configuration options in avrstudio that let's you do exactly this.

Offline sonictjTopic starter

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
Re: reducing program size
« Reply #2 on: August 15, 2009, 11:50:36 AM »
Thanks guncha I'll go tinker with settings.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: reducing program size
« Reply #3 on: August 18, 2009, 01:21:16 PM »
Sounds like you need to upgrade to an Axon :P

You know you want 64kb flash and 8kb SRAM ;)


as for the #includes, make sure other files don't also declare the same #include . . .

this C code optimization tutorial might also help:
http://www.societyofrobots.com/member_tutorials/node/202

Offline sonictjTopic starter

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
Re: reducing program size
« Reply #4 on: August 18, 2009, 02:22:21 PM »
@Admin I've got the same chip as the axon!  and I've got a 2560 sitting pretty just waiting to go on my next board  :P... That is if I don't decide to upgrade to an xmega or avr32 board.  Side note, the avr32 chips look awesome the high end ones have up to 210 MIPS and have DSP functions like interfacing with cmos cameras.

What I've been looking into is trying to create a static library using the avr-ar part of the GNU toolchain.  That way, the linker will only add in functions used.  I'm just not sure how I use the avr-ar (archiver aka librarian) command line utility.  I don't have alot of experience with command line stuff.

Its more of an OCD tendency of mine to want to make everything I code as small as possible.  I've got 7K of Sram and 40K Flash to spare.  I'm not even close to filling the chip.
« Last Edit: August 18, 2009, 02:53:45 PM by sonictj »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: reducing program size
« Reply #5 on: August 18, 2009, 02:44:59 PM »
lol its at the end of the day, forgot you had a 640 already . . .

well, then what you need is an old Axon prototype that uses the 2560 :P

Actually, I've never used more than 60% of my 64kb Axon memory, and thats without optimization or even commenting out any includes . . .

Offline sonictjTopic starter

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
Re: reducing program size
« Reply #6 on: August 18, 2009, 02:52:21 PM »
Quote
well, then what you need is an old Axon prototype that uses the 2560 Tongue

Actually, I've never used more than 60% of my 64kb Axon memory, and thats without optimization or even commenting out any includes . . .

Yah I don't expect I will run out of resources either I just have a compulsion to lean how to create a library .a file for the heck of it..

Offline Asellith

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: reducing program size
« Reply #7 on: August 18, 2009, 02:57:59 PM »
Best way to reduce code size is to write everything in assembler :) Not that I would do it but it sounds like a nice skill to learn for someone with OCD.
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline sonictjTopic starter

  • Supreme Robot
  • *****
  • Posts: 416
  • Helpful? 11
Re: reducing program size
« Reply #8 on: August 18, 2009, 03:17:16 PM »
Quote
Not that I would do it but it sounds like a nice skill to learn for someone with OCD.

you got me lol.  I have no desire to write in assembler, and I'm not really OCD.  I was just over exaggerating.  I just look at it as a personal challenge to code  as efficiently as possible.  I figure its a useful skill for when I get a project where I want to use a mcu with little resources, like an one of the ATtinys.

@Asellith I will have plenty of time to write in assembly anyway. I'm gonna be taking a microprocessors class soon and the instructors make us use assembly exclusively. The class just got an overhaul too where we will be using a TI processor with DSP capabilities.  So I'm betting after that class I'm gonna have a whole new appreciation for how awesome C is :D.

« Last Edit: August 18, 2009, 03:20:06 PM by sonictj »

Offline Asellith

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: reducing program size
« Reply #9 on: August 20, 2009, 09:30:16 AM »
Thats the way I was when I took the microprocessor class I had to take in school. They changed it after I took the class but my class had to enter the programs by hand using an lcd display and a keypad. I wrote an excel document to help me compile to programs but it was a pain. Oh and Heaven help you if you missed a command at the beginning no editing just reenter the entire program.... I enjoyed the class it was fun but to do it for a normal program that did more then light leds up or take a simple input then no thank you.
Jonathan Bowen
CorSec Engineering
www.corseceng.com

 


Get Your Ad Here

data_list