Sunday 22 April 2012

 Double the space – using a 1284P on Sanguinololu.

(Edit - see summary at end, the first attempts were not completely successful)


We have recently had a number of inquiries about upgrading the ATMEGA 644P on Sanguinololu to the ATMEGA 1284P. The original specs on the reprap wiki for the board stated it was “drop-in compatible”. It is physically; both the 644P and the 1284P are the same 40 pin DIP package, with the same pin-outs. Turns out it is not as “drop-in compatible” as far as bootloaders and firmware go.

A number of threads on the forums have talked about using this chip, either on the Sanguinololu or the Gen 7 electronics with people suggesting the Mighty 1248P bootloader. Written by ManiacBug and available on github this bootloader suffers from one rather large issue – it's designed for Arduino 1.0. The firmware I am familiar with  (Sprinter and Marlin) are pre-1.0 Arduino. A bit more searching found that there was a version of Sanguino available for Arduino 0023 which supported the 1284P. Brilliant!

Loading the bootloader

The first thing to be aware of is that you need a ISP capable of working with the 1284P. We have previously used the USBTiny ISP by ladyada, which works great; reliable and economical, but cannot handle AVRs with flash memory over 64k. Looking around I got hold of a Pololu ISP, which can handle the 1284P.

Getting the Pololu ISP recognised by my computer in Windows 7 was straightforward. The ISP also has a TTL breakout as a second COM port but this is not required here. If you are used to the USBtiny, be aware that the Pololu ISP does not provide power through the ISCP connection. This fact was lost on me the first time I tried to load the bootloader, but after applying power separately to the Sanguinololu board it works fine.


Be sure to pick the Pololu USB AVR Programmer Programming Port – COM 40 in this example.

The next step is to get the Arduino IDE setup right in order to burn the bootloader. I had to configure two things, the new Pololu ISP, and the 1284P bootloader.
Starting with the ISP; I added the following lines to “Arduino-0023\hardware\arduino\programmers.txt”:

avrispv2.name=AVR ISP v2
avrispv2.communication=serial
avrispv2.protocol=avrispv2



The  option “AVR ISP v2” will now appear within the IDE under the programmers menu.

For the 1284P bootloader I got the Sanguino files from google code and installed them within the Arduino directory. I extracted the entire zip into “Arduino-0023\hardware\Sanguino\”. Restarting the Arduino-0023 IDE gives:
 (note the Mighty 1284P... listing is there from previous experimenting)

I burnt the “Sanguino W/ATMega1284p 16Mhz” bootloader using the AVR ISP v2 programmer selection with no issues.

Quick Test

To confirm the bootloader had uploaded properly I ran a couple of quick test programs from the Arduino examples:

“Blink” worked fine, changed the blinking pin to pin 31 as this is easily accessible on the expansion header (A0 on extension header). (edit thanks to Alan Ryder - I had my analogue port numbering back to front and originally wrote pin 24, which is actually A7)

Next test was the “AnalogInOutSerial” example which also worked fine:


Passing these quick tests gave me the confidence that the bootloader was working. Next: Firmware.

Firmware

Sprinter compiles fine in Arduino 0023 choosing the Sanguino 644P option and so I had high hopes for it compiling with no issues choosing the 1284P. It did compile ok but then proceeded to hand on upload with no errors, just an infinite time to upload.

Doing a bit more searching I came across eMaker’s 1284P Github download (not sure why I did not find this earlier!). JM references Steve’s Fix It Shop blog where he mentions the different fuse settings required as the Sanguinololu uses a ceramic resonator, not a crystal oscillator:

Low 0xD6
High 0xDC
Ext  0xFD

These fuses get set in the boards.txt file.

So with a new fuse settings in the boards.txt I started from the beginning again. Upload bootloader: Tried the Sanguino 0023 version again with the different fuse settings and got the following error for the Arduino IDE:

avrdude: invalid byte value (null) specified for immediate mode
avrdude: write to file 'null' failed

With more than a little frustration I gave up on the Sanguino 0023R3 bootloader and switched to the version that came in the zip from JM at eMaker linked above. In the readme it is stated to be the Mighty 1284P; however the boards.txt file looks identical to the Sanguino 0023R3 with the modified fuse settings.

