Where does avr-size get the data for supported devices?

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

Hey,

 

I've downloaded the AVR 8-bit Toolchain 3.5.4 - Linux 64-bit from Microchip. The information / data regarding the ATmega328PB isn't included. Therefore I've downloaded Atmel ATmega Series Device Support (1.2.209) and copied some files into my toolchain folder:

"toolchain folder"/avr/lib/avr5/libatmega328pb.a

"toolchain folder"/avr/lib/avr5/crtatmega328pb.o

"toolchain folder"/avr/include/avr/iom328pb.h

"toolchain folder"/lib/gcc/avr/4.9.2/device-specs/specs-atmega328pb

 

Compiling works fine but avr-size tells me: "Device: Unknown". Command line:

"toolchain folder"/bin/avr-size -C --mcu=atmega328pb "project folder"/main.elf

Output

AVR Memory Usage
----------------
Device: Unknown

Program:    1288 bytes
(.text + .data + .bootloader)

Data:          7 bytes
(.data + .bss + .noinit)

 

It works for example if I tell avr-size that I'm working with an ATmega8 instead of the ATmega328PB.

"toolchain folder"/bin/avr-size -C --mcu=atmega8 "project folder"/main.elf

Output

AVR Memory Usage
----------------
Device: atmega8

Program:    1288 bytes (15.7% Full)
(.text + .data + .bootloader)

Data:          7 bytes (0.7% Full)
(.data + .bss + .noinit)

 

It's clear that avr-size can't find the needed information regarding the ATmega328PB. Unfortunately I don't know how I can give avr-size the needed information. Please point me in the right direction :-) Thanks!

This topic has a solution.

Regards Max

Last Edited: Fri. Apr 13, 2018 - 07:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The patch to avr-size that supports -C used to be maintained by Eric Weddington (the issuer of WinAVR) so that every time there was a new issue of avr-size he would apply the patch to support -C. But his involvement in avr-size stopped in about 2010 so I don't think the device list has been updated since then.

 

To combat that, in Atmel Studio 5, 6 and then 7 Atmel added their own utility that runs avr-size in a generic mode (-A or -B), captures the output then post processes it against a knowledge of the device that is being built for and a list of the memory sizes in each device. So when you build with AS7 you will see output for 328PB but do not expect to see it from avr-size using -C

 

Actually when I look at the (current) generic source for the binutils size utility:

 

https://sourceware.org/git/gitwe...

 

It seems like the "help" only mentions -A and -B but not the -C that Eric added. So I think any copies of avr-size you may have access to that will even admit to a -C option probably date from almost 10 years ago

 

Actually I say that but I just googled for the patch that adds -C and hit this:

 

https://gist.github.com/larsimmi...

 

That says it was updated 5 years ago. (but sadly I think the 328PB came within the last 5 years).

 

Obviously knowing it is 32K (and 2K SRAM is it?) you could write a utility in Python or similar that invokes avr-size with -A or -B (or even -C with "unknown" output), captures the output and post processes it to work out the % usage.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

The 'improved' way is to use avr-objdump -Pmem-usage <path to elf>. This reads the sizes embedded into a section in the elf file instead of having a big table in the tool itself:

>avr-objdump -Pmem-usage app.elf

app.elf:     file format elf32-avr
AVR Memory Usage
----------------
Device: atmega324pb

Program:     234 bytes (0.7% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

The data itself is embedded in .note.gnu.avr.deviceinfo

>avr-readelf.exe -x .note.gnu.avr.deviceinfo app.elf

Hex dump of section '.note.gnu.avr.deviceinfo':
  0x00000000 04000000 2e000000 01000000 41565200 ............AVR.
  0x00000010 00000000 00800000 00010000 00080000 ................
  0x00000020 00000000 00040000 08000000 01000000 ................
  0x00000030 0061746d 65676133 32347062 00000000 .atmega324pb....

 

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

Last Edited: Fri. Apr 13, 2018 - 04:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you both for your fast, informal and very helpful reply!

 

@clawson: That's good to know! It works using the ATmega328p for example. One could define a supported microcontroller with program memory and SRAM according to the used one.

 

@meolsen: Using avr-objdump works very well. I'll edit my makefile to use it instead of avr-size in the future.

 

 

edit

If someone is planning on doing the same, this is what I did:

 

old Makefile

SIZE = $(DIRAVR)/bin/avr-size

ELFSIZE = $(SIZE) -C --mcu=$(MCU) $(TARGET).elf

 

new Makefile

SIZE = $(DIRAVR)/bin/avr-objdump

ELFSIZE = $(SIZE) -Pmem-usage $(TARGET).elf

 

Regards Max

Last Edited: Fri. Apr 13, 2018 - 06:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just note that you need a 'fairly recent' version of avr-gcc for it to put this section in (as in no more than a year or two old...)

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)