Updated: Jul 4, 2020
Hi, in this guide you'll learn how you can flash a boot loader on your board using the raspberry Pi or similar.
Hardware you'll need
A PI (Any PI will do)
6 x female-female jumper cables ( Unless your pi does not have header then you need 6x female-male jumper cables )
Software You'll need
Download and Install Putty https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Download and Install Arduino IDE (Can also be downloaded from Windows APP Store) https://www.arduino.cc/en/Main/Software
Download and Install FileZilla Client https://filezilla-project.org/download.php?type=client
Disclaimer, YOU WILL HAVE TO TAKE APART YOUR CONTROL BOX AND ACCESS AREA'S THAT COULD POTENTIALLY CARRY MAINS POWER MAKE SURE POWER IS DISCONNECTED AND YOU ARE VERY CAREFULL. UNDER NO CIRCUMSTANCES WILL I BE HELD RESPONSIBLE FOR ANY DAMAGES TO YOU AND OR YOUR PROPERTY, PROCEED AT YOUR OWN RISK.
I would recommend using a different SD card than the one where you have your running octopi, just so as to avoid any trouble in case something gets messed up.
If you have octopi installed on your PI that's great, if not follow the guide below to do so. https://www.fission3d.com/single-post/2017/09/23/INSTALLING-OCTOPI
Open Putty connect and Login to your PI, if you don't know how follow the link. https://www.fission3d.com/single-post/2017/09/25/Configuring-Putty
Now that your connected to your PI you'll update, install and compile AVR Dude which is the program that will communicate with the board.
Copy and paste the lines of code into Putty one by one pressing enter and waiting for completion after each command, if prompted accept installation size increase by pressing Y and Enter
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install avrdude
Great AVR Dude should now be installed enter following to check.
the above will give a report of AVR Dude, if installed properly you should see Version 6.Xxx on the first line.
next you'll configure AVR Dude to properly communicate with the board
cp /etc/avrdude.conf ~/avrdude_gpio.conf
Press CTRL + W (this is search)
Type Linuxspi and hit enter
You should see something like id = "linuxspi"; desc = "Use Linux SPI device in /dev/spidev*"; type = "linuxspi"; reset = 25; baudrate=4000000; ;
if you don't see the above then keep pressing Ctrl + W (this is for find next) until you find the above code.
You will have to change the Baud rate, however this is printer specific you can see from octoprint connection settings what baud rate your printer is working at or you can google your printer model baud rate. I am going to flash my Creality CR-10 which I know is 115200 so i'll enter that. Please note do not use the Numeric pad as it has a different function.
Go to the bottom of the page hitting Ctrl+V (page Down) repeatedly (or hold) its a long ways down
add the following at the very bottom # Linux GPIO configuration for avrdude. # Change the lines below to the GPIO pins connected to the AVR. programmer id = "pi_1"; desc = "Use the Linux sysfs interface to bitbang GPIO lines"; type = "linuxgpio"; reset = 17; sck = 24; mosi = 23; miso = 18; ;
Press Ctrl+O (save)
Press Enter (confirm)
Press Ctrl+X (close)
Next You'll have to connect your pi to the board you want to program.
The GPIO headers we will use are the following
See Pictures at the top of the page
VCC (+3.3V) = Pin 1or 17 GND = Pin 6 or 14 or 20 or 32 reset = pin 11 GPIO 17 sck = Pin 18 GPIO 24 mosi = PIN 16 GPIO 23 miso = Pin 12 GPIO 18 Make sure you don't mix the pin numbers with the GPIO number I am flashing the CR 10 Melzi board the pinout is at the top for mine if your using a different board google your boards pinout (Note in most cases you do not need to remove the board from the control box and you do not have to remove the wires from the board as long as you disconnect the mains power to be sure no problems occur, if screen is blank no problem its normal)
On some boards you may have to move the power jumper to accept power from USB on your board.
Next we'll initialize AVR Dude to see if it can communicate with the board
You will have to know what chip your board uses, again as this is board specific I can't tell you but google is your friend. I am flashing the CR-10 which I know uses the Atmega 1284p so i'll enter that, you'll have to enter your printers chip in the below code (replace atmega1284p with yours)
sudo avrdude -p atmega1284p -C ~/avrdude_gpio.conf -c pi_1 –v if it says Avr device initialed and ready to accept instructions then your good to go if not go back and check the steps again you possibly misplaced a wire. If you get a syntax error look at the number at the end if its 14573 or nearby then you did not copy and paste the above code properly in Step 14, alternatively you could try typing the code in manually as sometimes when theres gaps and spaces it doesn't copy properly.
Now with need the boot loader .hex file, there's a few ways of getting it but easiest is either online search or through Arduino.
Again as this is board specific you need to know the type of board you have and the processor to continue google both. In my case with the CR-10 the board is a sanguino based with atmega1284p 16MHz which is not supported by Arduino out of the box so you will have to install it manually.
Go to Tools -> Boards-> Boards manager
Scroll (or search using the search box) till you find Sanguino and then select version and click install
When done click close
Navigate to the following folder correcting/replacing user with your username if your board is different then replace sanguino with your board C:\Users\USER\AppData\Local\Arduino15\packages\Sanguino\hardware\avr\1.0.2\bootloaders\optiboot ( if you cant see AppData enable view of hidden folders from folder options)
Copy the optiboot_atmega1284p.hex file and Paste it to the desktop (Again this file might be different if your using a different board what you need to check is your processor + frequency and .hex)
Connect to your Pi if you don't know how check here https://www.fission3d.com/single-post/2017/10/17/FileZilla
Transfer the in my case optiboot_atmega1284p.hex file onto the Pi's default directory (the one that opens when you connect FileZilla)
When you get a message that file is transferred exit FileZilla
Open Putty and connect to the Pi
Now you will flash the boot loader sudo avrdude -p atmega1284p -C ~/avrdude_gpio.conf -c pi_1 -v -U flash:w:optiboot_atmega1284p.hex:i Note where it says optiboot_atmega1284p.hex your file might be named differently if so change to your name (Case Sensitive) Note where it says atmega1284p your processor might be different rename as required Press Enter
Wait till it says AvrDude done and Your Done boot loading :)
If this is all you wanted to do then great don't forget to move the power jumper back to internal power mode if you changed it to USB.
If you want to flash a firmware on your newly emptied board with the PI then read on
Download the firmware that is for your board and open the .ino file using Arduino
Go to File -> Preferences -> enable Show verbose output during compile and upload
Select your board, processor
Go to Tools ->Boards -> select
Go to Tools -> Processor -> select
Go to Tools -> Programmer -> change to Arduino as ISP
Go to Sketch -> Verify/Compile
If it compiles then great Go to Sketch -> Export Compiled Binary
If you get an error then read the error most times its self explanatory
if your error is regarding a missing file the error will look like #include <name.h> // some description of the file
using the name and description above go to Go to Sketch > Include Library > Library Manager and search here if you find it click install if not search for the file on google and download it in my case for the CR10 I was missing the U8glib.h which is for the LCD, so I went to Sketch -> Include Library -> Manage Libraries and searched using the search box for U8glib selected the version and install. Once installed go to Go to Sketch -> Include Library -> find and select your newly added library
Now go to Sketch > Verify/Compile
Hopefully your done :)
Next go to Sketch > Export Compiled Binary
When Arduino says Done Compiling at the bottom black part you will have to find the output folder, if you read through there will be Compiling core... Using precompiled core Linking everything together... Directory line 1 Directory line 2 Directory line 3 You need to scroll horizontally on Directory line 3 and the last file should be a .hex navigate to this directory copy and paste this .hex file to your desktop in my case it was named Marlin.ino.hex
Open Filezilla and transfer the .hex file to the root of the pi
Disconnect the cables from the PI's GPIO and the boards SPI and connect the pi to your board using a USB Cable
If your board has a USB power jumper move it to USB mode or switch on your printer
Open Putty and Connect to your PI
Now you'll flash your new firmware sudo avrdude -p atmega1284p -c arduino -P /dev/ttyUSB0 -b 115200 -U flash:w:Marlin.ino.hex:i If you get an error you can try changing the USB number from 0 to 1 or 2 or 3 Note where it says Marlin.ino.hex your file might be named differently if so change to your name Note where it says atmega1284p your processor might be different rename as required don't forget this is case sensitive make sure the baud rate 115200 is correct for you aswell
Once its done hopfully you are greeted with your new Firmware :)
don't forget to change the power jumper back on your board before assembly
If you like this guide and would like to support so I can make more please consider donating ;)
If you think any part of this guide is wrong please send us a shout at email@example.com