Pages: 1 [2]   Go Down
Author Topic: Building custom bootloader?  (Read 3141 times)
0 Members and 1 Guest are viewing this topic.
Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Check the bootloader version in your Uno (see instructions here http://arduino.cc/forum/index.php/topic,64105.msg468453.html#msg468453).  Thanks to Westfw's work on optiboot, recent versions >=4.3 don't require reset to be disabled when running ArduinoISP.

Another good thing to know. Thanks! (Someone should update the ArduinoISP wiki to mention this :-).
Logged


SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
recent versions >=4.3 don't require reset to be disabled when running ArduinoISP.
FWIW, things still seem to work better for me with the cap between RESET and GND...
Logged

Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Seemed to work OK without the cap, but I did encounter the bug with 19200 baud causing problems. Had to figure out how to get everyone to agree on 9600 baud, then I was able to burn the new bootloader.
Logged


Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And now I've tried to use the watchdog reset gimmick to upload a new sketch and am utterly confused by the results :-). Avrdude appears to start talking to the bootloader OK (I don't get the kind of sync errors I get without the reset), but it gets to the point where it says "Writing" and would normally print # chars for progress, but it makes no progress and eventually says "not responding".

But wait! It gets weirder. At this point, it has apparently erased the old sketch, so now it really is sitting in the bootloader doing the 1-2-3 flashy thing on pin 13. If I try to upload the new sketch again, it works perfectly.

So I have a procedure that works for uploading microcode without physical access to the board, but I have no idea why it works :-).

Anyone know if there are things I need to reset manually that a watchdog reset doesn't reset? Should I be using different lock bits or something to make a watchdog reset "harder" in some way? I'm really mystified.

If anyone is actually curious enough to want to look at my bootloader hacks and the code that uses them, you
can always find the latest version of the source pointed at by:

http://home.comcast.net/~tomhorsley/hardware/arduino/software.html
Logged


Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, I'm not sure I follow.  Is this the sequence of events?

  • Sketch sets eeprom flag and executes watchdog reset
  • Bootloader starts running : detects and wipes eeprom flag, does three LED flashes, and starts communicating with AVRdude
  • Communication is lost for reasons unknown, and AVRdude hangs
  • Bootloader watchdog expires and bootloader resets itelf
  • On this pass the bootloader does not flash the LEDs but immediately tries to start the sketch
  • The sketch has been wiped, so nothing happens

How do you trigger the second sketch upload attempt?
Logged

Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually after the first failure, the bootloader seems to be in a loop starting itself back up over and over again. The 3 flashes keep happening at that point, so the 2nd upload always encounters the bootloader no matter when I start it. I did see some code in there that says something about temporarily reprogramming the reset vector to point to the bootloader, so perhaps it gets that far and no farther and it is just constantly hitting watchdog reset and calling bootloader over and over? Still have no idea why the first attempt fails though.
Logged


Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hum.  Try putting AVRdude into very verbose mode (avrdude -v -v -v -v ...) and look for the command which fails.  It will also tell you if your fuses are set correctly (low=0xFF, high=0xDC, ext=0x05).  You could also check that the memory is being unlocked properly before writing (lock=0x3f).
Logged

Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried ultra verbose mode, and it is still mysterious (to me anyway). The transcript of the session that failed followed by the one that worked is here:

http://home.comcast.net/~tomhorsley/hardware/arduino/files/transcript.txt

As near as I can tell the first run tells it to write the initial chunk and never gets back a response.

In the second run, everything looks identical to the first right through the first write which does get a response and then keeps going to a successful completion.

Very weird, but I guess I don't absolutely have to understand it. So far running avrdude twice in a row has always worked to do the upload, so I can upload over bluetooth now with no manual intervention.

I adjusted the boot size fuse bits for a 1K bootloader, is there something in lock bits or other fuse bits that needs tweaking?
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you show your fuse/lock bytes? Just use avrdude in -v mode to read from it.
Logged

Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you show your fuse/lock bytes? Just use avrdude in -v mode to read from it.

I suspect I don't understand something. Do I need it hooked up to the ISP to do this? If I just burn a sketch it tells me "safemode read" of all the fuse and lock bytes are zero.

Here's part of the board definition I used when I burned the new bootloader:

aardremote.bootloader.low_fuses=0xff
aardremote.bootloader.high_fuses=0xdc
aardremote.bootloader.extended_fuses=0x05
aardremote.bootloader.unlock_bits=0x3F
aardremote.bootloader.lock_bits=0x0F
aardremote.build.mcu=atmega328p
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's your programmer again? With USBtinyISP I see this:


Code:
$ avrdude -c usbtiny -p m328p -v

avrdude: Version 5.8cvs, compiled on Jan 15 2010 at 17:27:01
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

...

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

I think the ArduinoISP one might not read the fuse bytes, so you don't know for sure what they are. And perhaps you can't change them.
Logged

Pages: 1 [2]   Go Up
Jump to: