Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
gubon
PostPosted: Apr 22, 2008 - 05:25 PM
Newbie


Joined: Mar 02, 2007
Posts: 17


Hi,

I'm looking for a way of knowing the RAM usage (%) of a program. I'm using libraries and I just solved a problem related to memory usage. That is, it goes wrong when a static (global) array is too big. However, the linker never gave any error nor warning.

Is there a way of knowing the maximum memory usage of a program after linking, you know, the worst case when an ISR that uses local variables is executed while the stack is already used a lot and so on...

Thank you!
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Apr 22, 2008 - 05:35 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

avr-size

If you use either Studio+WinAVR or Mfile/Makefile+WinAVR you should be seeing something like this at the end of your build:
Code:
AVR Memory Usage
----------------
Device: atmega16

Program:    7376 bytes (45.0% Full)
(.text + .data + .bootloader)

Data:         81 bytes (7.9% Full)
(.data + .bss + .noinit)

EEPROM:       63 bytes (12.3% Full)
(.eeprom)

(that output is using the -C option on avr-size but this requires a patch that is normally only evident in the WinAVR build of avr-size and in other environments you may have to make do with -A or -B)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Apr 22, 2008 - 05:41 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 19464
Location: Wormshill, England

If you use the Studio4 default makefile, it calls avr-size. This will give an indication of your RAM usage.

As far as I know avr-gcc does not report on excessive stack usage from inappropriate recursion.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
clawson
PostPosted: Apr 22, 2008 - 05:44 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

Previous threads of mine and also a thread in the tutorial forum present an idea where you add a .init3 routine that floods SRAM with a recognizable value. You then run the code for a while then stop it in the debugger and examine the RAM. As long as there are still some of the recognizable bytes between the end of .bss and the low water mark of SP then you are probably OK with run time stack frame usage.

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
schamton
PostPosted: Sep 10, 2010 - 02:09 AM
Hangaround


Joined: Feb 17, 2010
Posts: 157


quick question related to the avr memory usage. I'm not sure what 'Data' is. The program that i wrote occupies 71.9% in my atmega16, it seems to be working fine. Should i worry about the Data 132.8% Full?

Quote:

AVR Memory Usage
----------------
Device: atmega16

Program: 11784 bytes (71.9% Full)
(.text + .data + .bootloader)

Data: 1360 bytes (132.8% Full)
(.data + .bss + .noinit)


Thank you,

Eric
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Sep 10, 2010 - 02:32 AM
10k+ Postman


Joined: Nov 17, 2004
Posts: 14683
Location: Vancouver, BC

Quote:
Should i worry about the Data 132.8% Full?
Yes, very. Data is your SRAM usage, and it is only the amount that the compiler knows at compile time. You also need room for things created at runtime (particularly stack usage).

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Sep 10, 2010 - 09:01 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

Eric,

You need to get Data down to about 75% or less to be "safe". The "unused" 25% is what will actually be used on the stack for return addresses and local variables.

Often the thing wasting RAM are constant strings and tables of data which, if you do nothing to prevent it, will be copied to RAM when the program starts. To prevent it you keep them in code flash using PROGMEM which is explained in an article in the Tutorial Forum.

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
schamton
PostPosted: Sep 16, 2010 - 09:43 PM
Hangaround


Joined: Feb 17, 2010
Posts: 157


Thank you Steve and Cliff, i have upgraded the chip to an atmega64. One more quick question, i have read in some thread that avr studio can migrate a code from, say, an atmega16 to an atmega64. But i can't find that thread, and i am not sure how to do it. Could you please tell me how to?
thanks!
- Eric
 
 View user's profile Send private message  
Reply with quote Back to top
mckeemj
PostPosted: Sep 16, 2010 - 10:54 PM
Resident


Joined: Jun 26, 2006
Posts: 818
Location: San Luis Valley, Colorado ( 2,318m )

