Adding a 3K data block and program falls over

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

Hi

Running latest 2007 version and have a problem I can’t seem to fix/explain

Processor is an Atmel 2560
Current program size = 30428 bytes.

Program consists of multiple modules and works well. The WinAVR is an impressive compiler.

Ok … all I do is add a block of data

unsigned char image_data[3352] = { 0x12 …… Ox34 };

Program size increases to 33772 bytes.
Program runs and resets itself after getting to a specific point in code.
The actual block of data need not even be processed. Just adding it causes the program to fall over. This appears to be a compiler issue .. or something needs to done that I am not aware of.

Any clues anybody
Thanx
Brian

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

If you don't specify otherwise that entire table will be located into the precious SRAM and this is probably what's running out. The data values will be built into the image in code flash but as the program starts they will then be copied out from code flash to the .data section in SRAM. If you want to tell the compiler that "this is a const data and I only want the copy that's in code flash and I don't want it copied out to SRAM" then you need to use PROGMEM and then read the data with pgm_read_byte(). There is an excellent tutorial about the use of PROGMEM in the Tutorial Forum under a thread title including the word PROGMEM

Cliff

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

Thanx cliff.

I will look into this.
I did try using the 'const' statement to specify flash data, but that too had same result. Need to look into the PROGMEM function. Did not know about this.

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

You probably found it already but this is the thread:

https://www.avrfreaks.net/index.p...

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

Ok .. made the changes using PROGMEM and pgm_read_byte().

All works . No resets. You called it correctly Cliff. Learned something new today.

Thanx again
Brian