Uno bootloader fixer

by westfw on Thu Jan 20, 2011 4:58 am

I've written a short sketch that will help you load a fixed bootloader unto you Uno systems, assuming that you have a second arduino of some kind to do the fixing.

This is based on the arduinoISP programming sketch, except it includes an internal copy of a (fixed) optiboot bootloader, so there are no communications issues. You just connect up an Arduino containing the sketch to an Uno with the iffy bootloader (as per instructions here: http://arduino.cc/en/Tutorial/ArduinoISP ), hit reset, and it will drop in a new bootloader. (Status is displayed to the Serial port at 19200bps, but you don't really need to watch it.)

This is actually a subset of a more ambitious effort to load optiboot into all sorts of old Arduinos, but that's waiting on more complete documentation. meanwhile, doing Uno only is pretty simple and is getting increasingly urgent as more optiboot bugs show up.

the fixed optiboot included in the sketch has:
1) PWM timer initialization fixed (this was also fixed in the core.)
2) 30k upload limit fixed.
3) zero register initialization (Sketch amnesia) fixed.

optifix.zip
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by richms on Thu Jan 20, 2011 5:43 am

Is there any reason that this could not be used to flash a bootloader into a blank 328 to use with the IDE but on protoboard?
richms
 
Posts: 558
Joined: Tue Jan 20, 2009 2:05 am
Location: New Zealand

Re: Uno bootloader fixer

by westfw on Thu Jan 20, 2011 10:55 am

Is there any reason that this could not be used to flash a bootloader into a blank 328

Your breadboard setup will need an external crystal; "optifix" won't deal with the different fuse settings needed to use the internal oscillator before or after the bootloader is programmed. I don't think that the crystal has to be 16MHz, though (it needs to RUN at 16MHz to get the right bitrate for upload.)
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by westfw on Fri Feb 04, 2011 3:09 am

BTW, I managed to confuse at least one user:

Alright WestFW, I got the 16MHz Xtal and followed exactly the instruction and as soon as I opened the serial monitor I hit reset and I got the following output:
OptiFix Bootstrap programmer.
2011 by Bill Westfield (WestfW)

Starting Program Mode [OK]

Reading signature:950F
Searching for image...
Found "optiboot_atmega328.hex" for atmega328
Start address at 7E00
Total bytes read: 508

Setting fuses for programming
Lock: 3F FFE000 Low: FF FFA000 High: DE FFA800 Ext: 5 FFA400

Programming bootloader: 512 bytes at 0x3F00
Commit Page: 3F00:3F00
Commit Page: 3F40:3F40
Commit Page: 3F80:3F80
Commit Page: 3FC0:3FC0

Restoring normal fuses
Lock: F FFE000

Type 'G' or hit RESET for next chip

And then they tried to use the "burn bootloader" menu (which didn't work.) Nope; they were already done. optifix is a one-trick low-interaction bit of code; connect it up, boot the code, and it burns the bootloader (if it can) and waits to be rebooted (and do it all again.) With a suitable cable that connects to the ISP connector, you can churn through a whole lot of old 328-based CPUs really quickly...
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by petrusp_id on Thu Feb 10, 2011 3:03 am

Sir, I only have 1 Arduino Uno, and I would like to burn bootloader onto ATmega168, can you tell me the exact problem of ArduinoISP or Optiboot?

BTW, I write a monitor program to reduce flashing 328 while learning, do you think it is useful? http://sites.google.com/site/pet4th/hom ... -uno-board

Thanks,
Petrus.
petrusp_id
 
Posts: 1
Joined: Thu Feb 10, 2011 2:35 am

Re: Uno bootloader fixer

by westfw on Thu Feb 10, 2011 11:24 am

can you tell me the exact problem of ArduinoISP or Optiboot?

I'm not sure what's wrong with ArduinoISP. It has been said to "not work on Uno" since the Uno came out, but I don't understand how Uno is different than previous boards. There is of course a problem with Autoreset - avrdude opens the serial port and resets the Arduino running ArduinoISP, and therefore ends up talking to its bootloader instead of to the ArduinoISP sketch.

Optiboot has two "major" problems:
1) Not able to write sketches larger than ~30k.
This is fixed in the optiboot source repository, but not in the Arduino-distributed copy.
http://code.google.com/p/optiboot/issues/detail?id=23
http://code.google.com/p/optiboot/sourc ... 192c3c9b83

2) (more serious) The "Sketch amnesia" problem: bootloader doesn't start the sketch that was previously downloaded.
This one is fixed in the Arduino-distributed code, but not in the optiboot repository.
http://code.google.com/p/optiboot/issues/detail?id=26
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by waterboy550 on Thu Feb 10, 2011 5:01 pm

