How to modify the ATMEGA_BOARD_PROGRAMMER (nick gammon) for new boot loaders

Hi,

I am trying to configure and Anarduino miniWirteless with a dual-optiboot from Moteino.

FYI Anarduino and Moteino are running on a AtmelMega38P-AU, 16 MHz powered by 3v3.

The miniWireless is running a Duemilanove bootloader.
Anarduino Miniwireless and Moteino are equivalent (beside the SPI Flash Ram, but this is another topic)

So I am trying to reprogram the miniWireless with the Dua-optiboot (see DualOptiboot/DualOptiboot_V5.0_atmega328_BlinkD9.hex at master · LowPowerLab/DualOptiboot · GitHub)

  1. I did follow the MUSHClient instruction to get a ‘.h’ file (note that I had to add a new Send/Start value of 7C00).

  2. This file named “bootloader_atmega328P_dual_boot.h” is added as part of the Atmega_Board_Programmer directory
    From the Board.txt I know that the Fuse is (see below extract of the board.txt):
    Moteino.bootloader.low_fuses=0xDE
    Moteino.bootloader.high_fuses=0xDC
    Moteino.bootloader.extended_fuses=0xFD

  3. Now what about the signature? I suppose it is 0x1E 0x95 0x0F
    QUESTIONS:

  4. How can I associate this new file in the Atmega_Board_Programmer.ino sketch?

Thanks in advance
Robert

Attachement:
// File = DualOptiboot_V5.0_atmega328_BlinkD9.hex
// Loader start: 7C00, length: 1024
// MD5 sum = D2 AF FE B5 5E D1 B4 FE A6 47 FE 45 2F 86 50 B1

const byte DualOptiboot_V5_0_atmega328_BlinkD9_hex [] PROGMEM = {
0x11, 0x24, 0x04, 0xB7, 0x14, 0xBE, 0x01, 0xFD, 0x04, 0xC0, 0x03, 0xFD, 0x24, 0xD1, 0x80, 0x2F,
0xDF, 0xD1, 0x85, 0xE0, 0x80, 0x93, 0x81, 0x00, 0x82, 0xE0, 0x80, 0x93, 0xC0, 0x00, 0x88, 0xE1,
0x80, 0x93, 0xC1, 0x00, 0x86, 0xE0, 0x80, 0x93, 0xC2, 0x00, 0x80, 0xE1, 0x80, 0x93, 0xC4, 0x00,
0x8E, 0xE0, 0xFB, 0xD0, 0x21, 0x9A, 0x86, 0xE0, 0x20, 0xE3, 0x3C, 0xE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 0xDF, 0xEE, 0x27, 0xFF, 0x27, 0x09, 0x94, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x05,
}; // end of DualOptiboot_V5_0_atmega328_BlinkD9_hex

Moteino board.txt
##############################################################
Moteino.name=Moteino
Moteino.upload.tool=avrdude
Moteino.upload.protocol=arduino
Moteino.upload.maximum_size=31744
Moteino.upload.speed=115200
Moteino.bootloader.low_fuses=0xDE
Moteino.bootloader.high_fuses=0xDC
Moteino.bootloader.extended_fuses=0xFD
Moteino.bootloader.path=Moteino
Moteino.bootloader.file=DualOptiboot_V5.0_atmega328_BlinkD9.hex
Moteino.bootloader.unlock_bits=0x3F
Moteino.bootloader.lock_bits=0xCF
Moteino.build.mcu=atmega328p
Moteino.build.f_cpu=16000000L
Moteino.build.core=arduino:arduino
Moteino.build.variant=arduino:standard
Moteino.build.board=AVR_MOTEINO

Is your problem that you can't select this new configuration in the Arduino IDE?

Well , I did use the arduino ide to try to burn the Uno optiboot loader in a new atmega 328p, without, success, always error messages.
Using the programmer sketch of Nick Gammon, it was immediately working, so I am pretty confident with this approach, unfortunately, it is not the optibootloader I want to have, dut the dual optiboot loader, which is not part of the standrad list provided with the sketch. So my question is how to add a new bootloader for an atmega328 (currently uno and lilypad are covered).

NB: Is it a chance to modify a current optiboot with a dual optiboot in a with the avr ide, I mean is it worth to debug the error messages?

Robert

Note that the error with the Arduino Burn boot loader is probably a well known one:
(I did try IDE v 1.65 and 1.05 with the same results)

<<<
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude: stk500_disable(): unknown response=0x12
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Robert

Did you add the 10 nF cap between reset and ground?

yes even a 10uF didn't help

I finally got it to work.
First by hacking the sketch of Nick Gammon replacing the UNO specifications by the Dual Optiboot one. A little bit dirty but it did solve my problem. May be Nick will add these new boot loaders in a new release of its code :-)

Now the elegant one, using the Arduino ISP boot loader (I am running Arduino 1.65 IDE)

  1. Ensure that Moteino is correctly defined for the IDE:
    On my system:
    Arduino
    Sketch
    Hardware
    Moteino
    avr
    bootloaders
    DualOptiboot_V5.0_atmega328_BlinkD9.hex
    DualOptiboot_V5.0_atmega1284p_BlinkD9.hex
    variants
    MoteinoMEGA
    pins_arduino.h
    boards.txt
    platform.txt
    programmers.txt
    1.1 The programmers.txt file is empty
    1.2 The platform.txt files is the standard one (a copy of the /Applications/Arduino-1.6.5.app/Contents/Java/hardware/arduino/avr/ platform.txt)
    1.3 The boards.txt should be as the dumped at the end of this topic:
    IMPORTANT:
    My original file from external_cores/Moteino/boards.txt at master · codebendercc/external_cores · GitHub as to be adapted as follow:

missing definition:
bootloader.tool=avrdude
and the (this is not a big deal but necessary because that Arduino burn procedure insist to have for these values)
bootloader.extended_fuses is to be modified from 0xFD to 0x05
bootloader.lock_bits is to be modified from 0xCF to 0x0F

  1. To ensure these modifications are taken into account by the IDE, it should be stopped and started again.
    You should see Moteino and MoteinoMEGA in the Tools>Boards menu.

  2. To program or reprogram an ATMEGA328P connection should be done as described by any tutorial.
    I did use two Arduino UNO; one as ISP, one as target,
    +5V +5V
    GND GND
    D10 RESET
    D11 (MOSI) D11 (MOSI)
    D12 (MISO) D12 (MISO)
    D13 (SCLK) D13 (SCLK)
    IMPORTANT Don’t forget a 10uF/16V capacitor that will have to be connected between the RESET and the GND pins of the ISP Arduino, just before starting to burn the bootloader.

  3. Connect the Arduino UNO ISP to the USB comm port

  4. Select the ArduinoISP sketch from the Arduino Files>Example>ArduinoISP

  5. Select the correct com port from the Tools>Port menu

  6. Because this sketch is to be loaded into an Arduino UNO ISP, select from the Tools>Boards Arduino UNO

  7. Load the sketch into the Arduino UNO ISP

  8. Select from the menu the Programmer type, here Tools>Programmer>Arduino as ISP

  9. IMPORTANT: Install NOW the 10uF capacitor between the RESET and GND Arduino ISP Power header

  10. From the Tools>Boards select now Moteino (same com port), because this is the bootloader you want to enforce to the target Arduino

  11. Wait few seconds and it should be OK.

NB:

  • You may reverse the process by selecting Arduino UNO as board and reload the original bootloader
  • You may verify the boot loader with Atmega_Board_Detector sketch of Nick Gammon (see Gammon Forum : Electronics : Microprocessors : Atmega bootloader programmer)
  • Be careful if you want to reprogram a Moteino or an Anarduino miniWireless, theses boards are powered by 3v3 and voltage level converters should be used for the outgoing (ISP to target ) signals.

Hoping this will be useful for others.
Robert

================
boards.txt format

##############################################################
Moteino.name=Moteino
Moteino.upload.tool=avrdude
Moteino.upload.protocol=arduino
Moteino.upload.maximum_size=31744
Moteino.upload.speed=115200

THIS LINE IS TO BE ADDED

Moteino.bootloader.tool=avrdude

Moteino.bootloader.low_fuses=0xDE
Moteino.bootloader.high_fuses=0xDC

THIS LINE IS TO BE MODIFIED

#Moteino.bootloader.extended_fuses=0xFD

AS FOLLOW

Moteino.bootloader.extended_fuses=0x05

Moteino.bootloader.path=Moteino
Moteino.bootloader.file=DualOptiboot_V5.0_atmega328_BlinkD9.hex
Moteino.bootloader.unlock_bits=0x3F

THIS LINE IS TO BE MODIFIED

#Moteino.bootloader.lock_bits=0xCF

AS FOLLOW

Moteino.bootloader.lock_bits=0x0F

Moteino.build.mcu=atmega328p
Moteino.build.f_cpu=16000000L
Moteino.build.core=arduino:arduino
Moteino.build.variant=arduino:standard
Moteino.build.board=AVR_MOTEINO
##############################################################
MoteinoMEGA.name=MoteinoMEGA
MoteinoMEGA.upload.tool=avrdude
MoteinoMEGA.upload.maximum_size=130048
MoteinoMEGA.upload.maximum_data_size=16384
MoteinoMEGA.upload.speed=115200
MoteinoMEGA.upload.protocol=arduino

THIS LINE IS TO BE ADDED

MoteinoMEGA.bootloader.tool=avrdude

MoteinoMEGA.bootloader.low_fuses=0xDE
MoteinoMEGA.bootloader.high_fuses=0xDE

THIS LINE IS TO BE MODIFIED

#MoteinoMEGA.bootloader.extended_fuses=0xFD

AS FOLLOW

MoteinoMEGA.bootloader.extended_fuses=0x05

MoteinoMEGA.bootloader.unlock_bits=0x3F

THIS LINE IS TO BE MODIFIED

#MoteinoMEGA.bootloader.lock_bits=0xCF

AS FOLLOW

MoteinoMEGA.bootloader.lock_bits=0x0F

MoteinoMEGA.bootloader.path=Moteino
MoteinoMEGA.bootloader.file=DualOptiboot_V5.0_atmega1284p_BlinkD15.hex

MoteinoMEGA.build.mcu=atmega1284p
MoteinoMEGA.build.f_cpu=16000000L
MoteinoMEGA.build.core=arduino:arduino
MoteinoMEGA.build.variant=MoteinoMEGA
MoteinoMEGA.build.board=AVR_MOTEINOMEGA

May be Nick will add these new boot loaders in a new release of its code :slight_smile:

I missed this thread when it first appeared. :frowning:

Writing a bootloader-uploader is a juggling act between keeping everyone happy, and having a sketch that is too large (or unwieldy).

For one-off situations I tend to use my other sketch: Gammon Forum : Electronics : Microprocessors : Atmega chip stand-alone programmer to upload .hex files - then you just put your bootloader onto a SD card and upload it. Very useful for more customized situations.