I am writing code for the ATMEGA128. After my program reached a
certain
size it crashes/resets in the middle of the program. If I increase
the size of the program further, even if that code won't be executed,
the MCU crashes very early in the program and hangs.
While investigating this problem, I made a simple program to test code
size (which is included below). I've incremented and deincremented 'i'
many times to increase the code size. with 404 increment and decrement
statements, the code is run correctly (the LED blinks). The addition
of one statement beyond that breaks the program.
It's interesting that the critical size of this program is much smaller
than my application, which did not exhibit code size sensative behavior
until it was 6.5 kB. My test program stopped working at 4.3 kB.
Any ideas about what could cause this problem?
--Kevin Neff
Here is the avr-size output, both the working (smaller) program and the
broken (larger) program.
avr-objcopy --strip-all -O ihex main.elf main.hex
text data bss dec hex filename
4312 0 0 4312 10d8 main.elfa
avr-gcc -mmcu=atmega128 -Wl,-Map=main.map,--cref main.o -o main.elf
avr-objcopy --strip-all -O ihex main.elf main.hex
text data bss dec hex filename
4322 0 0 4322 10e2 main.elf
Here's the difference between the avr-nm outputs.
# diff main_nm_fixed main_nm_broken
56,58c56,58
< 000010d8 A __data_load_end
< 000010d8 A __data_load_start
< 000010d8 T _etext
---
000010e2 A __data_load_end
000010e2 A __data_load_start
000010e2 T _etext
Here is the difference between the map files.
# diff main_fixed.map main_broken.map
4c4
< main_fixed.o (__do_clear_bss)
---
main_broken.o (__do_clear_bss)
18c18
< LOAD main_fixed.o
---
LOAD main_broken.o
113c113
< .text 0x00000000 0x10d8
---
.text 0x00000000 0x10e2
180c180
< .text 0x000000ca 0x100e main_fixed.o
---
.text 0x000000ca 0x1018 main_broken.o
182c182
< 0x000010d8 . = ALIGN (0x2)
---
0x000010e2 . = ALIGN (0x2)
---
0x000010e2 . = ALIGN (0x2)
184c184
< 0x000010d8 . = ALIGN (0x2)
---
0x000010e2 . = ALIGN (0x2)
195c195
< 0x000010d8 _etext = .
---
0x000010e2 _etext = .
197c197
< .data 0x00800100 0x0 load address 0x000010d8
---
.data 0x00800100 0x0 load address 0x000010e2
210,211c210,211
< 0x000010d8 __data_load_start =
LOADADDR (.data)< 0x000010d8
__data_load_end = (__data_load_start + SIZEOF (.data))
---
0x000010e2 __data_load_start =
LOADADDR (.data)> 0x000010e2
__data_load_end = (__data_load_start + SIZEOF (.data))
220c220
< .eeprom 0x00810000 0x0 load address 0x000010d8
---
.eeprom 0x00810000 0x0 load address 0x000010e2
287c287
< OUTPUT(main_fixed.elf elf32-avr)
---
OUTPUT(main_broken.elf elf32-avr)
299c299
< main_fixed.o
---
main_broken.o
301c301
< main_fixed.o
---
main_broken.o
305c305
< main_fixed.o
---
main_broken.o
342c342
< main main_fixed.o
---
main main_broken.o
Here is the listing of the test program.
#define __AVR_ATmega128__
#include <avr/io.h>
#include "../../bit_patterns.h" // B0 = 0x01, b0 = ~B0
int main()
{
int i = 0;
int status = 0;
DDRF = B0; // LED on this port
while( 1 )
{
// toggle LED
if( status == 0 )
{
PORTF = B0;
status = 1;
}
else
{
PORTF = 0;
status = 0;
}
i = 0;
i += 1; // line 30
i -= 1; // line 31
...
i += 1; // line 434
// this line must be commented out for the program to run
properly
i -= 1; // line 435
}
return 1;
}
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list