1
\$\begingroup\$

I'm new with Atmel Studio and I'm playing with ATtiny13. This mcu has 1K Bytes of Flash, 64 Bytes of EEPROM and 64 Bytes of SRAM.

I would like to know how much memory (flash, eeprom and sram) my code takes.

This is a piece of my compilation output.

I think my code takes 882 bytes of Flash and 15 bytes of EEPROM. Is that right?

Thanks in advance. code

\$\endgroup\$
9
  • 1
    \$\begingroup\$ 882 bytes of flash, and 15bytes of SRAM. \$\endgroup\$
    – Trevor_G
    Commented May 9, 2017 at 15:13
  • \$\begingroup\$ and what about the eeprom? \$\endgroup\$
    – Salva
    Commented May 9, 2017 at 15:19
  • 1
    \$\begingroup\$ The EEPROM is a peripheral and you need to keep track of the organization and usage of that on your own. \$\endgroup\$
    – Trevor_G
    Commented May 9, 2017 at 15:24
  • \$\begingroup\$ I understand. So, is not possible to see how much eeprom memory am I using, right? the only way is to track the code, right? \$\endgroup\$
    – Salva
    Commented May 9, 2017 at 15:27
  • 1
    \$\begingroup\$ Dude.. its just a list of constants one per address location with appropriate names. \$\endgroup\$
    – Trevor_G
    Commented May 9, 2017 at 16:00

2 Answers 2

2
\$\begingroup\$

The amount of memory your program uses has already been answered in the comments, but I would like to clarify how these different types of memory are used.

Flash is used to store the machine code that the CPU executes. It is nonvolatile, and is generally not modified at run-time (i.e. the flash is written once during upload, but it is not modified later by the CPU).

SRAM is where variables are stored. It is volatile, so the nothing is written into SRAM while the code is being uploaded. Rather, it is only modified by the CPU while it is running.

EEPROM is nonvolatile, but can also be modified by the CPU while it is running. The only way to access it is with special EEPROM registers such as EEDR, the EEPROM data register, EECR, the EEPROM control register, EEAR, the EEPROM address register, and several others. In order to read a byte of EEPROM for example, you must load the address of the byte you want into EEAR, then read the byte from EEDR. It is thus much slower to access EEPROM than SRAM. There is really no reason to use EEPROM except when you have modifiable data that you want to keep even when the ATtiny is unplugged.

By default, the compiler does not store any data in EEPROM, though it can be configured to do so.

\$\endgroup\$
1
\$\begingroup\$

As an addition to the other comments/answers:

You can keep track of how much EEPROM is used if you consequently use the EEMEM attribute for every variable you want to "map" to the EEPROM memory section.

If you declare a global/static variable like this

uint16_t EEMEM data_in_eeprom;

you can use it like this

eeprom_write_word(&data_in_eeprom, 1234);

and the compiler will manage the actual variable/memory addresses. This way, you will get information about the "EEPROM Memory Usage":

Program Memory Usage    :   7752 bytes   23,7 % Full
Data Memory Usage       :   918 bytes   44,8 % Full
EEPROM Memory Usage     :   2 bytes   0,2 % Full
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.