Fehlermeldung Arduino Mega 2560

Hallo,

habe heute mein Mega 2560 Board bekommen (kein original Arduino - laut Hersteller aber baugleich).
Nun wollte ich den Pragrammcode meines Roboters auf dieses Board übertragen, habe beim Kompilieren aber folgenden Fehlermeldung bekommen:

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+0x34): relocation truncated to fit: R_AVR_13_PCREL against symbol __vector_13' defined in .text.__vector_13 section in core.a(Tone.cpp.o)

kann damit leider nicht so viel anfangen.

Diese Fehlermeldung erscheint aber nur wenn der Arduino Mega 2560 eingestellt ist, für meinen Arduino Uno lässt sich das Programm problemlos kompilieren und auch hochladen.
Andererseits konnte ich aber das Programm Blink problemlos auf den Arduino Mega 2560 laden.

Hab trotzdem mal den Programmcode angehängt, möglicherweise liegt es an den eingebundenen Libraries.

Schon mal vielen Dank und viele Grüße

Simon

_2015-01-17_Roboter_3Ultrasonic.ino (6.03 KB)

Was der Fehler bedeutet ist hier erklärt:

Liegt an den unterschiedlichen JMP Befehlen die es gibt von denen der kürzere (2 Byte weniger) und schnellere (1 Takt weniger) RJMP nur +/-4kB von der aktuellen Stelle springen kann. Der Linker versucht dann den Code so zu platzieren dass das gut klappt, aber produziert dabei Fehler.

As the error message suggests, the issue has to do with the relocation (of code) which causes some truncation to occur. The message comes from the linker which is trying to map pieces of code to appropriate locations in the program memory.

When code is placed or moved to some location ("relocation") and this code is referred to from another piece of code, via JMP or CALL (i.e. a function call), the relocated address has to be added to the JMP or CALL instruction referring to it.

The AVR devices support two kinds of jump/call instructions: JMP vs. RJMP, and CALL vs. RCALL. The R variants make calls relative to the current location and are more efficient both in usage of program memory and execution time.

[...]

Therefore, if the linker decides it can put the code to be called within the +/-4kb range from the RJMP/RCALL there will be no problem, but if the linker fails to (re-)locate the code to be within that range, RJMP/RCALL cannot be used to reach the code's new address, the address is thus truncated

Was da zu den Link Switches steht, scheint aber auf dem Arduino nicht die Lösung zu sein, da -mshort-calls sowieso nicht verwendet wird.

Andere haben es durch ein Editieren des Make Files gelöst.

Im letzten Post ist vielleicht noch was das angenehmer ist. Da wird einfach ein Array im Flash am Anfang platziert. Und zwar zwischen die Interrupt Vektor Tabelle und den eigentlichen Code. Dadurch kann man man laut dem Post den Linker dazu bewegen keine RJMPs in der Vektor Tabelle zu verwenden.

Es kommt aber auch auf den genauen Wert an den man verwendet. Und das ist auch nur wenn der Linker nicht noch an einer andere Stelle herumpfuscht.