Showing posts with label Pololu AVR programmer. Show all posts
Showing posts with label Pololu AVR programmer. Show all posts

Sunday, 22 July 2012

Disabling JTAG on PrintrBoard

Disabling JTAG on PrintrBoard - Get 4 more I/O pins

As I discovered while getting the Panelolu working with a Printrboard the JTAG interface is enabled by default. This uses 4 pins on one of the expansion headers:


In order to get access to these pins the JTAG interface needs to be disabled: to do this you have to change the fuses on the AT90USB1286 micro. An ISP is required (I use the Pololu AVR ISP) but others should work fine.

Warning: You can "brick" your micro if you mess up the fuse settings: handle with care and I don't recommend you mess with the clock settings!

Lincomatic describes how to set the fuses in his blog post on uploading a bootloader to the AT90USB1286. He has the following settings

LOW : 0xDE
HIGH: 0x9B
EXT: 0xF0

Using the fuse calculator at engbedded.com, start by selecting the AT90USB1286 and then put the DE,9B and F0 setting in at the bottom of the page. After applying these settings it is simple to deselect the "JTAG Interface Enabled" check box and recalculate the settings. The only one which has changed is the HIGH setting to 0xDB

Using the version of avrdude that comes with arduino 0023 change the fuse setting to disable the JTAG interface:

avrdude -c avrispv2 -p at90usb1286 -U hfuse:w:0xdb:m  -C ..\etc\avrdude.conf -P com40

You will need to change the "-c avrisp2" to match your ISP and the "-P com40" to match the com port it's on.

Now that we have read-write access to those pins the connections for the Panelolu can use 1 less plug and stay on just one expansion header:


The pin allocations are:

With pin numbering of:
TDI = 42
TDO =43
TMS = 44
TCK = 45

The only change to the firmware from that described in my previous post is:

pins.h

      #define LCD_PINS_D4        42
      #define LCD_PINS_D5        43
      #define LCD_PINS_D6        44
      #define LCD_PINS_D7        45
 
So if you have an ISP and want 4 more IO pins this is the way to go. If you are going to buy a Printrboard then ensure you get your supplier to change the fuses to disable the JTAG interface before sending it to you.

Panelolu with Printrboard

Panelolu with Printrboard

Update: The Panelolu2 has replaced the Panelolu. It is much quicker to install, has adapter boards to no messing with cables and uses less pins. The blog post with the information is here, it is available to buy in our webshop.

The Printrboard is a based on the Teensylu which is itself a derivative of the Sanguinololu; the main difference is the use of the AT90USB1286  in place of the ATmega644P or 1284P.


Thanks to the work of Lincomatic, Marlin firmware will run on the AT90USB1286. The Printrboard section of the RepRap wiki page has information on the board and an outline of how to upload the firmware - you will need Lincomatic's fork of Marlin. The Printrboard I bought was supposed to come with a bootloader but that did not work. I followed Lincomatic's instructions to install the CDC bootloader using the Pololu ISP I have used previously on ATmega644P and ATmega1284P micros. It's worth ensuring you have a working setup with the Printrboard connecting to your control software (Pronterface for me) and firmware uploading before you go any further.

Built in SD card reader or SDSL?

The Printrboard has a build in SD card reader so you do not need an SDSL. That said I prefer to have the electronics hidden away, so using the SDSL in the Panelolu is my preference. Both options will work and are described below.

Hardware and wiring the Panelolu

The wiring internal to the Panelolu is identical to that described in my previous post, with the option not to bother with wires 13,15,16,17,19,20,21,22 and the 10 pin IDC connector if you are going to use the build in SD card reader on the Printrboard.
Unfortunately the design of the expansion headers on the Printrboard does not keep to the standard 2.54mm spacing between the expansion header and the ISP header (and 4 pins on ext1 are not I/O by default) - a simple IDC connector will not fit without bending the pins . The solution is to use the same connectors that are used on the LCD and circuit board within the Panelolu.


The pin out is as follows:
 
Ribbon cable wire number
Printrboard Pin Label
Marlin Pin
number
Marlin Pin
name
 1
 Not used *
---
---
 2
 Not used *
---
---
 3
 GND
---
---
 4
 5V
---
---
 5
 PD4
4
LCD_PINS_D7
 6
 A3
41
LCD_PINS_RS
 7
 PD6
6
LCD_PINS_D6 
 8
 TX1
2
ENC1
 9
 PE1
9
LCD_PINS_D5
 10
 RX1
3
ENC2
 11
 PC1
11
LCD_PINS_D4
 12
 SDA
1
LCD_PINS_ENABLE
 13
 A2***
40
SDSS
 14
 SCL
0

 18
 RESET**
---
---
* Wire 1 and 2 are not connected/used but kept in for consistency with the original instructions.
** Can come either from the RESET pin on the expansion header or the ISP header.
*** Only required if a SDSL is used rather than the on board SD card reader

Update There was a mistake in the table above, thanks to Colin Bradburne for bringing the problem to my attention. It is fixed now - the lines in red have been amended.

If using the SDSL rather than the on board SD card reader then the following connections to the ISP header are used as well.

Ribbon cable wire number
Printrboard Pin Label
Marlin Pin number
Marlin Pin name
 17
 GND
---
 ---
 18
 RESET
---
 ---
 19
 MOSI
 22
MOSI_PIN
 20
 SCLK
 21
SCK_PIN
 21
 5V
---
 ---
 22
 MISO
 23
 MISO_PIN

The Printrboard I bought does not have the expansion header pins labelled, I have annotated the pins on the screen shot of the board below:
The 4 pins labelled "JTAG PINS" are set to the JTAG interface by default - I have done a separate blog post about how to change the fuse settings to gain access to these pins as I/O. This does mean that we can't fit the Panelolu connections onto just one expansion header, hence the 4 pins on the second expansion header towards the centre of the board

The ribbon cable with the connectors will look like this:

Pairing this picture with the annotated screen shot of the board should show how to plug in the cables. (note that wire 1 and 2 are not in this picture as they are not used and that a 4 pin connector is used for MISO,SCLK and RESET because I ran out of 3 pin connectors)

Firmware configuration

The following firmware changes to Marlin are required to get the Panelolu working with a Printrboard. Please note that line numbers are based on my version of Lincomatic's branch of Marlin - they may be slightly different with a different version or after additional changes are made.

Configuration.h

line 34-40:
#define MOTHERBOARD 81

#if (MOTHERBOARD == 81) //printrboard
 #define SDSUPPORT
 //comment out the following line to use onboard SD card reader

#define USESDSL
#end
if
 
line 234:
#define ULTIMAKERCONTROLLER  

Pins.h

within the Printrboard (81) section
line 953 -984  
  #ifdef ULTRA_LCD
    #ifdef NEWPANEL
      //we have no buzzer installed
      #define BEEPER -1
      //LCD Pins
      #define LCD_PINS_RS        41
      #define LCD_PINS_ENABLE    1
      #define LCD_PINS_D4        11
      #define LCD_PINS_D5        9
      #define LCD_PINS_D6        6
      #define LCD_PINS_D7        4

      //The encoder and click button
      #define BTN_EN1 2  //must be a hardware interrupt pin
      #define BTN_EN2 3 //must be hardware interrupt pin
      #define BTN_ENC 0  //the click
      //not connected to a pin currently
      #define SDCARDDETECT -1
     
      //from the same bit in the RAMPS Newpanel define
      //encoder rotation values
      #define encrot0 0
      #define encrot1 2
      #define encrot2 3
      #define encrot3 1
     
      #define BLEN_C 2
      #define BLEN_B 1
      #define BLEN_A 0

    #endif //Newpanel
  #endif //Ultipanel

Sd2PinMap.h

Line 224-236

// SPI port
#if MOTHERBOARD == 81 //printrboard
#ifdef USESDSL  //SDSL with Panelolu
uint8_t const SS_PIN = 40;    //F2
#else
uint8_t const SS_PIN = 26;    // B6
#endif
#else
uint8_t const SS_PIN = 20;    // B0
#endif
uint8_t const MOSI_PIN = 22;  // B2
uint8_t const MISO_PIN = 23;  // B3
uint8_t const SCK_PIN = 21;   // B1 

To explain what the firmware changes actually do:
  • Add the USESDSL define to configuration.h which allows easy toggling between the onboard SD card reader and the SDSL
  • Enable the ULTIMAKERCONTROLLER which the PanelMax and Panelolu are derivatives of.
  • Define the pins that are used for the Panelolu within the Printrboard section of the pins definition file
  • Add a check to the SdPinMap to see if SDSL on onboard card reader is selected with the USESDSL define.
Summary

To get a Panelolu working on Printrboard: 
  • Confirm you can connect to the Printrboard and upload firmware - if not follow Lincomatic's instructions for loading a bootloader.
  • Get Lincomatic's branch of Marlin and make the changes listed in the Firmware section above.
  • Get the components required for a Panelololu and wire up the Panelolu end as described in my previous post.
  • Wire up the end of the ribbon cable that is going to the Printrboard as described above. 

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