Bootloader Modifications for Pro Mini 8mhz

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.

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.

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!

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:

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!

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: %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:

#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:

//if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
//      app_start();  // skip bootloader

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:

UBRR0H = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1) >> 8;
UBRR0L = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1);

MikeT

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.

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):

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:

make atmega328_pro8

and to upload

make atmega328_pro8_isp

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

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!

Hi wingnut87,

Now I would like to tweak the loader for the Arduino BT, but there is now makefile

just copy the Makefile from the "atmega" directory and insert the following section (just before "isp: $(TARGET)" line):

bt: TARGET = bt
bt: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' -DBAUD_RATE=115200L '-DARDUINO_BT' '-DWATCHDOG_MODS'
bt: AVR_FREQ = 16000000L 
bt: $(PROGRAM)_bt.hex

bt_isp: bt
bt_isp: TARGET = bt
bt_isp: HFUSE = DD
bt_isp: LFUSE = FF
bt_isp: EFUSE = 00
bt_isp: isp

To compile the bootloader use

make bt

I modified the wait time before leaving the bootloader and starting the sketch (-DMAX_TIME_COUNT=F_CPU>>1) and enabled the watchdog timer support (-DWATCHDOG_MODS).

Theoretically you can use the "bt_isp" target to program the ATmega, but I never tried this because I use a different programmer.

MikeT

Hey Mike, I was able to generate a hex file, but when I tried to burn the bootloader through the IDE, I got this message:

avrdude: ERROR: address 0x4010 out of range at line 129 of /Applications/Arduino.app/Contents/Resources/Java/hardware/bootloaders/bt/ATmegaBOOT_168.hex
avrdude: write to file '/Applications/Arduino.app/Contents/Resources/Java/hardware/bootloaders/bt/ATmegaBOOT_168.hex' failed

I also tried compiling the c file with avr studio. It uploaded to the chip, but does not seem to do anything. Led does not blink. Any ideas?

Thanks!

Hi wingnut87,

the ATmega168 on the Arduino-BT has 16kB flash and 2kB boot loader section (when fuses BOOTSZ0=0 and BOOTSZ1=0) at the end, starting at 0x3800. It seems your bootloader is some bytes too large, the maximum address must be less than 0x4000.

Have you used the original bootloader or did you modify it?

You can omit the following code from the boot loader, because it is not really needed:

   //message("SET BT PAGEMODE 3 2000 1");    
putch('S');
putch('E');
putch('T');
putch(' ');
putch('B');
putch('T');
putch(' ');
putch('P');
putch('A');
putch('G');
putch('E');
putch('M');
putch('O');
putch('D');
putch('E');
putch(' ');
putch('3');
putch(' ');
putch('2');
putch('0');
putch('0');
putch('0');
putch(' ');
putch('1');
putch(0x0D);

  
        //put_s("SET BT ROLE 0 f 7d00");  
      putch('S');
      putch('E');
      putch('T');
      putch(' ');
      putch('B');
      putch('T');
      putch(' ');
      putch('R');
      putch('O');
      putch('L');
      putch('E');
      putch(' ');
      putch('0');
      putch(' ');
      putch('f');
      putch(' ');
      putch('7');
      putch('d');
      putch('0');
      putch('0');
      putch(0x0D);

These commands make sure, that some settings of the WT-11 are restored to usable values.

If you need this feature, you better send the following commands once to the WT-11 in command mode (refer also to http://www.arduino.cc/en/Main/ArduinoBTInitializationSketch):

Serial.println(" SET CONTROL BIND 1 20 RISE SET BT AUTH * 12345");
  Serial.println(" SET CONTROL BIND 2 20 RISE SET CONTROL BAUD 115200,8n1");
  Serial.println(" SET CONTROL BIND 3 20 RISE SET BT PAGEMODE 3 2000 1");
  Serial.println(" SET CONTROL BIND 4 20 RISE SET BT ROLE 0 f 7d00");
  Serial.println(" SET CONTROL BIND 5 20 RISE SET CONTROL ECHO 0");
  Serial.println(" SET CONTROL BIND 6 20 RISE SET CONTROL ESCAPE - 00 1");
  Serial.println(" SET CONTROL BIND 7 20 RISE SET CONTROL CONFIG 102D");

To activate this commands, you need to apply LOW->HIGH edge (3,3V) at GPIO pin 5 of the WT-11 (pin 9 of connector SV2).

MikeT

Hey Mike, I was able to get everything working. Now I'm just wondering why it works. I basically have a circuit similar to the arduino bt, but am running it at 8mhz for power reasons. I ended up using a pro mini 168 8mhz bootloader. I read through the bootloader and makefile and it should be running at 19200. Then my program is running at 19200 for serial communication. The weird thing is that is only works if my bluetooth module is configured to 115200 communication. Why does this work, and only work this way? I can communicate with my program via bluetooth, (i.e. serial commands control leds), but the arduino serial window is set at 19200. I'm confused :frowning:

thanks so much for your help so far!

Hi wingnut87,

the baudrate of UART interface of the WT-11 bluetooth chip is totally independent of the transmission speed of the Bluetooth interface. The same is true for the baudrate of virtual Bluetooth COM ports on the PC, this means the PC baudrate is not relevant for this type of ports.

Which program do you mean with

Then my program is running at 19200 for serial communication.

the program on the ATmega or on the PC side?

The weird thing is that is only works if my bluetooth module is configured to 115200 communication

Which Bluetooth module do you mean?
A) the Bluetooth module connected to the ATmega
B) an extra Bluetooth module connected to a UART COM port of you PC
C) an extra Bluetooth module connected to a USB COM port of you PC (e.g. via FTDI)
D) a Bluetooth (USB) dongle

MikeT

So I have an atmel 168 running at 8mhz. I installed a pro8 bootloader, which should be expecting to communicate at 19200. There is a bluetooth module in my circuit which is connected to the UART on the 168. It is set to communicate at 115200. The arduino sketch which blinks an led based on serial commands is running at 19200. I'm sending commands using the Arduino IDE serial box. It is set to 19200 and I am using my laptop's built in bluetooth.

So everything is set to 19200 except the bluetooth module in the circuit. It is at 115200 and that is the only way it all works. I'm just wondering why. Is there something else I am missing or don't get yet?

thanks!

Hi wingnut87,

I also don't understand this. What type of bluetooth module are you using? How do you know it is really set to 115200 baud?

Does the baudrate of your bt module depend on an external crystal or does it have an addidtional clock divider (prescaler)?

To use higher baud rates, you have to change the crystal value to a multiple of 1843200 Hz, otherwise the error of the resultant baud rate gets too high.

The boot loader uses a formula for the UBRR divider which gets a greater error for 115200 baud and 16 MHz crystal. For a 8 Mhz crystal even the modified formula doesn't help, you will always have an error of +8.5% (125000 instead of 115200 baud).

Boot loader formula:    UBRR=((FOSC / 16)            / BAUD - 1)
HardwareSerial formula: UBRR=((FOSC / 16 + BAUD / 2) / BAUD - 1)

Here the table of the baudrate error using different CPU clocks:

CPU
clock
requested baudrate UBRR (floating point + 0.5) UBRR resultant baudrate error
8000000 230400 1,670138889 1 250000 8,51%
8000000 115200 3,840277778 3 125000 8,51%
8000000 57600 8,180555556 8 55555,56 -3,55%
8000000 38400 12,52083333 12 38461,54 0,16%
8000000 19200 25,54166667 25 19230,77 0,16%
8000000 9600 51,58333333 51 9615,385 0,16%
7372800 230400 1,5 1 230400 0,00%
7372800 115200 3,5 3 115200 0,00%
7372800 57600 7,5 7 57600 0,00%
7372800 38400 11,5 11 38400 0,00%
7372800 19200 23,5 23 19200 0,00%
7372800 9600 47,5 47 9600 0,00%
16000000 230400 3,840277778 3 250000 8,51%
16000000 115200 8,180555556 8 111111,1 -3,55%
16000000 57600 16,86111111 16 58823,53 2,12%
16000000 38400 25,54166667 25 38461,54 0,16%
16000000 19200 51,58333333 51 19230,77 0,16%
16000000 9600 103,6666667 103 9615,385 0,16%

See also here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251415313#2

MikeT

One thing I forgot to mention is that I have Arduino BT selected as the board I am using in the IDE.

So in an earlier post, you were helping me compile the BT bootloader. One of the options was 115200 in the makefile. Am I correct in assuming the bluetooth module on the board must be communicating with the arduino at 115200 for the bootloader to accept a new program? On the arduino BT, it sounds like the bluetooth module is set to 115200. Does that mean that your arduino sketch must use the code:

Serial.begin(115200)?

I am aware of the highspeed problems, which is why I've been trying to run everything at 19200. I do have some intermittent problems which might be related. So when it only worked with the module configured to 115200, I was pretty confused.

By configured, I mean I connected to the module via bluetooth, entered command mode, and set the baud rate. It is the same as the instructions you gave me in the post where I removed those from the bootloader.

Also, when I select Arduino BT as my board in the IDE, various things change, one of which being how long the software will attempt to open a connection and upload a program. Is it possible to see and change these settings? I've looked around for files that allow me to make some adjustments, but have only found boards.txt under hardware, which does not seem to have it.

Am I correct in assuming the bluetooth module on the board must be communicating with the arduino at 115200 for the bootloader to accept a new program?

It depends on the setting of the bluetooth module and the bootloader. Both must match and your sketches have to use the same setting for Serial.begin(). You can also use 19200, 38400 or 57600.

So in an earlier post, you were helping me compile the BT bootloader. One of the options was 115200 in the makefile.

Be careful: The Arduino-BT bootloader ignores the baudrate setting from the Makefile, it uses a hardcoded constant. use a modified Duemilanove boot loader for my Arduino-BT and that's the reason for the 115200 in the Makefile.

On the arduino BT, it sounds like the bluetooth module is set to 115200. Does that mean that your arduino sketch must use the code:
Serial.begin(115200)?

Yes, that's correct.

Also, when I select Arduino BT as my board in the IDE, various things change, one of which being how long the software will attempt to open a connection and upload a program.

The wait time in the boot loader of the Arduino-BT is longer and it might also take longer to open the bluetooth connection, but I don't think the IDE itself behaves differently. I couldn't find something specific by looking at the code (http://arduino.googlecode.com).

Is it possible to see and change these settings? I've looked around for files that allow me to make some adjustments, but have only found boards.txt under hardware, which does not seem to have it.

What do you want to change?

MikeT

So I read through the bootloader that most of the boards use and also the one for the BT. I know that all the 168 chip bootloaders run at 19200 and the 328 chips at 57600. Also, the BT bootloader runs at 115200. There are so many places to set the baud rate I just want to make sure I understand this. The rate in the bootloader determines the rate at which a new program is uploaded right?

In the files boards.txt, once again the 168 chips are set to 19200 and the 328 chips to 57600, but the BT is also set to 19200. Why is this? Is this where my computer must match the bootloader to work? If you make changes to the boards.txt do they take effect right away? Do I have to compile something?

I'm always worried I will make a change to something and assume it worked, but I was actually overridden by some other code. Or the changes didn't take effect because of some other reason.

Thanks!
Tom