Let's Make Robots! | RobotShop

Add support for ATmega168P in optiboot

These are instructions for the optiboot bootloader shipped with Arduino 1.0
  • Programming language:
AttachmentSize
optiboot-with-168p.zip47.75 KB

Optiboot works with ATmega168 but, to return the correct chip signature, for ATmega168P some changes must be done.
The easy solution is to copy attached file to the folder <path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders, unzip it there and use included optiboot_atmega168p.hex file.

If you want to replicate my work, here follows five steps.

Step.0: Backup original optiboot folder
Go to <path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders and make a copy of the optiboot folder

Step.1: in the file <path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders\optiboot\pin_defs.h
change the line:
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
with:
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
for the LED pin definition

Step.2: in the file <path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders\optiboot\optiboot.c
change the FIRST line of this block:
#if defined(__AVR_ATmega168__)
#define RAMSTART (0x100)
#define NRWWSTART (0x3800)
...

with:
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__)

Step.3: in the file <path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders\optiboot\Makefile
copy this block:

atmega168: TARGET = atmega168
atmega168: MCU_TARGET = atmega168
atmega168: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega168: AVR_FREQ = 16000000L
atmega168: $(PROGRAM)_atmega168.hex
atmega168: $(PROGRAM)_atmega168.lst

atmega168_isp: atmega168
atmega168_isp: TARGET = atmega168
# 2.7V brownout
atmega168_isp: HFUSE = DD
# Low power xtal (16MHz) 16KCK/14CK+65ms
atmega168_isp: LFUSE = FF
# 512 byte boot
atmega168_isp: EFUSE = 04
atmega168_isp: isp


and change every occurence of atmega168 with atmega168p to add the definitions for ATmega168P (Warning: do NOT change the spacing - spaces and tabs).
It must look like this:

atmega168p: TARGET = atmega168p
atmega168p: MCU_TARGET = atmega168p
atmega168p: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega168p: AVR_FREQ = 16000000L
atmega168p: $(PROGRAM)_atmega168p.hex
atmega168p: $(PROGRAM)_atmega168p.lst

atmega168p_isp: atmega168p
atmega168p_isp: TARGET = atmega168p
# 2.7V brownout
atmega168p_isp: HFUSE = DD
# Low power xtal (16MHz) 16KCK/14CK+65ms
atmega168p_isp: LFUSE = FF
# 512 byte boot
atmega168p_isp: EFUSE = 04
atmega168p_isp: isp


Step.4: Compilation of the new bootloader

  • launch command prompt (press Win+R, type cmd, hit Enter)
  • change the working directory by typing
    cd "<path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders\optiboot\"

    and hit Enter
  • launch compiler by typing
    omake atmega168p

    and hit Enter

Now, in the folder <path-where-you-installed-arduino-1.0>\hardware\arduino\bootloaders\optiboot you should have the compiled optiboot bootloader for ATmega168p: optiboot_atmega168p.hex