Go Down

Topic: Optiboot for 8MHz 3.3V Arduino Pro Mini (Read 9716 times) previous topic - next topic

fanofard

Hi,
I have recent version of Optiboot. How should I proceed for having working Optiboot bootloader in Arduino Pro Mini with 8MHz crystal? I am able to burn the bootloader, but then I am failing on uploading of the sketch.

I have following entry in boards.txt:

Code: [Select]
##############################################################
## Optiboot on 32pin (SMT) CPUs (Nano, Pro Micro, etc.)
##############################################################

optiboot32.name=Optiboot on 32-pin cpus

optiboot32.upload.tool=arduino:avrdude
optiboot32.upload.protocol=arduino
optiboot32.upload.speed=115200

optiboot32.bootloader.tool=arduino:avrdude
optiboot32.bootloader.low_fuses=0xF7
optiboot32.bootloader.unlock_bits=0x2F
optiboot32.bootloader.lock_bits=0x0F
optiboot32.build.f_cpu=16000000L

#
# Other Clock speeds.
#  For 8MHz using the internal RC Oscillator, we adjust fuses, use the same
#  bootloader binary, and halve the upload rate.
#
optiboot32.menu.mhz.16MHz=16MHz
optiboot32.menu.mhz.16MHz.upload.speed=115200
optiboot32.menu.mhz.16MHz.upload.speed=57600
optiboot32.menu.mhz.8MHzC=8MHz (crystal)
optiboot32.menu.mhz.8MHzC.build.f_cpu=8000000L
optiboot32.menu.mhz.8MHzC.upload.speed=57600
optiboot32.menu.mhz.8MHz=8MHz (int)
optiboot32.menu.mhz.8MHz.build.f_cpu=8000000L
optiboot32.menu.mhz.8MHz.bootloader.low_fuses=0xE2
optiboot32.menu.mhz.8MHz.upload.speed=57600
optiboot32.menu.mhz.1MHz=1MHz (int)
optiboot32.menu.mhz.1MHz.build.f_cpu=1000000L
optiboot32.menu.mhz.1MHz.bootloader.low_fuses=0x62
optiboot32.menu.mhz.1MHz.upload.speed=9600

# optiboot platforms should be UNO-like more than anything else.
optiboot32.build.board=AVR_UNO
optiboot32.build.core=arduino:arduino
optiboot32.build.variant=arduino:eightanaloginputs


## Optiboot for ATmega328p
## ---------------------------------------------
optiboot32.menu.cpu.atmega328p=ATmega328p
optiboot32.menu.cpu.atmega328p.upload.maximum_size=32256
optiboot32.menu.cpu.atmega328p.upload.maximum_data_size=2048

optiboot32.menu.cpu.atmega328p.bootloader.high_fuses=0xDE
optiboot32.menu.cpu.atmega328p.bootloader.extended_fuses=0x05
optiboot32.menu.cpu.atmega328p.bootloader.file=optiboot/optiboot_atmega328.hex

optiboot32.menu.cpu.atmega328p.build.mcu=atmega328p


I choose "Optiboot on 32-pin cpus" as the board, "8MHz (crystal)" as the CPU Speed and using Arduino UNO with ArduinoISP sketch loaded, I burn the bootloader successfully (see the log in an attached file).

So this is fine. But the problem comes up when I want to upload the sketch via ftdi cable (the log is attached).

I read several threads where they suggested to upload the 16MHz version of the bootloader and then using half baud rate (57600) when uploading. I do not know why this does not work for me. I think optiboot_atmega328.hex is a 16MHz optiboot bootloader and as you can see, I use 57600 baud rate when uploading:

Code: [Select]
Using Port                    : /dev/ttyUSB0
Using Programmer              : arduino
Overriding Baud Rate          : 57600


Can anybody "aim" me to working procedure?
What is interesting - when I use the standard bootloader "Pro or Pro Mini - ATmega328 (3.3V, 8 MHz) - atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex" in 1.6.7 IDE, everything works.

dmjlambert

What are you using for a USB-to-serial adapter?

fanofard

I use FTDI usb to serial converter (the same as on the attached image).

dmjlambert

Well, I had a close read of your post, and it has me stumped.   I am a little concerned about the way the boards.txt entries are arranged, but I guess it's a matter of style and I would have done it a little different.   This one place concerns me but it should not really affect your situation
Code: [Select]
optiboot32.menu.mhz.16MHz.upload.speed=115200
optiboot32.menu.mhz.16MHz.upload.speed=57600


Anyway it seems to me you are doing things right.   

I would suggest you choose "Optiboot on 32-pin cpus" as the board, "8MHz (crystal)" as the CPU Speed and upload the blink sketch using Upload Using Programmer.   Then observe the LED to make sure it is one second on and one second off.  That would make sure the crystal is really 8MHz.   Then re-burn the bootloader.    I am trying to imagine circumstances in which your process could fail and I just don't know.   

dmjlambert

You know just for kicks, you might try doing this with IDE version 1.6.5 and see what you get.  Also, make sure you have show verbose output during compilation and during upload checked in the IDE preferences.   Perhaps something would catch your eye in the output it gives you. 

DrAzzy

#5
Feb 14, 2016, 06:42 pm Last Edit: Feb 14, 2016, 06:44 pm by DrAzzy
The final error:


avrdude: stk500_recv(): programmer is not responding


suggests that it wasn't able to get far enough to get a sync error, and you'll get a sync error without even connecting an atmega chip....

Does that serial adapter work for you? Do loopback test on it, and if it doesn't work, fiddle with drivers until it does.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

fanofard

I tried once again now - I chose "Pro or Pro Mini - ATmega328 (3.3V, 8 MHz)", so non-optiboot bootloader and flashed it into the Pro Mini. Afterwards I connected the pro mini to the ftdi cable and tried to upload a sketch --> it worked properly.

Then I flashed the optiboot image as described in my 1st post, connected to ftdi and the same issue - I am not able to upload a sketch to the pro mini. So at least my FTDI cable works.

Currently I have no other pro mini with 8MHz crystal, so I can't test with another piece. But I do have an atmega328p DIP 28pin and I will try with that one on the breadboard with 8MHz crystal - just to check whether there is a general problem or a problem related to the currently tested pro mini.

fanofard

The breadboard setup resulted into the same issue.
I found this post - http://forum.arduino.cc/index.php?topic=134508.0
and this port - http://forum.arduino.cc/index.php/topic,101064.msg760450.html#msg760450
There is optiboot_atmega328_pro_8MHz.hex which user claims is compiled with 8MHz setting.
Believe or not, but once flashed into the Pro Mini, I am able to upload the sketch into it.

This is the boards entry for the mentioned hex file I used:

Code: [Select]
pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328

pro328.upload.tool=arduino:avrdude
pro328.upload.protocol=arduino
pro328.upload.maximum_size=32256
pro328.upload.speed=57600
pro328.bootloader.tool=arduino:avrdude

pro328.bootloader.low_fuses=0xFF
pro328.bootloader.high_fuses=0xDE
pro328.bootloader.extended_fuses=0x05
#pro328.bootloader.path=optiboot
pro328.bootloader.file=optiboot/optiboot_atmega328_pro_8MHz.hex
#pro328.bootloader.path=atmega
#pro328.bootloader.file=optiboot/ATmegaBOOT_168_atmega328_pro_8MHz.hex
pro328.bootloader.unlock_bits=0x3F
pro328.bootloader.lock_bits=0x0F

pro328.build.mcu=atmega328p
pro328.build.f_cpu=8000000L
pro328.build.core=arduino
pro328.build.board=AVR_UNO
pro328.build.variant=standard


This is the difference between "original" optiboot hex file and the one I downloaded from the post above:

Code: [Select]
diff optiboot_atmega328_pro_8MHz.hex optiboot_atmega328.hex
4c4
< :107E300028E13EEF91E0309385002093840096BBCB
---
> :107E300020E33CEF91E0309385002093840096BBD3

fanofard

Interesting is the current optiboot package from https://github.com/Optiboot/optiboot includes the file with the same name, but the file is different size and when I replace the "downloaded from http://forum.arduino.cc/index.php/topic,101064.msg760450.html#msg760450" hex file with the one which is included in the official optiboot package, it does not work - I can burn this bootloader, but using the same entry in boards.txt, the upload of a sketch fails.

I am wondering what is the optiboot_atmega328_pro_8MHz.hex in the official optiboot github repository for or how it should be flashed to have it working properly with Pro Mini 8MHz (crystal).

dmjlambert

 That is interesting, it seems you have found a mystery. I'm glad you got it going somewhat.

fanofard

