Sunday, July 20, 2014

Changing Arduino bootloader to Optiboot

All Arduino boards come with a pre-programmed boot loader. This boot loader allows you to program the Arduino from the IDE using a serial connection only. After programming the serial connection can be used as a console interface to 'talk' to the Arduino. Other ways exist to program an Arduino, but all of them require extra hardware.

First a big fat warning: Be sure you are familiar with compiling source code from the command line and programming your Arduino using ISP. Failure to update the boot loader might brick your Arduino for usage by the Arduino IDE !!!


Advantages of the Optiboot boot loader

  • Size is only 512 bytes. This leaves more room (flash) for own programs.
  • Works with watchdog enabled.
  • Serial connection speed can be increased (default 57k6). This shortens programming times!

What you'll need

  • An Arduino Pro Mini 3v3 @ 8MHz. This description is for an Arduino Pro Mini (3V3, 8Mhz), but the principle is the same for other ATmega328 based Arduino's)
  • An ISP programmer connected to the ATMega (I use Atmel's JTAGICE3) & software to flash (for JTAGICE3 I use Atmel Studio 6.1)
  • Arduino IDE (I used 1.5.6r2)
The description here assumes Windows.


Compiling Optiboot

  • Download Optiboot 5.0a sources: https://code.google.com/p/optiboot/downloads/detail?name=optiboot-v5.0a.zip
  • Extract to c:\Arduino_1.5.6-r2\hardware\arduino\avr\    (rename existing optiboot directory, when required)
  • Optional: Edit bootloaders\optiboot\Makefile to change the baud rate (line 562) (This is a makefile, so be sure to use tabs to indent instead of spaces!) I went from 57k6 to 76k8, because I got errors at 115k2:
atmega328_pro8: $(MAKE) $(CHIP) AVR_FREQ=8000000L LED_START_FLASHES=3 BAUD_RATE=76800
  • Start a cmd shell in c:\Arduino_1.5.6-r2\hardware\arduino\avr\bootloaders\optiboot
  • make clean
  • make atmega328_pro8


Flashing Optiboot to the Arduino

  • Optional: Use your ISP tool to create a backup of the existing bootloader and fuses.
  • Flash optiboot_atmega328_pro_8MHz.hex using your favourite ISP
  • Set fuses to: Low = 0xFF, High = 0xDE, Extended = 0xFE
  • Close any active Arduino windows


Add support for the new bootloader to Arduino IDE

  • Edit c:\Arduino_1.5.6-r2\hardware\arduino\avr\boards.txt
  • Add (based on Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328):
## Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 - Optiboot 76k8
## --------------------------------------------------
pro.menu.cpu.8MHzatmega328ob=ATmega328 (3.3V, 8 MHz, Optiboot 76k8)
pro.menu.cpu.8MHzatmega328ob.upload.maximum_size=32256
pro.menu.cpu.8MHzatmega328ob.upload.maximum_data_size=2048
pro.menu.cpu.8MHzatmega328ob.upload.speed=76800
pro.menu.cpu.8MHzatmega328ob.bootloader.low_fuses=0xFF
pro.menu.cpu.8MHzatmega328ob.bootloader.high_fuses=0xDE
pro.menu.cpu.8MHzatmega328ob.bootloader.extended_fuses=0xFE
pro.menu.cpu.8MHzatmega328ob.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
pro.menu.cpu.8MHzatmega328ob.build.mcu=atmega328p
pro.menu.cpu.8MHzatmega328ob.build.f_cpu=8000000L


Testing it!

  • Start Arduino IDE
  • Select Board -> Arduino Pro or Pro Mini
  • Select Processor -> ATmega328 (3.3V, 8 MHz, Optiboot 76k8)
  • File -> Upload

2 comments:

  1. I was of the impression that OptiBoot only took 512 bytes, leaving 32256 bytes (rather than 30720) for application code. Can the boards.txt entry be changed for the higher number?

    ReplyDelete
  2. You're right. Copy-past devil ;-)
    Update the post.

    ReplyDelete