Go Down

Topic: Bootloader Modifications for Pro Mini 8mhz (Read 4208 times) previous topic - next topic

wingnut87

Hi guys!  I searched around for a bit and didn't find anything on this.  I'm trying to reset my Pro Mini to accept a new program, but I'm not using the FTDI cable.  I would like to increase the time the bootloader will wait for the new program on the UART pins.  I originally tried using a watchdog timer, but while looking through the bootloader code, found there were a few lines that skip programming when the watchdog is used.

I guess these are my questions.  Where in the bootloader is the value of time it will wait?  I couldn't find it.  Also, in the bootloaders/atmega directory, there are a number of hex files and one c file.  How do I create a hex that I know will run on my board?  How do I select it in the IDE?

thanks!

BenF

Timeout is controlled by MAX_TIME_COUNT which is defined in the makefile (bootloader directory).

If you use Burn Bootloader from the IDE, the correct file gets built/uploaded based on your selection of board.


wingnut87

So I found the make file and changed:

'-DMAX_TIME_COUNT=F_CPU>>40' '-DNUM_LED_FLASHES=3'

When I upload, I get a successful program, but the board doesn't respond any differently and and the .hex file is labeled as being modified  months ago (assume when this version was released).  Any ideas?

BTW, I using 0017 on MAC OSX

Thanks!

wingnut87

Also, I noticed that 328P chips have bootloaders that run at 57600, even with 8 mhz chips.  I was under the impression this baud rate had error issues?  Why is this?

BenF

I think you need to either update the timestamp on the bootloader source file (open the source in a text editor and save) or delete the ".hex" file in order to force "make" to rebuild a new bootloader from the source. Otherwise it will assume no changes were made and just skip the rebuild. Apparently a change to the makefile only does not trigger a rebuild.

wingnut87

Thanks Ben, I will try re-saving the source file.  I assume that is the .c file right?  I did try removing the hex file, but I just got an error when I tried to reload it onto my board.


wingnut87

Ok, so I resaved the .c file an loaded the bootloader with no luck.  Next I removed the .hex file and got this message:

avrdude: can't open input file /Users/wingnut87/Desktop/Arduino.app/Contents/Resources/Java/hardware/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex: No such file or directory
avrdude: write to file '/Users/wingnut87/Desktop/Arduino.app/Contents/Resources/Java/hardware/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex' failed

Does it seem like avrdude tries to write a new file and can't?  Thanks!

BenF

Your topic suggested to me that you were familiar with burning bootloaders. If this is not the case I suggest you read up on the topic first. A good start might be:

http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader

wingnut87

Hey Ben, I am familiar with bootloaders to the extent that I know their purpose.  I am familiar with some differences between the boards that are available.  I also have a programmer and have successfully programmed bootloaders to chips many times.

This is the first time I have tried to change one.  All I need is to change the baud rate and reprogram it.  I just don't know how to generate a new hex file.  It appears that burning the bootloader just takes the hex file in the directory and loads it, but does not apply any changes made to the make file.

What should I do to compile a new hex?

Thanks for your help so far!

Mike T

#10
Oct 13, 2009, 08:17 pm Last Edit: Oct 13, 2009, 08:50 pm by nospam2000 Reason: 1
Hi,

please look at this thread for compiling the boot loader: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1255016475/1#1

You have to add the following line to get a boot loader for the pro 8 Mhz with ATmega328:
Code: [Select]
%DIRAVRUTIL%\make.exe atmega328_pro8

To increase the wait time, you have to change the Makefile in the opposite way. You are using "F_CPU>>40" = 8M / 2^40 which is exactly 0 in integer arithmetic, so there will be no wait time at all.

Try using something like '-DMAX_TIME_COUNT=F_CPU>>1' which means 8 times (2^3) longer than normal.

You can also use the WDT for the reset, but then you have to change the code a bit. Look at the following code lines:
Code: [Select]
#ifdef WATCHDOG_MODS
     ch = MCUSR;
     MCUSR = 0;

     WDTCSR |= _BV(WDCE) | _BV(WDE);
     WDTCSR = 0;

     // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
     if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
           app_start();  // skip bootloader
#else


You have to comment out the last two lines when you want to enter the bootloader using the WDT:
Code: [Select]
//if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
//      app_start();  // skip bootloader



Quote
Also, I noticed that 328P chips have bootloaders that run at 57600, even with 8 mhz chips.  I was under the impression this baud rate had error issues?


Whether this baud rate has issues, depends very much on the other side of the serial cable. What cable are you using?

To improve the baudrate calculation, you can change the baud-rate calculation in the bootloader to the formula of HardwareSerial which is more exact because of better rounding:
Code: [Select]
UBRR0H = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1) >> 8;
UBRR0L = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1);


 MikeT

wingnut87

Hey thanks a ton MikeT!  I will try it as soon as I get home.  I thought it was funny that the guy you helped in the other post was wyngnut.

BenF

What I normally do is to use the makefile directly from a command prompt. This ads some challenges since you need to set up the PATH to the build tools correctly (probably why they added "Burn Bootloader" as an option from within the IDE). Also you need a valid reference to the avrdude config file and approriate defines for your programmer.

To deal with above I modified the makefile to reflect my specific configuration and also made it reference a copy of the bootfile source (MyBoot.c).  If you want to go down this path you may get some inspiration from the following (shows the modified parts):

Quote
# program name should not be changed...
PROGRAM    = MyBoot_328

# enter the parameters for the avrdude isp tool
ISPTOOL         = stk500v2
ISPPORT         = COM4
ISPSPEED   = -b 115200
CFGFILE    = d:\arduino\hardware\tools\avr\etc\avrdude.conf

ISPFUSES    = avrdude -C $(CFGFILE) -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
ISPFLASH    = avrdude -C $(CFGFILE) -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m


To build I use the connand:
Quote
make atmega328_pro8

and to upload
Quote
make atmega328_pro8_isp


Marcus Fazzi (Anunakin)

Can I use this way on ATMEGA32L-8PU (8MHz) ?
I have some ones here...
:)

wingnut87

Mike T, thanks again for your help!  I was able to make a script to compile the bootloader for the pro 8.  Now I would like to tweak the loader for the Arduino BT, but there is now makefile, just the c file.  Is there a way to compile this?  Thanks!  

Go Up