I know your post says that the program is a Uno bootloader fixer. I have some Arduino Duemilanove atmega328. I want to switch out the bootloader so I can use the watch dog timer to reset my board. The original bootloader is freezing when I reset it via WDT. I know this is an issue as the WDT starts before the bootloader can finish. Could I use your program and install a new bootloader that would allow me to use the WDT and reset my board?
waterboy550
 
Posts: 1
Joined: Thu Feb 10, 2011 4:57 pm

Re: Uno bootloader fixer

by westfw on Thu Feb 10, 2011 7:43 pm

Yes, you can use "optifix" to install a new optiboot on any mega328-based Arduino board, including duemilanove or older variants. Optifix is actually a subset of another sketch "optiLoader" that will upgrade any old Arduino (mega8, mega168, mega328) to optiboot (but I'm still working on the documentation for that, and wanted to get something out quick to fix the bugs that were affecting Uno-smd users.)

(and also yes: optiboot (in all versions) should correctly handle watchdog timers used at the sketch level. The source even credits AdaBoot in the comments for the actual start/WD handling...)
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by ElectricMonk on Sun Feb 13, 2011 7:41 am

You sir, are my hero. Not only was I able to fix my UNO SMD's amnesia, I was able to burn the boot loader onto the 4 new 328's I just got :D
ElectricMonk
 
Posts: 2
Joined: Wed Feb 02, 2011 12:33 pm

Re: Uno bootloader fixer

by dreamcat4 on Sun Feb 13, 2011 11:23 am

ElectricMonk wrote:You sir, are my hero. Not only was I able to fix my UNO SMD's amnesia, I was able to burn the boot loader onto the 4 new 328's I just got :D


Great - some confirmation of using an Uno to write optiboot to a bare 328 chip. Is the wiring all the same as per the picture guide showing the Diecimilas? Looking at the final 2 pictures here "Circuit targeting an AVR on a breadboard".

http://arduino.cc/en/Tutorial/ArduinoISP

And with the UNO - can we still forget wiring the 16Mhz crystal and two 22nf capacitors, using the simpler wiring on the left hand side ?
dreamcat4
 
Posts: 1
Joined: Sun Feb 13, 2011 11:02 am

Re: Uno bootloader fixer

by westfw on Sun Feb 13, 2011 7:05 pm

can we still forget wiring the 16Mhz crystal and two 22nf capacitors

Not with "optifix"; it programs the 328 fuses for an external 16MHz crystal, which will cause it to stop working (probably not finish programming the bootloader, even) if you don't have a crystal there. I don't think the crystal has to be 16MHz (though the bootloader baud rate is set assuming a 16MHz crystal), but you'll need a crystal of some kind.

(optifix is primarily intended to "upgrade" existing Ardunios to optiboot, rather than be a general solution to putting the bootloader in alternate hardwre...)
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by pepe on Tue Feb 15, 2011 7:33 pm

Thanks a million!

Finally I also was able to program my blank 328 with the use of my Uno. It works like a charm :)

It looked like the other, "normal" way (ArduinoISP) indeed had some reset-issues while programming. I couldn't get it to work, as others also experienced. Do you - or anyone else, for that matter - have any information about progression in that area?
I'm asking because I would like to use my Uno as a more general ISP programmer, and to be able to also program AtTiny's in the near future...
pepe
 
Posts: 2
Joined: Tue Feb 15, 2011 7:24 pm

Re: Uno bootloader fixer

by westfw on Tue Feb 15, 2011 8:24 pm

It looked like the other, "normal" way (ArduinoISP) indeed had some reset-issues while programming. I couldn't get it to work, as others also experienced. Do you - or anyone else, for that matter - have any information about progression in that area?

I can't figure out how the Arduino's auto-reset feature ever allows ArduinoISP to work. AVRDude (especially if used with the "Burn Bootloader" IDE command) will send the reset sequence, which will cause it to end up talking to the bootloader of the Arduino that is running ArduinoISP, rather than the ArduinoISP sketch (and they'll look the same to ArduinoISP, since they run the same upload protocol.) In my case, I have enough "old" arduinos that it is no problem to find one that doesn't have the autoreset feature :-) It's easy enough to disable auto-reset permanently; it's the temporary disable hacks that seem to be prone to error. (OTHO, the auto-reset is convenient and you get used to it. Several times I've wondered "what happened to my BBB? Did I break it?" only to remember that I need to actually push the reset button when uploading.)
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: Uno bootloader fixer

by pepe on Wed Feb 16, 2011 6:24 pm

Thanks for the clarification ;)

I think I'll look into other options for programming then...
pepe
 
Posts: 2
Joined: Tue Feb 15, 2011 7:24 pm

Re: Uno bootloader fixer

by flakelabs on Sat Feb 26, 2011 1:17 pm

Thanks! That worked perfectly!
User avatar
flakelabs
 
Posts: 15
Joined: Thu Jan 21, 2010 10:52 pm