RAM hunting

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can I find what WinAVR/GCC libraries are using what static RAM? I use printf() for stdio, but no sscanf, no floating point. Default WinAVR settings.

Too large of a portion of 4K RAM is not available to me. I know what my code uses for statics, strings, etc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The library should use very little SRAM statically, if any (most everything is done on the stack, or heap, and released immediatly). I'm guessing you're missing something in the consumption by your program. Have you taken constant strings into consideration? Have you generated a map file and symbol table and looked at the allocations?

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup even the float and printf libraries have no global overhead - but they almost certainly use some RAm dynamically rather than statically when they create automatics on the stack. You won't see this in the fixed sizes of .data and .bss but you may want to monitor SP's low water mark in case it's bumping into the end of .bss

As for other stuff in .data and .bss - the .map file is your friend.

(but like glitch says, you probably just need to PROGMEM the const data)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
As for other stuff in .data and .bss - the .map file is your friend.
This will provide helpful data for elements contributed by your own program but it won't tell you whence came elements contributed by libc.a, etc. In my application, I noticed a 4-byte RAM variable called 'next' in the .sym file and couldn't find its source in my code. I finally discovered, using avr-nm, that it comes from rand.o and/or random.o in libc.a. Here is a portion of the output of 'avr-nm libc.a' (edited slightly):

rand.o:
00000000 t do_rand
00000000 d next
000000ae T rand
000000a8 T rand_r
000000b8 T srand

random.o:
00000000 t do_random
00000000 d next
000000be T random
000000b8 T random_r
000000c8 T srandom

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes some functions like rand do have statics, they will only show up if you use the function. As far as I know, the number of functions that require persistand state, or static allocation, are only a small handful... and the amount of memory certainly wouldn't add up to 4K. the time conversion functions are another set that use static allocation comes to mind immediately.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, the only symbols that appear in avr-nm for libc.a would appear to be:

malloc.o:
00000004 D __malloc_heap_end
00000002 D __malloc_heap_start
00000000 D __malloc_margin

rand.o:
00000000 d next
random.o:
00000000 d next

(there's no " b " or " B ")

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks - I'll try as suggested. The abbreviations in the listing and map files need a crib sheet.

Example: In the IDE of WinAVR sscanf.a is referenced. I had but removed use of that. Why is it still there? suggesting it'll be linked in.

Of course, I have all my constant strings and so on in program memory. I keep looking for errors on my part where I have large statics in RAM but I don't think I have any more hiding. I have between 1K and 2K unaccounted for. Stack size is only 200.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

do a make clean and then make again to re-build everything... perhaps one of your modules was not re-built, so it was still referencing it... either that, otr you missed a reference to it somewhere.

Had another thought, since you keep saying "statics" Perhaps you're having multiple instances created because they are static, even though you are expecting them to all be referencing the same instance.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps incorrectly, I say "static" to merely mean global variables, not on-stack locals.

Using WinAVR, I do "rebuild all" or whatever it's called in the GUI, this being the same as make clean and make all, I assume. I gave up make file editing years ago along with bacon-cheeseburgers and fries.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Perhaps incorrectly, I say "static" to merely mean global variables, not on-stack locals.

But "static" means neither.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a static var is one of 2 things...

1) a static global that is private to a module. Thus if in moduleA you declare a static global called aGlobal. and in moduleB you declare another static global called aGlobal. Even though the two share the same name, they are separate variables.

2) a static local moves the var from the stack to the data space (so that it retains value), but the name is only valid within the function that declares it. Thus it behaves like a global, but has the visibility of a local.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

glitch wrote:
a static var is one of 2 things...

1) a static global that is private to a module. Thus if in moduleA you declare a static global called aGlobal. and in moduleB you declare another static global called aGlobal. Even though the two share the same name, they are separate variables.

2) a static local moves the var from the stack to the data space (so that it retains value), but the name is only valid within the function that declares it. Thus it behaves like a global, but has the visibility of a local.

Right - a static is stored in RAM not used for the stack. The compiler's scope for the variable, module or global, is a different topic. I don't want to declare a static of the same purpose and name more than once among all modules. It wouldn't be logical or efficient.

So the OP was about hunting down hidden users of RAM in a program with lots of C library routines.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, just making sure... I kept hearing "static" and bells were going off that maybe something was being missed there.

As for hidden uses of RAM it will depend on what library functions you are using. Are you using any of the stdio functions? Are you using the built-in stream facilities? Either of those will create/use a buffer.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.