ahmetsemihparlak / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

SRAM Memory size check #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

Please have the IDE check the linker output, and report an error if the
SRAM usage exceeds the size determined by the CPU selected in the
preferences menu. 

Why?

Because this is an annoyingly difficult bug to track down if you are not
expecting it.  In my case I got weird output on the Serial line, and
thought I had messed up my interrupt code!

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

It shouldn't, the only issues would be for people using the IDE to generate
files for odd ball AVR chips.  eg. using the settings for a 168 to program
an at90, or an atmega48 say...

Original issue reported on code.google.com by rleylan...@gmail.com on 16 Jun 2009 at 1:44

GoogleCodeExporter commented 9 years ago
How do you get the avr tools to output the SRAM usage?  

Also, how useful is this?  Consider that the RAM usage changes as the program 
runs, so even if you fit under the 
limit when the program starts, you can run out of RAM in the middle of 
execution.

Original comment by dmel...@gmail.com on 16 Jun 2009 at 2:55

GoogleCodeExporter commented 9 years ago
True, but at least your code starts up ok. 

As far as size is concerned, could you check the bss + init data size?

Original comment by rleylan...@gmail.com on 16 Jun 2009 at 11:24

GoogleCodeExporter commented 9 years ago
Knowing how much .data + .bss being used will allow the programmer to leave a 
margin
of safety in the memory.

Original comment by frank.zhao.main@gmail.com on 12 Aug 2009 at 1:00

GoogleCodeExporter commented 9 years ago
If you are working on several platforms, it is not so easy to keep track of the 
RAM
usage all the time and it's easy to use up a little more than necessary. Even 
if you
are an experienced programmer.
For me, it would be a big help to see the RAM usage after compilation, to avoid
wasting the not so ample resource on the microcontroller. In my last project I
reached the point one time just by sending debug messages via serial which were 
a
little wordy. If you are used to a PC or other platforms with comparatively 
extensive
RAM, you fall into the trap.
Since Arduino is also intended as a platform to teach working with 
microcontrollers,
showing the RAM usage after compilation would show one of the key restrictions 
when
programming on such platforms, just like the needed nad max flash memory, which 
is
already shown.

Original comment by pj46...@t-online.de on 20 Feb 2010 at 2:23

GoogleCodeExporter commented 9 years ago
This would essentially require an arduino simulator to be run for some 
unspecified 
time. Also the inputs would need to be simulated somehow (buttons, sensors...) 
as 
different functions are likely to be involved based on the inputs (and their 
in-scope 
variables and hence SRAM usage. Also, how about recursive funcions?)

While it would be nice to have an arduino emulator/simulator, I think it is 
unreasonable to expect that of the IDE and compiler. It is really not just 
another 
simple function to add a "SRAM usage" warning, like with the (basically static, 
but not 
neccesarily so) flash memory. For now that is up to the programmer to know how 
much 
SRAM is needed, and how much the particular arduino variant has.

(Im just a casual user of the Arduino IDE, I just wanted to comment on this).

Original comment by raron...@gmail.com on 25 Mar 2010 at 1:13

GoogleCodeExporter commented 9 years ago
As an aside, this is a pretty standard feature of professional development 
tools (eg.
MPLAB).  Knowing how much RAM is used (and remaining) is critical to maximizing 
your
hardware use.

This bug concerns static memory use.

Run time RAM allocation (dynamic) is another matter.  That is not something 
expected
from the linker/compiler/IDE, and could/should be caught by the allocation 
methods,
and described in a separate report.

Original comment by rleylan...@gmail.com on 25 Mar 2010 at 4:44

GoogleCodeExporter commented 9 years ago
If I'm expect to be using dynamic allocation, I will definitely be checking the 
return status and (I hope) failing as gracefully as I can when I'm out. 

But I agree that it would be very nice to get a basic lower bound for static 
SRAM usage, even if it is just an estimate (it could be presented as an 
estimate of usage, to avoid confusion).  It would also help be a guide when 
trying to refactor to save RAM, to see how much of a difference a particular 
change might make.

