c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default':
(.vectors+0x10): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_4' defined in .text.__vector_4 section in core.a(WInterrupts.c.o)
This is the error I get when compiling. I say it is for no good reason because I reloaded a previous version of my sketch and started retracing my steps. The problem occurs when I remove or comment the following println statement.
...
case 36:
//RDIR
data[3] = buffer[bottom];
bottom++;
if (ENABLE_TEST_MODE) Serial.println("Case statement RDIR");
break;
...
For now, I have replaced that statement with delayMicroseconds(1) and that seems to be a bandaid but I'm a little concerned now. I have a lot riding on this project and can't waste a lot of hours fighting with a compiler.
Apologies if I haven't included enough information, I'm really not certain what will be relevant to this problem or not. To that end, I will dump a bunch of info here:
Things I have tried:
Restarting IDE
Trying same file on different computer
Copying file, renaming it, putting it in a different folder
The aforementioned previous version
Both my PCs are on Win 7 and I'm running an Arduino Mega 2560, although I don't have to try to upload the file to get this error, just clicking 'verify' so the Mega itself can't be to blame... I think.
Code uses the Timer3 library from arduino.cc - no other customizations have been made.
I can post the whole code if needed, it's pretty long... since I don't know what the actual problem is I just included the snippet that was giving the symptom even though I don't believe it is the cause.
Please let me know what else I can do to help the kind folks who take time to dig into this with me.
Sounds like a memory problem.
What do you get for RAM usage after a compile?
You have 1141 bytes wirth of constant strings and global variables (with the big block of comments at the bottom uncommented)
And without the test stuff, 889 bytes.
You can cut RAM usage WAY down by putting your constant strings in F() macros, forcing them to live in Program Memory.
Serial.println( F("Waiting for start" ) );
With testing stuff in, you'll save 435 bytes
With testibg stuff out, you'll save 183 bytes
So, I like that tip about the F() macro, had never heard that one (as you could have guessed). But I'm still a little confused. Here's my thought process:
a. Yesterday afternoon I had a println in all four case statements and the code was running
b. Remove those printlns (they were not printing even though the switch/case was working, not sure why)
c. Able to remove three, but removing the fourth makes it break
d. Change the code with F() so that the strings use less memory ... .... ....
e. There's no way that should work because I already was reducing the number of strings, and it was removing one that made the compile freak out........
f. the F() seems to have fixed the problem .... ... ... ... .. .. .. ... .. . .. .. .. ... ... !
Why wouldn't removing the println entirely also fix the problem? How is it possible that removing a println would cause this error?
The error message is reporting a link error. The compiler is trying to use a compact form of a relative address but the relative address it has got is too big to be held in that form. In effect, it is trying to reach an address which is 'too far away' in address terms. This sort of problem can be affected in very unintuitive ways by anything which affects the address of a piece of code. Some possible workarounds were discussed here: