Upload bootloader

From Flav's Wiki
Revision as of 21:05, 12 July 2015 by Flav (Talk | contribs) (Upload Issues)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page describes how to upload a bootloader on an Arduino Pro Mini with an Arduino Uno.

References:

Hardware Connexion

Arduino Uno (Programmer) Arduino Pro Mini
3.3V or 5V (depending on on Mini version) Vcc
GND GND
10 Reset
11 (MOSI) 11 (MOSI)
12 (MISO) 12 (MISO)
13 (SCK) 13 (SCK)

Programming with IDE

Disconnect the Arduino Pro Mini

Program the programmer

Steps:

  1. Select the ArduinoISP Sketch: Select File>Examples>Arduino ISP
  2. Select your programmer board (Arduino Uno): Tools>Board>Arduino Uno
  3. Select the serial port: Tools>Serial Port>COMXXX
  4. Upload

Connect the Arduino Pro Mini

Flash the bootloader

Steps:

  1. Select the target board: Tools>Board>Arduino Pro Mini ...
  2. Select type of programmer: Tools>Programmer>Arduino as ISP
  3. Burn: Tools>Burn Bootloader

Flash optiboot

Watchdog is not working on Arduino Pro Mini with default atmega bootloader. Here are the instructions to flash optiboot.

Read:

On Windows Download arduino-1.5.6-r2-windows.zip as it has the "make" in it.

Prepare environment

  • Create C:\ard
  • Copy tools from arduino-1.5.6-r2-windows.zip: copy from arduino-1.5.6-r2\hardware the arduino and tools in C:\ard
  • Modify: C:\ard\arduino\avr\bootloaders\optiboot\omake.bat

before:

..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino %*

after:

..\..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino %*
  • Modify C:\ard\arduino\avr\bootloaders\optiboot\Makefile

Diff:

*
*** Makefile.origin     Fri Feb 21 16:11:50 2014
--- Makefile    Sun Jul 12 16:13:51 2015
***************
*** 50,56 ****
  # For Arduino, we assume that we're connected to the optiboot directory
  # included with the arduino distribution, which means that the full set
  # of avr-tools are "right up there" in standard places.
! TOOLROOT = ../../../tools
  GCCROOT = $(TOOLROOT)/avr/bin/
  AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf

--- 50,56 ----
  # For Arduino, we assume that we're connected to the optiboot directory
  # included with the arduino distribution, which means that the full set
  # of avr-tools are "right up there" in standard places.
! TOOLROOT = ../../../../tools
  GCCROOT = $(TOOLROOT)/avr/bin/
  AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf

***************
*** 70,76 ****
  TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
  endif
  ifeq ($(OS), windows)
! TOOLROOT = ../../../../build/windows/work/hardware/tools
  endif

  GCCROOT = $(TOOLROOT)/avr/bin/
--- 70,76 ----
  TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
  endif
  ifeq ($(OS), windows)
! TOOLROOT = ../../../../../tools
  endif

  GCCROOT = $(TOOLROOT)/avr/bin/
***************
*** 376,382 ****

  atmega328_pro8: TARGET = atmega328_pro_8MHz
  atmega328_pro8: MCU_TARGET = atmega328p
! atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  atmega328_pro8: AVR_FREQ = 8000000L
  atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
  atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
--- 376,382 ----

  atmega328_pro8: TARGET = atmega328_pro_8MHz
  atmega328_pro8: MCU_TARGET = atmega328p
! atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=57600'
  atmega328_pro8: AVR_FREQ = 8000000L
  atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
  atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex

Make

Compile in command line: Define env:

set PATH=C:\ard\tools\avr\utils\bin;C:\ard\tools\avr\bin
cd C:\ard\arduino\avr\bootloaders\optiboot

Delete the existing : optiboot_atmega328.* and optiboot_atmega328_pro_8MHz.*

Compile; Use commands:

omake atmega328
omake atmega328_pro8

The output should look like:

c:\ard\arduino\avr\bootloaders\optiboot>omake atmega328
c:\ard\arduino\avr\bootloaders\optiboot>..\..\..\..\tools\avr\utils\bin\make OS=
windows ENV=arduino atmega328
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-
split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=16000000L  '-DLED_START_
FLASHES=3' '-DBAUD_RATE=115200'   -c -o optiboot.o optiboot.c
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-
split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=16000000L  '-DLED_START_
FLASHES=3' '-DBAUD_RATE=115200' -Wl,--section-start=.text=0x7e00 -Wl,--section-s
tart=.version=0x7ffe -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -o op
tiboot_atmega328.elf optiboot.o
../../../../tools/avr/bin/avr-size optiboot_atmega328.elf
   text    data     bss     dec     hex filename
    500       0       0     500     1f4 optiboot_atmega328.elf
../../../../tools/avr/bin/avr-objcopy -j .text -j .data -j .version --set-sectio
n-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.he
x
..\..\..\..\tools\avr\bin\avr-objdump -h -S optiboot_atmega328.elf > optiboot_at
mega328.lst
rm optiboot.o optiboot_atmega328.elf

c:\ard\arduino\avr\bootloaders\optiboot>omake atmega328_pro8

c:\ard\arduino\avr\bootloaders\optiboot>..\..\..\..\tools\avr\utils\bin\make OS=
windows ENV=arduino atmega328_pro8
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-
split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=8000000L  '-DLED_START_F
LASHES=3' '-DBAUD_RATE=57600'   -c -o optiboot.o optiboot.c
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-
split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=8000000L  '-DLED_START_F
LASHES=3' '-DBAUD_RATE=57600' -Wl,--section-start=.text=0x7e00 -Wl,--section-sta
rt=.version=0x7ffe -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -o opti
boot_atmega328_pro_8MHz.elf optiboot.o
../../../../tools/avr/bin/avr-size optiboot_atmega328_pro_8MHz.elf
   text    data     bss     dec     hex filename
    500       0       0     500     1f4 optiboot_atmega328_pro_8MHz.elf
../../../../tools/avr/bin/avr-objcopy -j .text -j .data -j .version --set-sectio
n-flags .version=alloc,load -O ihex optiboot_atmega328_pro_8MHz.elf optiboot_atm
ega328_pro_8MHz.hex
..\..\..\..\tools\avr\bin\avr-objdump -h -S optiboot_atmega328_pro_8MHz.elf > op
tiboot_atmega328_pro_8MHz.lst
rm optiboot.o optiboot_atmega328_pro_8MHz.elf

Install the new bootloaders in the Arduino IDE

Here I have used Arduino IDE 1.6.0

Copy from C:\ard\arduino\avr\bootloaders\optiboot to C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\optiboot the 4 files: optiboot_atmega328.hex optiboot_atmega328.lst optiboot_atmega328_pro_8MHz.hex optiboot_atmega328_pro_8MHz.lst

Edit C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt and add:


## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 - Optiboot 115.2k
## --------------------------------------------------
pro.menu.cpu.16MHzatmega328ob=ATmega328 (5V, 16 MHz, Optiboot 115.2k)
pro.menu.cpu.16MHzatmega328ob.upload.maximum_size=32256
pro.menu.cpu.16MHzatmega328ob.upload.maximum_data_size=2048
pro.menu.cpu.16MHzatmega328ob.upload.speed=115200
pro.menu.cpu.16MHzatmega328ob.bootloader.low_fuses=0xFF
pro.menu.cpu.16MHzatmega328ob.bootloader.high_fuses=0xDE
pro.menu.cpu.16MHzatmega328ob.bootloader.extended_fuses=0x05
pro.menu.cpu.16MHzatmega328ob.bootloader.file=optiboot/optiboot_atmega328.hex
pro.menu.cpu.16MHzatmega328ob.build.mcu=atmega328p
pro.menu.cpu.16MHzatmega328ob.build.f_cpu=16000000L

## Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 - Optiboot 57.6k
## --------------------------------------------------
pro.menu.cpu.8MHzatmega328ob=ATmega328 (3.3V, 8 MHz, Optiboot 57.6k)
pro.menu.cpu.8MHzatmega328ob.upload.maximum_size=32256
pro.menu.cpu.8MHzatmega328ob.upload.maximum_data_size=2048
pro.menu.cpu.8MHzatmega328ob.upload.speed=57600
pro.menu.cpu.8MHzatmega328ob.bootloader.low_fuses=0xFF
pro.menu.cpu.8MHzatmega328ob.bootloader.high_fuses=0xDE
pro.menu.cpu.8MHzatmega328ob.bootloader.extended_fuses=0x05
pro.menu.cpu.8MHzatmega328ob.bootloader.file=optiboot/optiboot_atmega328_pro_8MHz.hex
pro.menu.cpu.8MHzatmega328ob.build.mcu=atmega328p
pro.menu.cpu.8MHzatmega328ob.build.f_cpu=8000000L

Just before:

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
## -------------------------------------------------

Then you can upload the bootloader as described in before.

Upload Issues

If you experience uploading issues like:

avrdude: verification error, first mismatch at byte 0x7800

first check the fuses and set the correct values.

The values for the specific board are in C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt

Allways take care to keep SPIEN fuse set. If not the SPI programming will not work.

More can be read here:

Read Current Fuse Settings

Use arvdude option -v

Example:

C:\Users\mike>"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -cstk500v1 -PCOM10 -b19200 -v

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM10
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page      Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.09s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK (H:05, E:DA, L:FF)

avrdude done.  Thank you.

Write Fuse

Use avrdude option: -U lfuse:w:0xvalue:m -U hfuse:w:0xvalue:m -U efuse:w:0xvalue:m

Example:

C:\Users\mike>"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -cstk500v1 -PCOM10 -b19200 -U lfuse:w:0xff:m -U hfuse:w:0xda:m -U efuse:w:0x05:m

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM10
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page      Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.11s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xda"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.05s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xda:
avrdude: load data hfuse data from input file 0xda:
avrdude: input file 0xda contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0x05"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x05:
avrdude: load data efuse data from input file 0x05:
avrdude: input file 0x05 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK (H:05, E:DA, L:FF)

avrdude done.  Thank you.