ButterflyBoot2 is an Enhanced Butterfly BootLoader. It is a fully compatible, alternative Butterfly BootLoader with the unique feature of power management, that extends the battery life.
Tests have been done, resulted in impressively lower power consumption: Down to 27% of any other similar firmware release without power management, either being official or not.
ButterflyBoot2 is the GPL licenced upgrowth of my own ButterflyBoot LGPL licenced project, I have published at: https://www.avrfreaks.net/index.p...
The ButterflyBoot2 firmware size is below the 512W boundary, in order to fit into the 512W bootloader space of the third boot-start option. This way, the ButterflyBoot2 releases 1KB of program memory space for you to dedicate to your Application Section by presetting the boot-start at the third position (512W, at address 0x1E00) instead of the standard fourth position (1024W, at address 0x1C00). This can be easily done by changing the boot-block-size Fuses, accordingly.
The ButterflyBoot2 firmware size can be so small, without sacrificing any functionality at all, because it is hand-crafted in pure assembly.
The major enhancements of the ButterflyBoot2 are:
* The addition of Power Management routines, to minimize the overall power consumption.
* A large part of its predecessor's ButterflyBoot Programming Engine has been rewritten and optimized.
* It has an improved Auto-Oscillator-Calibration accuracy.
* The firmware still fits into the 512W bootloader space, of the third boot-start option.
* It is functionally compatible with the official Butterfly bootloader releases, because it supports all the memory access modes (Word/Block mode, FLASH/EEPROM read/write and LOCK/FUSE read access).
* It is failsafe because the Write_Lock_Bits command is disabled, therefore the MCU cannot be locked by itself. This way, the firmware eliminates the known 0x940C error, discussed at: https://www.avrfreaks.net/index.p...
Here are a few typical current consumption figures:
# Butterfly Battery specifications: Model: CR2450 Nominal Voltage: 3.0 Volts Nominal Capacity: 550 mAh (at 0.2 mA Discharge Current, +23°C) Standard Discharge Rate: 0.2 mAh Maximum recommended current under continuous discharge: 3 mA Maximum recommended current under pulse discharge: 15 mA # Butterfly current consumption measurement conditions: Butterfly Vcc: 3.00V (provided by a regulated power supply) Brown-Out Detector: Disabled CPU clock frequency: 2 MHz USART baud rate: 19200 bps Test-writing and reading the official "AVR_Butterfly_application_rev06.hex" firmware # "ButterflyBoot v1.1" (or any other) bootloader, without power management: * Bootloader is inactive: Buttons released: 0.01 mA (100%) "ENTER" presssed: 1.50 mA (100%) * Bootloader is active: On line, standing by: 1.42 mA (100%) FLASH reading: 1.95 mA (100%) FLASH programming: 1.95 mA (100%) FLASH erasing: 4.41 mA (100%) EEPROM reading: 1.95 mA (100%) EEPROM programming: 4.44 mA (100%) # "ButterflyBoot2 v1.0" bootloader, with power management: * Bootloader is inactive: Buttons released: 0.01 mA (100%) "ENTER" presssed: 0.47 mA ( 31%) * Bootloader is active: On line, standing by: 0.39 mA ( 27%) FLASH reading: 0.99 mA ( 50%) FLASH programming: 0.99 mA ( 50%) FLASH erasing: 3.82 mA ( 86%) EEPROM reading: 0.99 mA ( 50%) EEPROM programming: 3.91 mA ( 88%) Note: The ATmega169 does not support single EEPROM erasing operations; these take place in the background, during EEPROM Programming.
If anybody wonders why I have not released a smaller sized bootloader firmware, to fit into the 256W bootloader space perhaps, my answer is straightforward: It can easily be done; but it is NOT recommended at all for the Butterfly device.
Having it discussed off-line with Smiley, the huge Oscillator_Calibration function is essential for the Butterfly bootloader operation, to help the latter have an accurate baud-rate USART. This is because the main clock source of the Butterfly is its calibrated internal oscillator, whose default OSCCAL value is not always the best one: The frequency of the Butterfly internal oscillator will drift over the ambient temperature range and the power supply voltage variations, and as a result of this, the oscillator has to be calibrated at every power-up or reset.
In my opinion, the oscillator calibration function should not be omitted, especially when the Butterfly is operated on battery power. Therefore the Butterfly bootloader cannot be stripped down, below the 512W boundary, which is already half of the size of the official bootloader.
TIP #1: Even with power management, since a battery is the Butterfly's main power source, when the battery is almost empty there is a possibility for the CPU to execute random instructions, that could probably alter the Fuse/Lock settings and/or the program memory and/or the EEPROM contents. Reference: "Preventing Flash Corruption" at the ATmega169 data sheet Rev.O, page 262.
To prevent this erratic behaviour you can enable the Brown-Out Detector at 1.8V, which will prevent the CPU from random instruction executions when the voltage drops, at the expense of an extra 10μA continous current consumption. Unfortunately, the BOD Fuses cannot be changed during the program runtime, so the BOD cannot be controlled by the firmware. The BOD can only be always enabled, or always disabled, and its status and settings can be changed only during the ISP/JTAG/HVP programming.
TIP #2: After the completion of any BootLoader operation you can reset the Butterfly, to enter a minimal power consumption state, by sending the "Bootloader Exit" command ("E"), pressing the "Exit" button of the AVRProg.exe front-end programmer. It has the same effect as pulling the /RESET line to GND. The AVRDude programmer sends the "Exit" command automatically.
Be careful though, not to confuse the "Bootloader Exit" command ("E") with the "Chip Erase" command ("e"), if using an RS-232 terminal. The ASCII BootLoader commands are case-sensitive.
I hope that you will find useful this special piece of firmware, I had promised to release.