Andrew

Original comment by sch...@gmail.com on 16 Aug 2010 at 6:39

GoogleCodeExporter commented 9 years ago
I'd like to see this feature support add ons from other vendors that use other 
AVR chips such as the teensy or sanguino. Of course those vendors would have to 
setup their board support files appropriately...

Original comment by standard...@gmail.com on 18 Aug 2010 at 2:56

GoogleCodeExporter commented 9 years ago
yes i'd love to see this as well, just as the compiler reports flash usage, it 
should report initial/static RAM usage(again, MPLab has been doing this for at 
least 11 years)

Original comment by glov...@gmail.com on 16 Feb 2011 at 10:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Since the microcontroller knows that a buffer overflow happens, IDE could at 
least show where on the code was the problem. I believe that the 
microcontroller warns of buffer overflow errors.

Original comment by xanoko...@gmail.com on 18 Mar 2011 at 12:17

GoogleCodeExporter commented 9 years ago
To check for static RAM please take a look at this:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224729260

There is even a comment from dmellis adding this to the TO DO list :-)

So please consider this a gentle reminder to incorporate this into the next 
revision.

thanks,
Robert.

Original comment by rleylan...@gmail.com on 18 Mar 2011 at 12:45

GoogleCodeExporter commented 9 years ago
Issue 395 has been merged into this issue.

Original comment by dmel...@gmail.com on 3 Apr 2012 at 2:36

GoogleCodeExporter commented 9 years ago
Please keep in mind that many new users already misunderstand the flash memory 
usage message today.  Many believe that X bytes (of a Y maximum) is how much 
RAM, or simply stated "memory", is free.  So is saying nothing better than 
saying something?

It would be helpful to include at least an estimation (from avr-size?) to help 
people realize there is a difference between RAM and PROGMEM.

Initial RAM Usage:  562 bytes (of a 2048 byte maximum)
Binary sketch size (PROGMEM): 2650 bytes (of a 32256 byte maximum)

This would at least prompt the question, "what's the difference?"

Original comment by byerly0...@gmail.com on 23 May 2012 at 2:29

GoogleCodeExporter commented 9 years ago
Using the code as a starting point from this very old example:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224729260

I have modified it to work with the latest 1.01 source such that now it the 
Arduino app prints this out:

Binary sketch size: 163718 bytes (of a 258048 byte maximum)
Initial minimum RAM usage (more will be used at run time): 1098 bytes (of a 
8192 byte maximum)

I have also modified the boards.txt file to contain the SRAM size for each 
board.

The modification uses objdump to get the static allocation for SRAM which we 
know of course is only the starting point since there is dynamic allocation 
going on at run time as well. But, it's still very useful.

I use this myself everyday and several others have asked me for it and are 
using it. How can I get this submitted so that it  becomes part of the standard 
distribution. Seems like many, many people want this.

Attached is a zip file containing the modified files.

Ron Curry

Original comment by Wingspin...@gmail.com on 29 May 2012 at 5:17

Attachments:

GoogleCodeExporter commented 9 years ago
yes please,

amazing that the standard IDE does not provide an indication on where one is 
starting at.
    for new users, the output would also allow them to learn how ram usage changes with different styles of code. having nothing because its not perfect is an interesting responce. 

in a car, if I had a choice between no breaks , because it was hard to make 
perfect, and breaks that were slow but worked, I know what I'd have.

Original comment by andrew6...@gmail.com on 8 Jul 2012 at 6:05

GoogleCodeExporter commented 9 years ago
a little extra update,

its amazing how many example code we see that use memory free to try to get an 
estimate of free memory,

Original comment by andrew6...@gmail.com on 27 Jul 2012 at 6:03

GoogleCodeExporter commented 9 years ago
The memory check has been introduced in the IDE 1.5.x series.

Original comment by c.mag...@arduino.cc on 21 Feb 2014 at 3:57