4
\$\begingroup\$

The flash memory of atmega8 is 8Kb.

Is this the maximum size for the .hex file, or it the max memory which i can allocate to variables in my code?

If none of the above is true, than what is memory allocation structure of Atmega8? To which memory does .hex file goes to?

\$\endgroup\$

3 Answers 3

3
\$\begingroup\$

In standard use your code goes into the 8 Kbytes of Flash memory and variables go into the 1 Kbyte of SRAM. Note that because a hex file represents a single byte as a pair of hexadecimal characters and contains some other information it will be over twice the size of the actual code that will be loaded, so a hex file a bit over 16K should load.

The most reliable place to find out of much Flash and SRAM your code uses is from the compiler. If you're using Atmel Studio 6 in the build output area if you scroll up you should see something like:

Program Memory Usage : 540 bytes 0.8 % Full

Data Memory Usage : 0 bytes 0.0 % Full

So the program memory use shows how much of the Flash will be used and data memory usage shows how much of the SRAM will be used.

\$\endgroup\$
7
  • \$\begingroup\$ And EEPROM? Can it be included in the hex? \$\endgroup\$
    – user17592
    Commented Jun 21, 2013 at 6:18
  • 1
    \$\begingroup\$ @CamilStaps, unless it's changed recently most Atmel compilers keep that in a seperate file. \$\endgroup\$
    – PeterJ
    Commented Jun 21, 2013 at 6:19
  • \$\begingroup\$ very very thanks to you @peterj.Actually this is the structure what i want to know.By the way i'm coding in cvAVR.plz tell me where to check this in it? Also what will happen if my code size exceeds the flash memory? \$\endgroup\$
    – shafeeq
    Commented Jun 21, 2013 at 6:25
  • \$\begingroup\$ @shafeeq, it's been a long time since I've used cvAVR but I think you need to find where to turn on either the listing or map file options under the project and then you'll either get a .map or .lst file that contains it. When it runs out you'll get a compiler error, it won't damage anything you just won't be able to load it. \$\endgroup\$
    – PeterJ
    Commented Jun 21, 2013 at 6:28
  • \$\begingroup\$ so @PeterJ nothing will happen like this as only that part of code is loaded uptil memory is filled and then remaining code is left out and when we run MCU it behaves abnormally. \$\endgroup\$
    – shafeeq
    Commented Jun 21, 2013 at 6:33
2
\$\begingroup\$

The flash memory is your program memory. That would be where your hex file is stored. You can force data into flash if you're tight on RAM, but it isn't as fast of a read/write as RAM.

RAM is the memory used at run time, for variables and whatever other else needs to be accessed on the fly.

EEPROM is nonvolatile memory for storing things such as calibration data, serial numbers, etc. It is rarely used for anything that needs to be written regularly.

\$\endgroup\$
2
  • \$\begingroup\$ so @matt .hex goes to flash and during excecution variables are created in RAM ,used,then decomposed.use of EEPROM is to store global variable Data or constants of program.is it the whole Structure? if this is not then plz tell me right interpretation of above piece of knowledge. \$\endgroup\$
    – shafeeq
    Commented Jun 21, 2013 at 6:30
  • \$\begingroup\$ While any program depends on Flash (code) and SRAM (variable heap/stack) to run, using the EEPROM is entirely optional. EEPROM is commonly used to store configuration data for example. \$\endgroup\$
    – Rev
    Commented Jun 21, 2013 at 6:44
0
\$\begingroup\$

For actual memory usage see map file. In case of GCC tool-chain that do by linker as:

avr-ld -Map=app.map

or through gcc driver:

avr-gcc -Wl,-Map,app.map
\$\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.