Flash Bootloader and Install Firmware With Raspberry PI

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

  1. A PI (Any PI will do)

  2. 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

  1. Download and Install Putty https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

  2. Download and Install Arduino IDE (Can also be downloaded from Windows APP Store) https://www.arduino.cc/en/Main/Software

  3. Download and Install FileZilla Client https://filezilla-project.org/download.php?type=client

Lets Start


  2. 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.

  3. 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

  4. 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

  5. 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.

  6. 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

  7. sudo apt-get update

  8. sudo apt-get upgrade

  9. sudo apt-get install avrdude

  10. Great AVR Dude should now be installed enter following to check.

  11. avrdude -v

  12. the above will give a report of AVR Dude, if installed properly you should see Version 6.Xxx on the first line.

  13. next you'll configure AVR Dude to properly communicate with the board

  14. cp /etc/avrdude.conf ~/avrdude_gpio.conf

  15. nano ~/avrdude_gpio.conf

  16. Press CTRL + W (this is search)

  17. Type Linuxspi and hit enter

  18. You should see something like id = "linuxspi"; desc = "Use Linux SPI device in /dev/spidev*"; type = "linuxspi"; reset = 25; baudrate=4000000; ;

  19. if you don't see the above then keep pressing Ctrl + W (this is for find next) until you find the above code.

  20. 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.

  21. Go to the bottom of the page hitting Ctrl+V (page Down) repeatedly (or hold) its a long ways down

  22. 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; ;

  23. Press Ctrl+O (save)

  24. Press Enter (confirm)

  25. Press Ctrl+X (close)

  26. Next You'll have to connect your pi to the board you want to program.

  27. The GPIO headers we will use are the following

  28. See Pictures at the top of the page

  29. 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)

  30. On some boards you may have to move the power jumper to accept power from USB on your board.

  31. Next we'll initialize AVR Dude to see if it can communicate with the board

  32. 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)

  33. 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.

  34. Exit Putty

  35. 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.

  36. Open Arduino

  37. Click ok

  38. 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.

  39. Go to Tools -> Boards-> Boards manager

  40. Scroll (or search using the search box) till you find Sanguino and then select version and click install

  41. When done click close

  42. Close Arduino

  43. 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)

  44. 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)

  45. Open FileZilla

  46. Connect to your Pi if you don't know how check here https://www.fission3d.com/single-post/2017/10/17/FileZilla

  47. Transfer the in my case optiboot_atmega1284p.hex file onto the Pi's default directory (the one that opens when you connect FileZilla)

  48. When you get a message that file is transferred exit FileZilla

  49. Open Putty and connect to the Pi

  50. 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

  51. Wait till it says AvrDude done and Your Done boot loading :)

  52. 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.

  53. If you want to flash a firmware on your newly emptied board with the PI then read on

  54. Download the firmware that is for your board and open the .ino file using Arduino

  55. Go to File -> Preferences -> enable Show verbose output during compile and upload

  56. Select your board, processor

  57. Go to Tools ->Boards -> select

  58. Go to Tools -> Processor -> select

  59. Go to Tools -> Programmer -> change to Arduino as ISP

  60. Go to Sketch -> Verify/Compile

  61. If it compiles then great Go to Sketch -> Export Compiled Binary

  62. If you get an error then read the error most times its self explanatory

  63. if your error is regarding a missing file the error will look like #include <name.h> // some description of the file

  64. 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

  65. Now go to Sketch > Verify/Compile

  66. Hopefully your done :)

  67. Next go to Sketch > Export Compiled Binary

  68. 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

  69. Open Filezilla and transfer the .hex file to the root of the pi

  70. Close FileZilla

  71. Disconnect the cables from the PI's GPIO and the boards SPI and connect the pi to your board using a USB Cable

  72. If your board has a USB power jumper move it to USB mode or switch on your printer

  73. Open Putty and Connect to your PI

  74. 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

  75. Once its done hopfully you are greeted with your new Firmware :)

  76. don't forget to change the power jumper back on your board before assembly

  77. Enjoy

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 guides@fission3d.com

67,224 views17 comments

Recent Posts

See All