Problem burning dual optiboot (Solved)

Started by Hermann, April 07, 2014, 04:25:25 PM

Hermann

After using some homemade Moteinos (R1) for some time, I decided to try the RFM69 module and the wireless programming.
So I made some Moteino R4 boards and tried to burn the dual optiboot loader. I downloaded the ZIP from Github, made a copy of the optiboot folder and replaced the files optiboot.c and makefile as described.
In a DOS box I entered "make atmega328" and got this:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

e:\Atmel\Arduino\arduino-1.0.3\hardware\arduino\bootloaders\doptiboot_moteino>make atmega328
MAKE Version 5.2  Copyright (c) 1987, 2000 Borland
Error makefile 50: Command syntax error
Error makefile 58: Command syntax error
Error makefile 65: Command syntax error
Error makefile 67: Command syntax error
Error makefile 70: Command syntax error
Error makefile 72: Command syntax error
Error makefile 73: Command syntax error
Error makefile 75: Command syntax error
Error makefile 80: Command syntax error
Error makefile 83: Command syntax error
*** 10 errors during make ***


Then I tried "omake atmega328" and got this:
e:\Atmel\Arduino\arduino-1.0.3\hardware\arduino\bootloaders\doptiboot_moteino>omake atmega328

e:\Atmel\Arduino\arduino-1.0.3\hardware\arduino\bootloaders\doptiboot_moteino>..
\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino atmega328
../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-spl
it-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=16000000L  '-DLED_START_FLA
SHES=3' '-DBAUD_RATE=115200' '-DLED_DATA_FLASH=1'   -c -o optiboot.o optiboot.c
optiboot.c: In function 'CheckFlashImage':
optiboot.c:367: error: 'PB3' undeclared (first use in this function)
optiboot.c:367: error: (Each undeclared identifier is reported only once
optiboot.c:367: error: for each function it appears in.)
optiboot.c:367: error: 'PB5' undeclared (first use in this function)
make: *** [optiboot.o] Error 1


In another topic in this forum I read about a similar problem and replaced PB3 with PORT3 and PB5 with PORT5.
This way the bootloader compiled with omake - make still gave the same errors - and I could burn it.

BUT! The first thing I noticed was that the LED did not blink... And it is not possible to upload a sketch. "stk500_getsync(): not in sync..." I can see the TX LED on the FTDI adapter blink but there is no answer from the Moteino. I also burned the file DualOtiboot_atmega328_1k_d9LED_debugOFF.hex but the results are the same.
Just to make sure the hardware is ok I burned the older optiboot loader I use for my other Moteinos and that worked. LED blinks, uploads work OK.
For now all I have on the board is the processor, resonator, LED and capacitors. So no voltage regulator, flash memory chip or radio.

Any ideas what went wrong?

Felix


Hermann

Felix, thanks for the quick answer.
I am sure the code is ok and I burned the file you mention  but it still won't work.
Does the memory chip have to be there for it to work?

Felix

No flash needed, just atmega328P.
You will need a good programmer for burning. I tell everyone to just get an AVR ISP MKii.
Make sure to burn the fuses as well.

Hermann

Yep. That was it!
So if you do it like me and download the code from Github there is one more step necessary:
Just replacing optiboot.c and makefile is not enough. In pin_defs.h you need to replace
#define LED         PINB1

with
#define LED         PINB5
to activate the LED on pin 9.
Of course if you use the precompiled hex file this is not necessary.

Then the fuses: since the dual optiboot loader is twice as big as the original, the high fuse must be changed to 0xDC and the max. size of the sketch is 31744.

Here is the part of boards.txt referring to the Moteino:
moteinow.name=Moteino Wireless
moteinow.upload.protocol=arduino
moteinow.upload.maximum_size=31744
moteinow.upload.speed=115200
moteinow.bootloader.low_fuses=0xFF
moteinow.bootloader.high_fuses=0xDC
moteinow.bootloader.extended_fuses=0x05
moteinow.bootloader.path=doptiboot_moteino
moteinow.bootloader.file=optiboot_atmega328.hex
moteinow.bootloader.unlock_bits=0x3F
moteinow.bootloader.lock_bits=0x0F
moteinow.build.mcu=atmega328p
moteinow.build.f_cpu=16000000L
moteinow.build.core=arduino
moteinow.build.variant=standard


Felix, thank you for the awesome work you are doing here and for sharing it!

Felix

Hey you're welcome, glad you solved it. And thanks for sharing your boards file, it should help other folks that are looking for it (actually only necessary when lock fuses are not set and sketch size is over 31K).
Recently I started locking down the boot section from any SPM/LPM instructions access to avoid bootloader corruption.