Sunday, 12 February 2023

Replacing the bootloader and installing Klipper firmware on a Cocoon Create 3D Printer V1

This process outlines the steps to replace the bootloader and firmware on an ALDI Cocoon Create 3D Printer V1. It also applies to the Wanhao Duplicator i3 V2, which the ALDI printer is based on:

Both ship with Repetier 0.91 firmware and use the Melzi controller board.

The Melzi utilises an 8-bit AVR MCU with 128K of flash (ATmega1284P).

Dumping standard firmware

Before overwriting the bootloader or flash, I wanted to dump the existing flash so I could back out of changes if I wanted to go back to the original firmware.

I first tried using avrdude 6.3 on OctoPi via standard USB interface:

$ avrdude -p m1284p -c arduino -P /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AI03KF0Y-if00-port0 -v

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xac

The printer likely has a bootloader that doesn't support updates via USB.

I then moved to using a Bus Pirate v3.6 running community firmware connected to the ISP pins on the Melzi board, and used avrdude 6.4 on macOS 12.1:

% avrdude -p m1284p -c buspirate -P /dev/tty.usbserial-AJ02XIK6 -v

avrdude: Device signature = 0x1e9705 (probably m1284p)

avrdude: safemode: lfuse reads as D6

avrdude: safemode: hfuse reads as DC

avrdude: safemode: efuse reads as FD

I had no problem dumping EEPROM:

% avrdude -p m1284p -c buspirate -P /dev/tty.usbserial-AJ02XIK6 -U eeprom:r:eeprom.bin:r

Dumping flash read would fail at 99%:

BusPirate: Paged Read command returned zero.

After some reading of the datasheet, lock bits probably set to prevent reading bootloader, read the lock bits, the value was 0xCF.

I was able to dump flash (minus bootloader area) without errors with paged read mode disabled, although it was much slower:

% avrdude -p m1284p -c buspirate -P /dev/tty.usbserial-AJ02XIK6 -U flash:r:flash.bin:r -x nopagedread

Flashing Optiboot bootloader

You could leave the original bootloader in place but it would mean you would need to do all firmware updates via the ISP.

Downloaded the suggested Optiboot bootloader mentioned in the Klipper documentation.

Optiboot much smaller than original bootloader, so had to adjust high byte fuse (hfuse) to suit:

% avrdude -p m1284p -c buspirate -P /dev/tty.usbserial-AJ02XIK6 -U hfuse:w:0xDE:m

See table 25-4 on page 293 of the datasheet for more details on the high byte fuse.

This shouldn't affect going back to the standard firmware as the bootloader code is at the end of the flash, so it just starts at a higher memory address than usual:

% avrdude -p m1284p -c buspirate -P /dev/tty.usbserial-AJ02XIK6 -U flash:w:optiboot_atmega1284p.hex:i

Set lock bits back to original value to stop bootloader from accidental damage:

% avrdude -p m1284p -c buspirate -P /dev/tty.usbserial-AJ02XIK6 -U lock:w:0xCF:m

Flashing can now be done via standard USB interface on printer.

Testing new bootloader with standard firmware

Make sure you use -D flag when programming application area via the ISP or you will need to reflash the bootloader again with the steps above

% avrdude -p m1284p -c buspirate -D -P /dev/tty.usbserial-AJ02XIK6 -U flash:w:flash.bin:r

Booted successfully and although I did not try a test print I was able to control steppers.

Flashing Klipper

Used standard USB interface on printer connected to OctoPi and followed the installation instructions.

No comments:

Post a Comment