Society of Robots - Robot Forum
Software => Software => Topic started by: Admin on May 12, 2008, 01:17:53 PM
-
After compiling my program with AVR Studio, how do I figure out what my flash memory usage is?
Looking at the .lss file, the .hex, and the .hex in a disassembler, I'm still confused on how to determine memory usage . . .
-
open the hex file as text,
these are the bytes thats going to be in your mcu's flash,,count em, ;D
im not sure checking the file size on the hard disk would be the same,,
-
In your makefile then the 'sizebefore' and 'sizeafter' dependencies should surround the HEX file rather than the ELF file.
Then:-
# Display size of file.
HEXSIZE = $(SIZE) -A $(PRG).hex
ELFSIZE = $(SIZE) -A $(PRG).elf
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
sizebefore:
# @if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
@if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
sizeafter:
# @if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
@if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
-
This does make assumptions about your makefile based on the $50 Robot. So (Admin) post your makefile if what I've said is garbage.
-
Hmmmm webbot, I am getting this error when using your code:
make: [AVR_Fish.eep] Error 1 (ignored)
but if I do this:
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
sizebefore:
# @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
@if [ -f $(TARGET).hex ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
sizeafter:
# @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
@if [ -f $(TARGET).hex ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
Then I get this:
Size before:
text data bss dec hex filename
0 17826 0 17826 45a2 AVR_Fish.hex
Creating load file for EEPROM: AVR_Fish.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex AVR_Fish.elf AVR_Fish.eep
c:\Program Files\WinAVR\bin\avr-objcopy.exe: there are no sections to be copied!
c:\Program Files\WinAVR\bin\avr-objcopy.exe: --change-section-lma .eeprom=0x00000000 never used
make: [AVR_Fish.eep] Error 1 (ignored)
Size after:
text data bss dec hex filename
0 17826 0 17826 45a2 AVR_Fish.hex
That still has an error in it (why?), but at least it gives me size info. Sooooo . . . this means it uses 17.8kb? Why is size before and after the same?
-
Just for the info:
Anybody using PIC mcu's can load their project in mplab then goto view->memory usage gauge and this will tell you how much flash memory is being used as well as any data or ram memory.
-
Hmmmm webbot, I am getting this error when using your code:
As with all things software - I get a completely different output in my make cycle!!
Can you attach your makefile?
-
Admin,
-right click on the hex file chooose properties
-there is somthing called SIZE ,, this is how much flash its gonna consume.
watch out its NOT the SIZE ON DISK
this is according to windown vista ,, i think its the same on other ones.
-
dude, are you talking about program memory? cause I have a hunch you're onto RAM usage here.
-
makefile is attached
benji, according to XP, its 49kb which I highly doubt is the actual amount of memory space it takes up on my micro . . . its just too large . . .
cause I have a hunch you're onto RAM usage here.
I wouldn't mind an automated way to determine RAM usage too . . .
-
benji, according to XP, its 49kb which I highly doubt is the actual amount of memory space it takes up on my micro . . . its just too large . . .
weird, are you sure its not the size on disk?
anyways another way to know it is to open the hex file in notepad
,it would looklike this
:A7SF9C0F8DS0F9DS9G8VBD09D8DFG989
:S8F0G0D78F7F0HGDG0F098DFF09DF8093
:H9D0F9S7DF0G8DFG0DFG7DF9GD7GD0FG
:DFGDFGDFGDVS9F8VSDVDS68F7S9SS8D9
so you simply put the cursor after the last byte of the program which is 9 in the above program
then look at the status bar it shows you line number and column number.
so just do (line num * column number)=number of bytes is what you get
maybe the status bar in the notepad wont be available by default so just go to view / states bar
-
Hey admin try this:
# Display size of file.
HEXSIZE = $(SIZE) -C --mcu=$(MCU) $(PRG).hex
ELFSIZE = $(SIZE) -C --mcu=$(MCU) $(PRG).elf
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
sizebefore:
@if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
# @if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
sizeafter:
@if [ -f $(PRG).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
# @if [ -f $(PRG).hex ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
I get an output like this:-
Size before:
AVR Memory Usage
----------------
Device: atmega8
Program: 3748 bytes (45.8% Full)
(.text + .data + .bootloader)
Data: 190 bytes (18.6% Full)
(.data + .bss + .noinit)
avr-g++ -g -Wall -Os -mmcu=atmega8 -D F_CPU=8000000 -c -o main.o main.cpp
avr-g++ -g -Wall -Os -mmcu=atmega8 -D F_CPU=8000000 -Wl -o SonarSRF05.elf main.
o ..\..\bin\cpplib.a
Creating load file for Flash: SonarSRF05.hex
avr-objcopy -O ihex -R .eeprom -g --strip-debug SonarSRF05.elf SonarSRF05.hex
avr-objdump -h -S SonarSRF05.elf > SonarSRF05.lst
Size after:
AVR Memory Usage
----------------
Device: atmega8
Program: 3748 bytes (45.8% Full)
(.text + .data + .bootloader)
Data: 190 bytes (18.6% Full)
(.data + .bss + .noinit)
-
Admin - you may also have noticed that in your makefile:
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
# Typical values are:
# F_CPU = 1000000
# F_CPU = 1843200
# F_CPU = 2000000
# F_CPU = 3686400
# F_CPU = 4000000
# F_CPU = 7372800
# F_CPU = 8000000
# F_CPU = 11059200
# F_CPU = 14745600
F_CPU = 16000000
# F_CPU = 18432000
# F_CPU = 20000000
# F_CPU = 3686400
Doesn't actually do anything! Which is why you have to redefine it in a header file in your project.
If you change your makefile:-
From:
# Place -D or -U options here
CDEFS =
To:
# Place -D or -U options here
CDEFS =-D F_CPU=$(F_CPU)
Then you can get rid of its redefinition in your headerfile and just control it from your makefile.
-
Webbot, it appears you are using the auto-generated makefile and not the external one?
I tried your code but still no luck . . . this time it didn't print anything but this:
Creating load file for Flash: AVR_Fish.hex
avr-objcopy -O ihex -R .eeprom AVR_Fish.elf AVR_Fish.hex
avr-objcopy: AVR_Fish.elf: File format not recognized
make: *** [AVR_Fish.hex] Error 1
Build succeeded with 0 Warnings...
Im trying to interpret this:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=62498&start=all&postdays=0&postorder=asc
It basically says a .hex file size has little to do with memory usage, because .hex is in ascii and has additional info (address, checksum, etc) that the uploaded binary wouldn't have.
-
Have you made the change from my post that starts: 'Hey admin try this:' ?
The changes there work with the .elf file not the .hex file.
using the auto-generated makefile and not the external one?
I'm just using Notepad to write my code and then using 'make' at the command line prompt.
Looks like your error is in turning the elf file to a hex file. Have you tried doing a 'clean' and then a fresh 'make' ?
-
I tried hex2bin.exe and got this:
Z:\>HEX2BIN AVR_Fish.hex binary.bin [/Z:]
HEX2BIN.EXE v3.1 - Converts Intel,Motorola and Tektronixs HEX files to BINARY
Supports 16,24 and 32 bit addressing formats
Copyright (c) 1994,1996
Read 1117 lines. Wrote 17840 bytes
and since that is the same byte count as when I modded the makefile:
Size after:
text data bss dec hex filename
0 17840 0 17840 45b0 AVR_Fish.hex
I am assuming my memory usage is 17840 bytes, right?
I don't have time to fully investigate why your suggestions aren't working . . . I tried rebuilding everything but still no luck . . . on with the next problem! :P
-
I am assuming my memory usage is 17840 bytes, right?
It'll probably be just under that as the hex file also contains any initialised data
-
yea true , experimenting with that the hex file has nothing to do with the flash size
i have my compiler telling me how much flash does the program consumes,
i guess the only way is to use such a software,,
-
Didn't any one check the wiki (http://en.wikipedia.org/wiki/.hex). ;)
Basically you can add up the first two digit hex value of each line and that is how many bytes will be written to flash when you program. Normally the first tow digit hex value is 10 (or 16 in decimal) so it's just as easy to count rows and multiply for a rough guess. If you are getting close enough to really really care, it's probably time to buy a bigger micro anyways.
As far as RAM usage... I don't know yet...
-
Didn't any one check the wiki.
Well no - coz hex files are a mix of data and code etc. I'm kinda happy with my makefile change above that shows code and data sizes as well % used for the controller.
Admin seemed a bit busy to pursue it, which is fine, but - has anyone else except me got this to work?