In most cases all that is required within a family is to recompile the code with the new processor set. If there are errors about unknown registers you fix those, obviously, as you go. If you don't have the source... well that's a different matter.

Martin Jay McKee
 
 View user's profile Send private message  
Reply with quote Back to top
schamton
PostPosted: Sep 17, 2010 - 12:18 AM
Hangaround


Joined: Feb 17, 2010
Posts: 157


oh, ok, thanks Martin. i thought there was a way that avr studio would update the registers automatically when changing the microcontroller...
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Sep 17, 2010 - 12:43 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

i thought there was a way that avr studio would update the registers automatically when changing the microcontroller

Studio is about as simplistic as it could possibly ever get when it comes to IDEs. Be thankful it can even edit/build programs but don't expect anything more from it.

To be honest I've never heard of a "porting assitant" as you describe here.

It's true that going up and down a family line: 48<->88<->168<->328 or 8535<->16<->32 is relatively painless (though even a 48 is quite different from 88/168/328). But going across from a 16 to a 168 is quite a bit more complex and can only really be achieved by close studying of the respective datsheets.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
barklis
PostPosted: Aug 01, 2011 - 07:22 AM
Wannabe


Joined: Jul 14, 2011
Posts: 84


Hi,

I am using AVR studio4 with Atmeg1281 as a target device and had the same "code memory usage" question but At build time I only see:


Quote:
make[1]: Entering directory `C:/Documents and Settings/oren/Desktop/ZIGBIT900/BitCloud_ZIGBIT_1_12_0/Applications/WSNDemo/makefiles/MeshBean_900'
cp -f All_ZigBit_Atmega1281_Rf212_8Mhz_Gcc/Exe/*.* ./../../

text data bss dec hex filename
91350 4220 4990 100560 188d0 All_ZigBit_Atmega1281_Rf212_8Mhz_Gcc/Exe/WSNDemo.elf
91350 4220 4990 100560 188d0 (TOTALS)
make[1]: Leaving directory `C:/Documents and Settings/oren/Desktop/ZIGBIT900/BitCloud_ZIGBIT_1_12_0/Applications/WSNDemo/makefiles/MeshBean_900'



are the numbers in bytes?bits? what is my memory consumption?
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Aug 01, 2011 - 09:59 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

are the numbers in bytes?bits?

bytes

The flash usage will be the text+data figures. The static usage of RAM will be the data+bss figure. So:
Code:
flash = 91350 + 4220 = 95,570 bytes
RAM = 4220 + 4990 = 9,210 bytes

The flash sounds OK if this is a 128K chip but the RAM sounds "iffy". Does this chip really have 16K of SRAM?

BTW if you can find the point where avr-size is being invoked then change the invocation to be:
Code:
avr-size -C -mcu=atmega1281 projname.elf

In this case you'll get a much more human-readable output such as:
Code:
AVR Memory Usage
----------------
Device: atmega168

Program:     172 bytes (1.0% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
barklis
PostPosted: Aug 01, 2011 - 10:10 AM
Wannabe


Joined: Jul 14, 2011
Posts: 84


Thank you!
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
barklis
PostPosted: Aug 01, 2011 - 10:14 AM
Wannabe


Joined: Jul 14, 2011
Posts: 84


BTW I dont understand how and where to change the invocation and to put

Quote:
avr-size -C -mcu=atmega1281 projname.elf
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Aug 01, 2011 - 10:18 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 69423
Location: (using avr-gcc in) Finchingfield, Essex, England

Nor do I as I don't know this software stack that you are building. Presumably there is a "Makefile" somewhere? Just search that for "size" and see what you hit. Also note that I do not know the model number of your AVR - perhaps mcu=atmega1281 is not the right model?? (oh and it's unlikely the project is really called "projname.elf")

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
barklis
PostPosted: Aug 01, 2011 - 12:06 PM
Wannabe


Joined: Jul 14, 2011
Posts: 84


Smile thanks.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits