Burning Optiboot / DualOptiboot bootloader [solved]

Started by lilpint97, January 27, 2014, 01:04:27 PM

lilpint97

This may be a dumb question, but if one needed to reload the optiboot loader, can this be done through the moteino pins? If so which pins would one connect to the AVR programmer? I am looking at the following one: http://www.amazon.com/SparkFun-Pocket-AVR-Programmer/dp/B004G54E9I/ref=pd_sim_sbs_indust_2

I am new to this level of programming so hope not sounding to silly.

Thanks.

Felix

If you need to reflash a Moteino you:

- need an AVR programmer - just get the AVR ISP MKii (digikey, don't mess with other cheapie non OEM ones. Saving $10 here is REALLY not worth it - see http://www.digikey.com/product-search/en?keywords=ATAVRISP2-ND
- need to power the Moteino independently of the AVR programmer
- need to pullup pin D10 if the RFM69 radio is already soldered
- the pins are the standard ISP protocol pins (VCC, GND, RST, SPI_CK, SPI_MISO, SPI_MOSI)
- use AVR Studio with target Atmega328p

lilpint97

Thanks that is helpful, and one last dense question, when you say "need to pullup pin D10 if the RFM69 radio is already soldered" add a pull up resistor or de-solder pin 10?

Thanks.

Felix

Pull up D10 to VCC with a high K resistor, ie 10K is good enough.

ltj

Everything Felix said :) However it works absolutely fine using the "Arduino as ISP" trick. That could save you the AVR ISP mkII if you really only need to do this on rare occasions. Check out http://jeelabs.org/2011/05/29/summary-of-isp-options/ for some rather creative takes on ISP.

vectorspace

#5
Quote from: Felix on January 27, 2014, 02:17:23 PM
If you need to reflash a Moteino you:

- need an AVR programmer - just get the AVR ISP MKii (digikey, don't mess with other cheapie non OEM ones. Saving $10 here is REALLY not worth it - see http://www.digikey.com/product-search/en?keywords=ATAVRISP2-ND
- need to power the Moteino independently of the AVR programmer
- need to pullup pin D10 if the RFM69 radio is already soldered
- the pins are the standard ISP protocol pins (VCC, GND, RST, SPI_CK, SPI_MISO, SPI_MOSI)
- use AVR Studio with target Atmega328p

I've built a DIY Moteino and 2 DIY MoteinoMegas and can't get past burning the bootloader. I'm trying to use an AVRasp programmer and also tried a USBTinyISP on the 328P. From the instructions above, should I assume that using "Burn Bootloader" in the Arduino IDE won't work? Doing that with the 328P results in:
***failed;  
avrdude: verification error, first mismatch at byte 0x0000
         0xfd != 0x05
avrdude: verification error; content mismatch


I started with the Mega and had similar errors. I kept fooling around with the IDE Burn Bootloader and also with AVRDUDESS until I bricked it. I put together another Mega but until I can get a bootloader into the 328P I don't want to chance killing another 1284P.

I was able to read the signature of both MCUs and change the fuses with avrdude. I then tried avrdude to burn the flash and got this:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 

avrdude.exe: set SCK frequency to 32000 Hz
avrdude.exe: AVR device initialized and ready to accept instructions

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

avrdude.exe: Device signature = 0x1e950f
avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: set SCK frequency to 32000 Hz
avrdude.exe: reading input file "C:\Users\Jphn\OneDrive\Elec\ArduinoLib\userSketch\hardware\Moteino\bootloaders\Moteino\DualOptiboot_V5.0_atmega328_BlinkD9.hex"
avrdude.exe: input file C:\Users\Jphn\OneDrive\Elec\ArduinoLib\userSketch\hardware\Moteino\bootloaders\Moteino\DualOptiboot_V5.0_atmega328_BlinkD9.hex auto detected as Intel Hex
avrdude.exe: writing flash (32768 bytes):

Writing | ################################################## | 100% 0.00s

avrdude.exe: 32768 bytes of flash written
avrdude.exe: verifying flash memory against C:\Users\Jphn\OneDrive\Elec\ArduinoLib\userSketch\hardware\Moteino\bootloaders\Moteino\DualOptiboot_V5.0_atmega328_BlinkD9.hex:
avrdude.exe: load data flash data from input file C:\Users\Jphn\OneDrive\Elec\ArduinoLib\userSketch\hardware\Moteino\bootloaders\Moteino\DualOptiboot_V5.0_atmega328_BlinkD9.hex:
avrdude.exe: input file C:\Users\Jphn\OneDrive\Elec\ArduinoLib\userSketch\hardware\Moteino\bootloaders\Moteino\DualOptiboot_V5.0_atmega328_BlinkD9.hex auto detected as Intel Hex
avrdude.exe: input file C:\Users\Jphn\OneDrive\Elec\ArduinoLib\userSketch\hardware\Moteino\bootloaders\Moteino\DualOptiboot_V5.0_atmega328_BlinkD9.hex contains 32768 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude.exe: verifying ...
avrdude.exe: verification error, first mismatch at byte 0x7c00
             0x00 != 0x11
avrdude.exe: verification error; content mismatch

avrdude.exe done.  Thank you.


I tried numerous SCK frequencies and also specified the -b at sever different rates without success.
No radios soldered and no Flash.

Do I need to install/use AVR Studio?
Do I need a different programmer?

The Moteinos I purchased from you have been performing flawlessly. Thanks for a great project/product.


Felix

Since I always used AVR Studio for flashing I don't have the patience to try something else since I know that method just works. So it's the default I recommend. I too tried other methods and the IDE and avrdude etc etc... just a mess and waste of time. AVR Studio does the job, every time :)

vectorspace

Thanks for the quick-fast reply.

I'll d/l and run AVR Studio and give it a spin.


vectorspace

So, I've got the latest AVR Studio installed. I looked up how to use the USBasp and decided to use the AVR Dragon instead. Wired up the ISP connection to my DIY Moteino board. And just as you stated, AVR Studio worked much better and there were no errors. I set the fuses to LO:DE   HI:DC   EX:FD and then burned the DualOptiboot hex file.

For the first time since I built the board the LED lit up and it does so each time I read or write to the board!!

I didn't really understand the UNlock_bit line in the boards.txt file (Moteino.bootloader.unlock_bits=0x3F    Moteino.bootloader.lock_bits=0xCF) so I left those at default. I'm assuming that the bootloader should blink the LED regardless of the Lock (and UNlock) bits??

But I'm not getting the blinking LED after the bootloader is burned and confirmed. Below are the results:

Fuses:


Flash:


Lock bits:


Do you have any suggestions as to what I'm doing wrong?





Felix

Everything looks good. You need not touch the lock fuses unless you want to block access to the bootloader section from the program section.
The fuses are good and the bootloader should work.
The LED blinking is caused by the bootloader, that is expected after you burn the bootloader.
I am not sure what other blinking you are expecting?

vectorspace

The only time the LED does anything is when AVR Studio reads or writes. It's not blinking after the bootload burn.

I also just tried to burn the bootloader for the DIY MoteinoMega and got the same results. The fuses and Flash burn all show good in AVR Studio but no blinking LED.

No telling what I've screwed up here. . .

:(


Felix

So after the burn you can't program them via FTDI?
Any LED activity is ONLY going to be caused by the bootloader. Nothing else will turn digital pins on/off randomly like that. So my guess is you've burned the bootloader right.
For the MEGA the bootloader is different, make sure you fetch the HEX compiled for the 1284p MCU.

vectorspace

Haven't tried the FTDI burn yet. After the burning described, if I provide 3.3V and GND, neither board does anything and no LED activity. The LED lit only when reading/writing Fuse bits or reading/writing Flash with Dragon.

I did use the other .hex file for the mega.


Felix

Of course, applying power will cause the bootloader to jump directly to the program section, which in your case is blank.
So I dont think there's any issue. Please report back once you try the sketch upload via FTDI header.

vectorspace

"I see" said the blind man, as he picked up his hammer and saw.   8)
So when you burn the bootloader you also burn a program that flashes the LED? Somehow I was under the impression that the bootloader did that itself.
That's definitely the piece I was missing. I really appreciate the help. In spite of the issues I encounter doing this kind of stuff (or perhaps because of them??) I'm enjoying the learning experience.

I'll report back as soon as I give it a try. Thanks!