Pages: [1]   Go Down
Author Topic: Tiny85 PCREL error  (Read 4362 times)
0 Members and 1 Guest are viewing this topic.
Tennessee
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Retired EE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I am using the Tiny85 Arduino 'compiler' in the v0022 IDE, selecting ATtiny85 @ 1MHz as my board.  When I verify my code I sometimes get this PCREL error:

.../arduino-0022/arduino-0022/hardware/tools/avr/
bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2)
: relocation truncated to fit: R_AVR_13_PCREL against symbol `exit'
defined in .fini9 section in
.../arduino-0022/arduino-0022/hardware/tools/avr/
bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_exit.o)

If I delete practically any portion of the code the error goes away and I can download and run it successfully.  The error is code dependent, I can delete a little here and it will compile, or put that section back in and delete a little there and it will compile. I can make it bigger and it will sometimes compile when a smaller program won't compile. It compiles to about 4900 bytes in the about 7100 byte space.  Weird, and frustrating.

Direct me to a known solution or to an appropriate person or whatever...  Thanks!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12911
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


The problem stems from a bug in the linker.  This is the best description of the problem I've been able to find...

http://old.nabble.com/Advice-on-R_AVR_13_PCREL-errors-linking-for-Tiny85-_and_-Mega168-!-td21652985.html

Quote
Basically, the problem stems from the fact that the linker allows all devices in only the avr2 and avr4 architectures to wrap around the offsets. Devices in the avr25 architecture should be allowed to do that too (as avr25 is the same as avr2, plus 2 extra instructions), but for some reason it looks like the avr25 was forgotten when it comes to this reloc. It just so happens that the ATtiny85 belongs to the avr25 architecture. My work colleague mentions that he doesn't have this problem when he uses an ATmega8 (with the same amount of code space). And that is because the ATmega8 belongs to the avr4 architecture.

Fortunately, the bug was fixed long ago so upgrading the toolset takes care of the problem.


This is what I did (with the caveat that I may have forgotten some steps)...

● Ensure the Arduino IDE is not running
   
● Download the latest version of WinAVR from here...
http://winavr.sourceforge.net/
   
● Install WinAVR.  I installed to "C:\WinAVR\" and will use that directory name as an example.

● Locate the AVR toolset directory used by Arduino.  The directory name is "avr" and is located in "{ArduinoRoot}\hardware\tools\".

● Rename the AVR toolset directory.  In my case, I changed the directory name from "avr" to "avr (old)".

● Create a new directory named "avr"

● Copy all of WinAVR into the newly created AVR toolset directory.  In my case, I copied everything in "C:\WinAVR\" to "{ArduinoRoot}\hardware\tools\avr\".

● Create an "etc" directory in the "{ArduinoRoot}\hardware\tools\avr\" directory

● Locate and open the "avrdude.conf" file.  It is now located in the "{ArduinoRoot}\hardware\tools\avr\bin\" directory.

● Search for the "ATtiny25" section and make the following addition (the first element is page-el (pagel) not page-one)...

Quote
#------------------------------------------------------------
# ATtiny25
#------------------------------------------------------------

part
     id            = "t25";
     desc          = "ATtiny25";
     has_debugwire = yes;
     flash_instr   = 0xB4, 0x02, 0x12;
     eeprom_instr  = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D,
                0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC,
                0x99, 0xE1, 0xBB, 0xAC;
## no STK500 devcode in XML file, use the ATtiny45 one
     stk500_devcode   = 0x14;
##  avr910_devcode   = ?;
##  Try the AT90S2313 devcode:
     avr910_devcode   = 0x20;
     signature        = 0x1e 0x91 0x08;
     reset            = io;
     chip_erase_delay = 4500;
   pagel            = 0x00;
    bs2              = 0x00;

● Still working In the "ATtiny25" section, search for (or page down to) ... memory "lock" .. and change the entry to this...

Quote
    memory "lock"
         size            = 1;
         write           = "1 0 1 0  1 1 0 0  1 1 1 x  x x x x",
                           "x x x x  x x x x  1 1 i i  i i i i";
        read            = "0 1 0 1  1 0 0 0  0 0 0 0  0 0 0 0",
                           "0 0 0 0  0 0 0 0  o o o o  o o o o";

        min_write_delay = 9000;
        max_write_delay = 9000;
       ;

● Search for the "ATtiny45" section and make the following addition (the first element is page-el (pagel) not page-one)......

Quote
#------------------------------------------------------------
# ATtiny45
#------------------------------------------------------------

part
     id            = "t45";
     desc          = "ATtiny45";
     has_debugwire = yes;
     flash_instr   = 0xB4, 0x02, 0x12;
     eeprom_instr  = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D,
                0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC,
                0x99, 0xE1, 0xBB, 0xAC;
     stk500_devcode   = 0x14;
##  avr910_devcode   = ?;
##  Try the AT90S2313 devcode:
     avr910_devcode   = 0x20;
     signature        = 0x1e 0x92 0x06;
     reset            = io;
     chip_erase_delay = 4500;
   pagel            = 0x00;
    bs2              = 0x00;

● Still working In the "ATtiny45" section, search for (or page down to) ... memory "lock" .. and change the entry to this...

Quote
    memory "lock"
         size            = 1;
         write           = "1 0 1 0  1 1 0 0  1 1 1 x  x x x x",
                           "x x x x  x x x x  1 1 i i  i i i i";
        read            = "0 1 0 1  1 0 0 0  0 0 0 0  0 0 0 0",
                           "0 0 0 0  0 0 0 0  o o o o  o o o o";

        min_write_delay = 9000;
        max_write_delay = 9000;
       ;

● Finally, search for the "ATtiny85" section and make the following addition (the first element is page-el (pagel) not page-one)......

Quote
#------------------------------------------------------------
# ATtiny85
#------------------------------------------------------------

part
     id            = "t85";
     desc          = "ATtiny85";
     has_debugwire = yes;
     flash_instr   = 0xB4, 0x02, 0x12;
     eeprom_instr  = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D,
                0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC,
                0x99, 0xE1, 0xBB, 0xAC;
## no STK500 devcode in XML file, use the ATtiny45 one
     stk500_devcode   = 0x14;
##  avr910_devcode   = ?;
##  Try the AT90S2313 devcode:
     avr910_devcode   = 0x20;
     signature        = 0x1e 0x93 0x0b;
     reset            = io;
     chip_erase_delay = 4500;
   pagel            = 0xB3;
    bs2              = 0xB4;

● Still working In the "ATtiny85" section, search for (or page down to) ... memory "lock" .. and change the entry to this...

Quote
    memory "lock"
         size            = 1;
         write           = "1 0 1 0  1 1 0 0  1 1 1 x  x x x x",
                           "x x x x  x x x x  1 1 i i  i i i i";
        read            = "0 1 0 1  1 0 0 0  0 0 0 0  0 0 0 0",
                           "0 0 0 0  0 0 0 0  o o o o  o o o o";

        min_write_delay = 9000;
        max_write_delay = 9000;
       ;

● Save and close the "avrdude.conf" file.

● Copy the "avrdude.conf" file to the {ArduinoRoot}\hardware\tools\avr\etc\ directory


That's it.  You should now be able to start the Arduino IDE and continue work!


Switching to the previous AVR toolset...

● Ensure the Arduino IDE is not running

● Locate the current AVR toolset directory used by Arduino.  The directory name is "avr" and is located in "{ArduinoRoot}\hardware\tools\".

● Rename the current AVR toolset directory.  In my case, I changed the directory name from "avr" to "avr (new)".

● Rename the previous AVR toolset directory back to "avr".  In my case, I change the directory name from "avr (old)" to "avr".

● Start the Arduino IDE and continue work


Notes...

● I have not been able to find a definitive source for the "pagel" and "bs2" settings.  My suspicion is that the values should all be the same.  I've found people that have suggested 0xF0 / 0xF1, 0x00 / 0x00, and 0xB3 / 0xB4.  The values are used for "parallel programming".  If you don't do parallel programming, the values do not come into play.

● The memory "lock" entries are essentially meaningless.  The ATtinyX5 processors do not have lock bits.  The Tiny Core allows the fuses to be changed by executing "Burn Bootloader" from the Arduino IDE.  The memory "lock" entries appease the IDE into believing it has correctly installed a bootloader.
« Last Edit: June 08, 2014, 03:58:30 pm by Coding Badly » Logged

Tennessee
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Retired EE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot!  Works like a charm.  Only mistake I made was to type page1 (one) instead of pagel (el).  Glad to have the Tiny core as a very nice (and working) resource!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12911
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot!  Works like a charm.

You are welcome!

Quote
Only mistake I made was to type page1 (one) instead of pagel (el).

It is difficult to tell if that is a one or an el.  I updated the instructions.  Thanks for the feedback.
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great work.  Saved my butt. Thank you, thank you, thank you. Blessings on you and your posterity, free pizza, etc.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12911
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


You are welcome and thank you for the kind wishes.
Logged

Charleroi - Belgium
Offline Offline
Newbie
*
Karma: 1
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was having the same problem but with an ATtiny84.
This solution works also for the 84 models. I suppose that it's the same for the 44 (not tested). I precise that I've not modified for 44/84, but the error disapeared.
thank you very much for the tutorial.
Logged

73 de ON7KER Bertrand

Vivez si m'en croyez, cueillez dès aujourd'hui les roses de la vie.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 207
Posts: 12911
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you very much for the tutorial.

You are welcome.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Had been strugling  smiley-madsmiley-roll-sweat smiley-cry with this for the past 3 days!!

Thanks for coming to my rescue smiley-grin To the point and very well written!

Worked like a charm!   smiley smiley-lol

Thanks
Logged

Pages: [1]   Go Up
Jump to: