Author Topic: Burning Optiboot / DualOptiboot bootloader [solved]  (Read 66540 times)

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: optiboot loader
« Reply #15 on: February 04, 2015, 08:30:03 AM »
The bootloader is itself a program that sits at the END of the flash region (in our case the last KB of the available 32KB).
Its function is to help you load the real program via serial (and hence FTDI) instead of having to load it via ISP/AVR programmer every time.
The bootloader starts every time you power the board. It checks whether there was a hardware reset (FTDI does that via the DTR line which in turn asserts the RST signal through a 0.1uF cap, see schematic) and if so it will wait for about 1-3 seconds for a serial programming request. If there was no reset (in the case of plain power up from GND+VCC) or there was no sketch upload request via serial, it will jump directly to the existing program section at the START of the flash region. If there is no program there (blank chip) it does nothing, no blinking, nothing. Blank memory doesnt flash LEDS (it would be very disturbing if it did!).
So once you burn your bootloader, the chip still doesnt do anything useful other than look for a sketch upload request via FTDI. When you load your real sketch via FTDI it will jump to that sketch and start doing things. That's when you can load a blinky sketch so once its uploaded you should see your LED blinking.
I hope this clears things up a bit.

vectorspace

  • NewMember
  • *
  • Posts: 8
Re: optiboot loader
« Reply #16 on: February 04, 2015, 08:47:31 AM »
Clears it up very well.

I'll be posting my Moteino based Davis VP2 wireless weather receiver display project once it's cleaned up a bit.



I've got it pretty close to done but still needs some work right now.

vectorspace

  • NewMember
  • *
  • Posts: 8
Re: optiboot loader
« Reply #17 on: February 04, 2015, 03:00:06 PM »
Just uploaded a blink program with FTDI into both the DIYMoteino and DIYMoteinoMega.

BINGO!

Both are blinking quite nicely.  Thank you so much for taking the time to help teach me some things AND help me get these going.

Cheers!!!   ;D

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: optiboot loader
« Reply #18 on: February 04, 2015, 08:53:28 PM »
Awesome, good for you!

ivars211

  • NewMember
  • *
  • Posts: 16
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #19 on: February 27, 2015, 10:30:07 AM »
I am trying to make a custom board using Atmega1284p and would love to use the wireless programming features. But I am having the same problem, i.e.
Code: [Select]
avrdude: Device signature = 0x1e9705
....
....
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x3f
avrdude: verification error; content mismatch
when trying to burn moteino dual optiboot from Arduino IDE and using uno board as ISP programmer. I can however, burn "Mighty 1284p 16Mhz using optiboot" and "Original Mighty 1284p 16Mhz" without any problem.
Since I am cheap and don't want to spend money on proper programmer, is there any way to burn the bootloader without buying extra hardware? (Arduino as ISP programmer worked well so far).
« Last Edit: February 27, 2015, 10:33:59 AM by ivars211 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #20 on: February 27, 2015, 10:50:16 AM »
I don't know ... i always use a real programmer. Cheap is only cheap if your time is not worth anything ;)

ivars211

  • NewMember
  • *
  • Posts: 16
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #21 on: February 27, 2015, 01:12:16 PM »
Although I am a lazy bastard, I feel the need to share the solution with community.

In this example my ArduinoISP is on port 4 and I am using Arduino uno (atmega328pu) and I am trying to program atmega1284p

1) Download avrdude and extract. http://mirror6.layerjet.com/nongnu//avrdude/avrdude-5.11-Patch7610-win32.zip
2) make a new folder on your C: drive called "avrdude"
3) Copy the extracted files in step 1 to that folder
4) Download/copy the bootloader file to the avrdude folder created in step2. (DualOptiboot_V5.0_atmega1284p_BlinkD15.hex in my case hardware\MoteinoMEGA_Core\bootloaders\MoteinoMEGA)
5) Rename the .hex file to boot.hex
4) Connect your ArduinoISP, check on which port it is.
5) Open cmd, start->cmd
6) write "cd C:\avrdude"
7) write "avrdude -c arduino -p m1284p -P \\.\COM4 -b 19200 -v"
All the information about the chip should show up. If not, check your power supply and wiring. You are good to go to step 8
8 ) write "avrdude -c arduino -p m1284p -P \\.\COM4 -b 19200 -U flash:w:boot.hex:i -U efuse:w:0xFD:m -U hfuse:w:0xDE:m -U lfuse:w:0xDE:m"
9) should take a minute or so and if no error, just upload the code through Arduino IDE


References: http://heliosoph.mit-links.info/arduinoisp-reading-writing-fuses-atmega328p/

P.S. Saved 50 pounds and spent 2 hours googling, thats 3 times my wage per hour there. :D
« Last Edit: March 24, 2015, 01:16:19 PM by ivars211 »

dale.s

  • NewMember
  • *
  • Posts: 14
Re: optiboot loader
« Reply #22 on: June 11, 2015, 05:59:10 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

Now that the AVR ISP MKii has been discontinued, do you have a suggestion on another programmer to use? I can find lots of MKii clones, but somehow i just don't trust them without good reports!

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #23 on: June 11, 2015, 06:12:05 PM »
I've successfully used a moteino to program another moteino using the sketch that ships with Arduino and avrdude. I did this while I was waiting for the mkii to ship (yes impatient). It might be worth a try.

I did fry a moteino but that was due to my bootloader accessing the radio after install and talking against the programmer on spi.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: optiboot loader
« Reply #24 on: June 11, 2015, 06:53:47 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

Now that the AVR ISP MKii has been discontinued, do you have a suggestion on another programmer to use? I can find lots of MKii clones, but somehow i just don't trust them without good reports!
Have you answered the very first question from above? 
If you need to reflash a Moteino...
You only need an ISP programmer if you need to reflash the fuses or bootloader.  If you're using a standard Moteino and just changing sketchcode, you can use an FTDI cable to program your Moteino.  Very few people need the former.

Tom

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #25 on: June 11, 2015, 07:04:22 PM »
I've successfully used a moteino to program another moteino using the sketch that ships with Arduino and avrdude. I did this while I was waiting for the mkii to ship (yes impatient). It might be worth a try.

I did fry a moteino but that was due to my bootloader accessing the radio after install and talking against the programmer on spi.
Does this mean we finally get to see the code?

When you say you 'fried' a moteino (I prefer them toasted) does that mean you need to wait for the MKII to arrive or did you really 'fry' it?

Tom

dale.s

  • NewMember
  • *
  • Posts: 14
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #26 on: June 11, 2015, 08:03:15 PM »
I do like tweeking bootloaders so i use one for that, and i do a fair amount with attiny chips so i tend to use one with that, uptill now ive been using arduino-as-isp then moved onto a usbasp.  Im sick of all the little problems you get with these, they can be so flaky!

I found a few sites with what they claim to be "real" MKii's but they price is upto $55+ and im not 100% sure they are accually REAL MKii's.
Lots of clones out there, some with interesting extra bits, saw one with a logic analyser built in, seems interesting, however id much rather have somthing i know is 100% supported and 100% working!

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #27 on: June 11, 2015, 08:47:50 PM »
I do like tweeking bootloaders so i use one for that, and i do a fair amount with attiny chips so i tend to use one with that, uptill now ive been using arduino-as-isp then moved onto a usbasp.  Im sick of all the little problems you get with these, they can be so flaky!

I found a few sites with what they claim to be "real" MKii's but they price is upto $55+ and im not 100% sure they are accually REAL MKii's.
Lots of clones out there, some with interesting extra bits, saw one with a logic analyser built in, seems interesting, however id much rather have somthing i know is 100% supported and 100% working!
I've managed with Sparkfun's pocket programmer.  It's sort of a PITA, but, supremely flexible.  I don't use it for Sketch loading, only fuse and bootloader 'adjustments'.

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #28 on: June 12, 2015, 03:01:27 AM »
Quote
When you say you 'fried' a moteino (I prefer them toasted) does that mean you need to wait for the MKII to arrive or did you really 'fry' it?

As i remember this one didn't come back to life. It seems understandable that two SPI masters talking at the same time could do some damage to the atmega328. I've had the mkii for months and I'm happy with it.

Quote
Does this mean we finally get to see the code?

I'd say from a functionality perspective it's ready. It now does adaptive bitrate downgrading so it'll work wherever Felix 55kbaud bitrate works (it actually goes down to 19200baud if necessary but clients initially connect at 55kbaud). It's just still pretty tightly coupled with the rest of my stuff and right now I'm also a bit occupied work wise  :-\

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Burning Optiboot / DualOptiboot bootloader [solved]
« Reply #29 on: June 12, 2015, 08:55:27 AM »
First there's a difference between fried and bricked. Fried is physical damage/magic smoke etc. Bricked is at a fuse/firmware level and there's various degrees to that as well.

I will forever stay away from programmer clones and aftermarket stuff, or things made by 3rd parties. I will only use a genuine mkII or ICE AVR programmer. I've had bad experiences. If the programming of the fuses is not done right or there's a glitch and you write an invalid byte there, your mega can be bricked. It happened a lot in my early days and it was driving me crazy and thought it was me doing something wrong or pogo pins weren't making good contact etc.

It will take a lot of effort to unbrick it with HV programming and I've done that too in the old days, and about half the chips were salvaged. Not to mention having to desolder and resolder them. Even that is a big issue with the packages being moisture rated and could get damaged when desoldering with hot air etc.