Weird compiler error after adding yet another delay statement

I have developed a class with a few methods for controlling a motor. It includes two delay statements and compiles and runs ok. After some testing I noticed the need for an additional delay statement for debouncing reasons. But this time it was easier said than done. If I include this extra delay statement, the compiler reports a weird compilation error:

d:/users/egbert/desktop/arduino-1.0.3/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function __vector_default': (.vectors+0x64): relocation truncated to fit: R_AVR_13_PCREL against symbol __vector_25' defined in .text.__vector_25 section in core.a(HardwareSerial.cpp.o)

It is even more weird as the same error appears when I put the delay statement in another class or in a particular part of the loop() section. I'm lost.....any suggestions?

Btw, I have a Mega 2560 board.
Egbert, Netherlands

If the compilation or uploading in process and you press the compilation buttons again, such type of error accurs to me and especially i can recognise core.a.. but instead of the error compilation working fine, so i no worry about such error...
Is it the case.. do you able to upload the sketch to Arduino?.. or compilation never occur??

Hi, I didn't press the compilation button twice and it isn't uploading as this is not possible because of the error. So it's a normal and straight forward compilation action. For me there is no logical reason, from user perspective, for this error. I assume it is some hick up in the IDE. Or maybe I just have a demo version of the IDE with the a limitation on the number of delay statements in a program XD Well, I did some reprogramming to overcome this mysterious error.

Then , i shall not ask you to share the sketch with all libraries to track down the problem by some of our gurus here ]:smiley: :grin:

Its to do with where the compiler places the hardware serial interrupt routines (ISRs) in the flash. Something causes it to put the ISRs too far away from the start of the program for the vector table (a lookup table for where the ISRs are) to call them.
(See here for full explaination: Arduino Forum )

There is something weird going on as someone else reported a similar problem. By any chance if you enable verbose output during complilation (File->Preferences), do you get any other warnings?

There is a temporary work around, but without testing I don’t know if it will have any unforseen side effects - it shouldn’t I don’t think.

Open the directory in which the arduino program files are stored, then go to:
hardware\arduino\cores\arduino

Open ‘HardwareSerial.h’ and add the following lines to the VERY TOP of the file:

#ifndef HardwareSerial_h
#if defined(USART_RX_vect)
  SIGNAL(USART_RX_vect)  __attribute__ ((section (".init8")));
#elif defined(SIG_USART0_RECV)
  SIGNAL(SIG_USART0_RECV)  __attribute__ ((section (".init8")));
#elif defined(SIG_UART0_RECV)
  SIGNAL(SIG_UART0_RECV)  __attribute__ ((section (".init8")));
#elif defined(USART0_RX_vect)
  SIGNAL(USART0_RX_vect)  __attribute__ ((section (".init8")));
#elif defined(SIG_UART_RECV)
  SIGNAL(SIG_UART_RECV)  __attribute__ ((section (".init8")));
#endif
#endif

I've tried to reproduce the error after modifying the program and didn't succeed. I can add as many delays now as I want; good news! :wink: I will keep your workarround in mind in case the error pops up again. And re the warnings: no relevant warnings are being reported only about some unused variables.

Thanks anyway guys for your quick reactions.

Just do, during compilation process press the Compile button..and you will find the error.. Actually this appears for long programms...i imagine your program is a bit bigger than 20Kb? :grin:

Noooo, it’s only 7k+ at the moment XD
It will soon exceed 20k though I’m sure as the compiler ‘punish’ me with lots of extra bytes each time I add some silly little statement :P. Even after adding one simple AttachInterrupt the code size explodes to 8k+ ]:slight_smile: Talking about weird…

Code size isn't the real issue, i got to 95kB in one of my projects on a mega and never ran into this problem. Something is confusing the compiler with regards to where it puts interrupt service routines.

Even after adding one simple AttachInterrupt the code size explodes to 8k+

Lots of extra code is required to handle interrupts. Of course, this whole discussion is a waste of time if you don't post your code, as you are supposed to in the Programming section.

Thanks for the hint. If I want to start a discussion on the AttachInterrupt issue, I will post the code. At the moment it isn't an issue as I decided to not use interrupts in my project after all.

Charm:
Thanks for the hint. If I want to start a discussion on the AttachInterrupt issue, I will post the code. At the moment it isn't an issue as I decided to not use interrupts in my project after all.

Can I take it that you don't want any more help on this topic, then?

The issue I started this topic for, has been 'solved'. See my earlier posts. I simply cannot reproduce it anymore after changing the code.

I still belive that was not an issue at all.. :grin: This appear time and again here...i still belive this will come to you sooner again... ]:smiley:

@ Tom Carpenter…

Thanks Tom - Your patch fixed my problem.

FYI - I am writing a very large Sketch with a huge amount of text in PROGMEM. Currently it is …
“Binary sketch size: 107,726 bytes (of a 258,048 byte maximum)”
and just over half finished. It has every type of interrupt you could think of and then some!

I was getting this error after adding some new text strings and I assumed the interrupt vectors were ending up outside the pointer offset range of the compiler.
So I minimised the string lengths and that got it working again, but I had to address the problem eventually as I knew it would arise again as the sketch bloated away.

I applied your code and added back all my text strings (and then some) and it is working fine. I can now move on to the ‘next’ brick wall that I will hit my head on!!! (<< note the 3 x ‘!’ - that one cost me 3 daze…)
Baz