I believe this is not a mystery and it has an explanation. I would be very interested in the explanation of the issue and I would like to know what should be the official procedure for putting optiboot into an 8MHz crystal version of the pro mini.

dmjlambert

It's up to you to explain it to us!  :-)  We're counting on you.   There isn't an official procedure because officially the Pro Mini comes with the ATmegaBOOT bootloader.   The semi-official way on the forum is to use Nick Gammon's Board Programmer sketch and use it to load the UNO 16MHz bootloader onto it.   Then when your Pro Mini runs that bootloader at 8MHz it will result in the baud rate half speed, 57600.  

http://www.gammon.com.au/bootloader


dmjlambert

Also WestfW has a sketch that he recently updated, called OptiLoader:

https://github.com/WestfW/OptiLoader

westfw


fanofard

OK, so I needed a bit of sleep to get it working :)
I took the current version (6.2) of the optiboot from theit repository. Then I modified Makefile and changed:
Code: [Select]
ifdef BAUD_RATE
BAUD_RATE_CMD = -DBAUD_RATE=$(BAUD_RATE)
dummy = FORCE
else
BAUD_RATE_CMD = -DBAUD_RATE=115200
endif


to
Code: [Select]
ifdef BAUD_RATE
BAUD_RATE_CMD = -DBAUD_RATE=$(BAUD_RATE)
dummy = FORCE
else
BAUD_RATE_CMD = -DBAUD_RATE=57600
endif


Then executed (ubuntu 15.04):
sudo apt-get install gcc-avr
sudo apt-get install avr-libc
make clean
make atmega328_pro8

And it compiled new bootloader optiboot_atmega328_pro_8MHz.hex

Interesting is there was this warining about BAUD_RATE error greater than 2%:

Code: [Select]
make atmega328_pro8
make atmega328 AVR_FREQ=8000000L LED_START_FLASHES=3
make[1]: Entering directory '/tmp/optiboot-master/optiboot/bootloaders/optiboot'
avr-gcc (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 57600, Real: 58823, UBRRL = 16, Error=2.1%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=8000000L  -DBAUD_RATE=57600 -DLED_START_FLASHES=3        -c -o optiboot.o optiboot.c
optiboot.c:305:6: warning: #warning BAUD_RATE error greater than 2% [-Wcpp]
     #warning BAUD_RATE error greater than 2%
      ^
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=8000000L  -DBAUD_RATE=57600 -DLED_START_FLASHES=3      -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o -lc
avr-size optiboot_atmega328.elf
   text    data     bss     dec     hex filename
    464       0       0     464     1d0 optiboot_atmega328.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
rm optiboot.o optiboot_atmega328.elf
make[1]: Leaving directory '/tmp/optiboot-master/optiboot/bootloaders/optiboot'
mv optiboot_atmega328.hex optiboot_atmega328_pro_8MHz.hex
mv optiboot_atmega328.lst optiboot_atmega328_pro_8MHz.lst


I am not an expert in this area (as you already most likely noticed  :D ) and I do not know based on what is the error rate calculeted and how does it affects things.
Nevermind - I took the built hex file, renamed it to optiboot_atmega328_pro_8MHz_56k.hex (to prevent confusion) and burned it to the pro mini 8MHz using this boards.txt entry:

Code: [Select]
pro328.name=[Optiboot 6.2] Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 for 56K
pro328.upload.protocol=arduino
pro328.upload.maximum_size=32256
pro328.upload.speed=57600
pro328.bootloader.low_fuses=0xFF
pro328.bootloader.high_fuses=0xDE
pro328.bootloader.extended_fuses=0x05
#pro328.bootloader.path=optiboot
pro328.bootloader.file=optiboot/optiboot_atmega328_pro_8MHz_56k.hex
pro328.bootloader.unlock_bits=0x3F
pro328.bootloader.lock_bits=0x0F
pro328.build.mcu=atmega328p
pro328.build.f_cpu=8000000L
pro328.build.core=arduino:arduino
pro328.build.variant=arduino:standard


Now guess what? :) FINALLY I got it working!!!
So it looks the optiboot_atmega328_pro_8MHz.hex which is originally included in optiboot repository is built with 115200 baud rate and 8MHz, so you can't use it for the pro mini 8mhz (I tried this before and it did not work). And the trick was to build an optiboot bootloader atmega328_pro8 with 57600 baud rate. And the building is quite east - just editing 1 line in Makefile and 2 commands as mentioned above.

Go Up