Loading Firmware
About Firmware
Firmware is software that is programmed into the Read Only Memory of your electronics' microcontroller. Its job is to transform the incoming GCode instructions into physical actions, for example heating your extruder to a certain temperature or moving the nozzle to a certain point in space.
The firmware contains lots of calibration settings for fine tuning your RepRap. Each time you make a change to these settings you will need to upload the firmware onto your electronics.
About Bootloaders
Microcontrollers are usually programmed using a special ICSP programmer, a piece of hardware not included in the standard TVRRUG kits. A bootloader is a small program that is loaded onto the microcontroller using an ICSP programmer. It then allows you to upload and update firmware using the USB cable provided in the kit, without further need for the special programmer.
Loading the Bootloader
Loading the bootloader is only required once, future firmware updates can be made using the USB cable.
My Bootloader Came Preloaded
Your electronics may come preloaded with the bootloader. In which case, don't worry about this step! Skip straight to "Loading the Firmware". If you are unsure whether your electronics has a bootloader preloaded, ask on the Google Group.
I am Missing the Bootloader
No bootloader preloaded? The next step depends on whether you have or want to get an ICSP programmer. Not having a programmer is not a problem, and indeed most people don't.
I Don't Have/Want a Programmer
That's OK. We do not expect everyone to have their own programmer, and there will be opportunities to have your bootloader loaded at the various meetings. If you do not have a programmer, then you should arrange to meet at one of our monthly meetings, or possibly at a Reading Hackspace Geek Night - but you should discuss options on the Google group.
I Want to Load My Own Bootloader
Further information may be available in the Google Group, for example in this thread.
In Jan2013 Peter posted this youtube link video that he says
"It helped me to program my atmega 644 using windows xp but I believe it will be the same with Win7. Ignore the middle bit about writing code ,he then goes on to program a different atmega but you can see how to select the 644. Well anyway I found it very useful. Best regards...........Peter "
Thread here
Loading the Firmware
Files
You need to download the Marlin firmware. Marlin source is available at BusError's firmware repository.
One good place to discuss these files is on the Marlin & Bootloader thread.
If you have a flash device like the USBTiny then you can load the bootloader with:
# bootloader is loaded at 0x7c00 is as 579 words long, we need
# the bootzs at 1+0 for that, and program BOOTRST too so thats 1+0+0
avrdude -c usbtiny -B 4 -p atmega644 -U hfuse:w:0xd4:m -Ulfuse:w:0xe7:m -U flash:w:bootloader-644-20MHz.hex
The "-c usbtiny -B 4" needs to be replaced by whatever AVR programmer you use. The "-B 4" is to slow down the clock, and is mandatory...
The fuze values can be caculated useing this caculation page
Setup
In order to load the firmware, you will need to have power to your OMC board and connect your electronics to your computer using the USB FTDI cable. For instructions on wiring up your electronics, look for the 'Electronics Wiring' page corresponding to the version of your electronics on the 'TVPrusa Design' page.
Using the Arduino IDE (Integrated Development Environment, or software!)
Install Arduino 0022
If you do not already have Arduino 0022 installed (you might be able to use v0023, but I had problems with it under Ubuntu, others have reported issues under Windows; use 0022):
- Download Arduino 0022 from the Arduino website. Do NOT download v1 or later, as this will not work with Marlin firmware.
- Extract the files.
- Check Arduino works by running the
arduino-0022/arduino
file.
Set up Arduino for OMC
Arduino doesn't include the details for the OMC board by default, so we must add them:
- Download the OMC board definition and extract it to either:
<sketchbook>/hardware
- the location of your sketchbook folder is given in the File > Preferences menu within the Arduino applicationarduino-0022/hardware
- Restart Arduino. Check for the entry 'OMC with Atmega644 at 20MHz' under the Tools > Board menu
Editing, compiling and uploading Marlin to the OMC
- Open the Marlin.pde file from the downloaded Marlin source files in the Arduino software.
- Select "OMC with Atmega644 at 20MHz" from the Tools > Board menu.
- Choose the right port from the Tools > Serial Port menu (in Ubuntu it's usually ttyUSB0, just try USB1 etc. if it's not working).
- Go to the Configuration.h tab and make any changes you need to, for example if you are calibrating the extruder.
- Verify your changes by hitting the 'Verify' icon (looks like a play sign), or choosing Sketch > Verify/Compile from the menu. Any problems will appear in the console at the bottom of the window - there shouldn't be any
- Upload firmware to the board:
- Hold down the 'Reset' button on the board.
- Press the 'Upload' icon, (or choose it from the File menu). Arduino will compile the firmware and then attempt to upload it to the board.
- Release the 'Reset' button immediately after the "Binary sketch size:...." message appears in the console, usually a few seconds. If the motors are connected to your board, they will make a 'thud' sound as the board resets, release the button after you hear this sound.
PLEASE NOTE: If you're having issues, restarting the Arduino IDE and re-opening the file to try again is sometimes necessary. Additionally, while calibrating and re-compiling, make sure Printrun/Pronterface or whichever program you're using to control the printer isn't connected and communicating with the electronics while you try to re-upload the firmware, as this seems to inhibit the upload (you'll get an endless number of avrdude timeouts and other errors). Best of all is to just close that program while updating the firmware.
Loading pre-compiled firmware on Ubuntu 12.04 via the command line
You will need to install avrdude version 5.11 or later. if you are using Ubuntu, then the version in 12.04 is known to work. Other versions may be downloaded from the AVRDude website.
A precompiled version of the firmware is attached at the bottom of the page. Download this if you will not be re-compiling the firmware yourself.
Check the output of dmesg to ensure it has been detected correctly, and to determine the allocation of USB port, and use this in the command below. Press the reset button and about half a second later run the following command (updated with correct USB port and path to Marlin.hex). You may need the jumper near R13 to make the reset work.
$ avrdude -c wiring -P /dev/ttyUSB0 -p m644 -b 115200 -v -U flash:w:Marlin.hex
Once successfully completed, you are ready to print!
Re-compiling the Firmware
In order to calibrate your extruder, you will need to recompile the firmware with your revised settings. To re-upload, simply follow the same procedure as when you first uploaded the firmware (above).
Download Arduino
Download the Arduino 0022 source tree from http://arduino.cc/en/Main/Software:
# wget http://files.arduino.cc/downloads/arduino-0022-src.tar.gz # tar xvvzf arduino-0022-src.tar.gz
Download Marlin
# git clone https://github.com/buserror-uk/Marlin # cd Marlin # git checkout master
Compiling Marlin
Before compiling Marlin, you probably want to edit the Marlin/Marlin/Configuration.h file - as this is likely to be the reason you are re-compiling. See section above for Calibrating Extruder.
# cd Marlin/Marlin # make
If this has worked, you will have a new Marlin.hex file, sitting in Marlin/Marlin/applet directory. If it failed on Ubuntu 12.04, this may be because of a bug in binutils-avr, see section below on Re-compiling binutils-avr.
Re-compiling binutils-avr
You should not have to carry out this step - indeed don't, unless you have no choice. But, if you are running Ubuntu 12.04, then there is a chance that the above step did not work. To fix this, you will need to patch binutils-avr.
# apt-get build-dep binutils-avr # apt-get source binutils-avr
This will have created a binutils directory...
Download Patch file and save as "elf32-avr.c.diff".
# cd bintils*
Unfortunately the source code is in a .tar.bz2, which makes it difficult to patch. I am sure that the correct solution is to add this new patch to the deb package patches, but I simply copied the .tar.bz2 elsewhere, extracting it:
# tar -xvvjf binutils-avr---.tar.bz2
and patched the file:
# patch < elf32-avr.c.diff
then re-creating the tar.bz2 with:
# tar -cvvjpsf binutils-avr---.tar.bz2 binutils-avr---/
then replace the original .tar.bz2 file with this one.
Ensure this completes successfully, then:
# cd binutils* # dpkg-buildpackage -rfakeroot -uc -b # dpkg -i binutils-avr*.deb
Attachment | Size |
---|---|
Marlin.hex | 125.52 KB |
bootloader-644-20MHz.hex | 3.15 KB |