Update: make sure you copy the avrdude.conf from JM's zip. This contains the definition of the 1284p - if you don't have this then the Arduino environment will say that a 1284p is "unknown". I overwrote the stock avrdude.conf in arduino-0023\hardware\tools\avr\etc\

 This time the bootloader uploaded with no problems and a quick test with the "AnalogInOutSerial" example went fine as well.

Third time lucky with the Sprinter upload! A quick test with pronterface shows the firmware connects and talks back (M105 gives temp return).

Next test was Marlin which also uploaded fine. I setup the board in a test environment with a potentiometer in place of the hotend thermistor for the extruder (to trick the firmware into thinking the hotend was hot) and with no stepper drivers or anything connected. I then dumped a large g-code file onto an SD card and will let that run for a bit to see if anything breaks before connecting the board to an actual printer:



Summary

  • Use a ISP programmer capable of burning a AVR with 128k flash, like the Pololu programmer.
  • Check your fuse settings, Crystal Oscillators vs Ceramic Resonators.
  • I had best luck with Jean-Marc's bundle of bootloader and Sanguno core, available on github  
Tony


8 comments:

  1. Couple of updates, the main one being:

    "make sure you copy the avrdude.conf from JM's zip. This contains the definition of the 1284p, if you don't have this then the Arduino environment will say that a 1284p is "unknown". I overwrote the stock avrdude.conf in arduino-0023\hardware\tools\avr\etc\ "

    ReplyDelete
  2. Thanks for this - really helpful article.

    Something that got me stumped was that I found that the avrdude.conf was unzipped into the wrong directory: arduino-0023\hardware\tools

    So I had to move it after extracting the zip to arduino-0023\hardware\tools\avr\etc\

    I know you already said this but when I saw the file in arduino-0023\hardware\tools I just assumed it was in the right place and didn't spot the exact path.

    Thanks again

    ReplyDelete
  3. Don't forget to use 120 ohm resistor between reset and 5V to disable auto reset using Arduino as ISP.

    http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

    ReplyDelete
  4. Hi there, great info, I followed it very carefully but I get the following error:

    avrdude: stk500v2_command(): command failed
    avrdude: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    This is at the loading the bootloader stage. I am actually trying to burn the atmega644 bootloader to an atmega644 chip but thought I would follow your guide becuase it is well explained. Unfortunately, I must have gone wrong somewhere, any idea?

    ReplyDelete
    Replies
    1. hi

      What ISP are you using?

      Delete
    2. Hi, I was am using the same as in your guide. I am sure I did everything exactly as you said but still have this issue. Any ideas what I might have done wrong?

      Delete
  5. Thanks, this helped alot. I found that I had to burn the bootloader using yours and an Arduino Uno programmed as an AVR ISP then restore the standard hardware setup I had in there to program my Sanguino board with Marlin. Worked great then.

    ReplyDelete
  6. Hi,
    I get this

    avrdude -C /etc/avrdude.conf -c usbtiny -p atmega1284p -B 1 -U flash:w:./ATmegaBOOT_1284P_8MHz.hex

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.00s

    avrdude: Device signature = 0x1e9705 (probably m1284p)
    avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
    To disable this feature, specify the -D option.
    avrdude: erasing chip
    avrdude: reading input file "./ATmegaBOOT_1284P_8MHz.hex"
    avrdude: input file ./ATmegaBOOT_1284P_8MHz.hex auto detected as Intel Hex
    avrdude: writing flash (130824 bytes):

    Writing | ################################################## | 100% 0.00s

    avrdude: 130824 bytes of flash written
    avrdude: verifying flash memory against ./ATmegaBOOT_1284P_8MHz.hex:
    avrdude: load data flash data from input file ./ATmegaBOOT_1284P_8MHz.hex:
    avrdude: input file ./ATmegaBOOT_1284P_8MHz.hex auto detected as Intel Hex
    avrdude: input file ./ATmegaBOOT_1284P_8MHz.hex contains 130824 bytes
    avrdude: reading on-chip flash data:

    Reading | ################################################## | 100% 0.00s

    avrdude: verifying ...
    avrdude: verification error, first mismatch at byte 0x1f800
    0xff != 0x0c
    avrdude: verification error; content mismatch

    avrdude: safemode: Fuses OK (E:FC, H:DC, L:F7)

    avrdude done. Thank you.

    ReplyDelete

Comments are now moderated to reduce spam, please excuse the additional time this will entail.

Note: only a member of this blog may post a comment.