| Author |
Message |
|
|
Posted: Apr 22, 2008 - 05:25 PM |
|

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! |
|
|
| |
|
|
|
|
|
Posted: Apr 22, 2008 - 05:35 PM |
|


Joined: Jul 18, 2005
Posts: 62922
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) |
_________________
|
| |
|
|
|
|
|
Posted: Apr 22, 2008 - 05:41 PM |
|

Joined: Feb 12, 2005
Posts: 16544
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. |
|
|
| |
|
|
|
|
|
Posted: Apr 22, 2008 - 05:44 PM |
|


Joined: Jul 18, 2005
Posts: 62922
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 |
_________________
|
| |
|
|
|
|
|
Posted: Sep 10, 2010 - 02:09 AM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: Sep 10, 2010 - 02:32 AM |
|

Joined: Nov 17, 2004
Posts: 13956
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.
|
| |
|
|
|
|
|
Posted: Sep 10, 2010 - 09:01 AM |
|


Joined: Jul 18, 2005
Posts: 62922
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 |
_________________
|
| |
|
|
|
|
|
Posted: Sep 16, 2010 - 09:43 PM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: Sep 16, 2010 - 10:54 PM |
|


Joined: Jun 26, 2006
Posts: 627
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 |
|
|
| |
|
|
|
|
|
Posted: Sep 17, 2010 - 12:18 AM |
|

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... |
|
|
| |
|
|
|
|
|
Posted: Sep 17, 2010 - 12:43 PM |
|


Joined: Jul 18, 2005
Posts: 62922
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. |
_________________
|
| |
|
|
|
|
|
Posted: Aug 01, 2011 - 07:22 AM |
|

Joined: Jul 14, 2011
Posts: 62
|
|
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? |
|
|
| |
|
|
|
|
|
Posted: Aug 01, 2011 - 09:59 AM |
|


Joined: Jul 18, 2005
Posts: 62922
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)
|
_________________
|
| |
|
|
|
|
|
Posted: Aug 01, 2011 - 10:10 AM |
|

Joined: Jul 14, 2011
Posts: 62
|
|
|
|
|
|
|
Posted: Aug 01, 2011 - 10:14 AM |
|

Joined: Jul 14, 2011
Posts: 62
|
|
BTW I dont understand how and where to change the invocation and to put
Quote:
avr-size -C -mcu=atmega1281 projname.elf
|
|
|
| |
|
|
|
|
|
Posted: Aug 01, 2011 - 10:18 AM |
|


Joined: Jul 18, 2005
Posts: 62922
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") |
_________________
|
| |
|
|
|
|
|
Posted: Aug 01, 2011 - 12:06 PM |
|

Joined: Jul 14, 2011
Posts: 62
|
|
thanks. |
|
|
| |
|
|
|
|
|