I've written some simple code that works if I compile it using the IDE. Trying to understand more of the process I looked at the verbose build log and used these commands to compile the code myself. As I strictly used non-arduino functions I didn't link against core.a.
The problem:
for(ctr=0; etc. etc.) {
PORTB = 0xFF;
PORTB &= ~( (1<<ctr) );
}
works just fine and the LEDs light up. For sake of simplicity I've left out the _delay_ms().
Now as I've got a small bug on my PCB, I need to remap 2 LEDs to make the sequence correct. Thus:
uint8_t fix_led_numbering[8] = {0,1,2,3,4,6,5,7};
for(ctr=0; etc. etc.) {
PORTB = 0xFF;
PORTB &= ~( (1<<fix_led_numbering[ctr]) );
}
This doesn't work if compiled by hand. I've verified that the array actually exists. It shows up in the disassembled elf file just fine.
Behaviour:
using no arrays: LEDs light up one after another, but wrong sequence (PCB bug).
with array: just 3 LEDs light up in a strange order. I have a feeling that it doesn't use the contents of the array, but maybe the pointer address (wild guess).
I've looked at the assembler code, but I'm not skilled enough to spot the error.
Here's the code + disassembled elf
It was compiled with this set of commands:
avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections $1 -o $1.o
avr-gcc -Os -Wl,--gc-sections -o $1.elf $1.o -lm
avr-objcopy -O ihex -R .eeprom $1.elf $1.hex
avr-size $1.hex
I really don't understand why using an array confuses the little cpu that much.