Memory overflow of 2KB on atmega328 16KB | WHAT?

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

I'm getting this error:

Severity    Code    Description    Project    File    Line
Error        Program Memory Usage     :    2464 bytes   7.5 % Full
                Data Memory Usage         :    2390 bytes   116.7 % Full    (Memory Overflow)    

 

but the 328 has memory of 16KB?

 

What am I doing wrong here? 

 

Code is everything, code is life :D
 

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

32K Flash - but only 2K RAM: http://www.atmel.com/devices/atm...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jul 28, 2016 - 08:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

M328 only has 2K bytes of SRAM. Data Memory = SRAM! Definitely over-full!  32K bytes of program memory. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Okay, how can I reduce ram than? I have alot of calculations with arrays? Something with malloc? Haven't worked with them before.

 

Thanks for the info

Code is everything, code is life :D
 

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

Malloc uses sram, also. So does stack. If you are using more than 75% to 80% of sram, you also have no room for stack!

 

Big user can be strings. Use PROGMEM or newer methods to keep constant strings from being copied into sram. 

 

If it is ram-intensive, you may need to migrate to a device with more data memory!

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. Jul 28, 2016 - 08:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes progmem is working nicely, thank you!

Code is everything, code is life :D
 

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

Remember, you really need to keep the used data space under 75-80% of the available sram.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

I will, thank you.

Code is everything, code is life :D
 

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

If you have a bunch of strings and they are not declared as flash, they get copied to ram at poweron and soak up ram.

 

Imagecraft compiler user

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

gproduct wrote:

Yes progmem is working nicely, thank you!

PROGMEM is the old way to do it. If you are writing new code and using an up to date compiler life gets far simpler if you switch from PROGMEM to __flash.

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

clawson wrote:

PROGMEM is the old way to do it. If you are writing new code and using an up to date compiler life gets far simpler if you switch from PROGMEM to __flash.

I was just recently doing some audio work that needed to use program memory and I was trying to remember what the new way of doing it without the PROGMEM and pgm_read_byte. In the end, I didn't bother to search for it because it was a quick throwaway prototype and just wanted to get it done but I will need to remember about __flash for later! Thanks, Cliff!

My digital portfolio: www.jamisonjerving.com

My game company: www.polygonbyte.com

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

gproduct wrote:
Okay, how can I reduce ram [usage] then?

The first thing to do is to find what's actually using all that RAM.

 

You do this by looking at the so-called Map File - which, as the name suggests, maps out what is using how much memory, and where ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some folks (that includes me!) find the output of nm more palatable than wading through the .map file. Your mileage may vary.

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

Thanks for the reminder:

 

https://sourceware.org/binutils/...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...